Don't understand why PORTA pin isn't working like before

Started by Roger_4U May 23, 2007
Hi I am new to the 16F88 chip and I am trying to run some code that
previously worked on a 16F628. The code is to simply cause an LED to
blink on/off after a delay period.

>With this code it blinks:

Start
MOVLW D'200'
SUBWF r_Clk1_For2HzOutput_ms, 0
BTFSS 3, 0
GOTO Start

BCF PORTA, 2
CLRF r_Clk1_For2HzOutput_ms
a1_Loop2
MOVLW D'200'
SUBWF r_Clk1_For2HzOutput_ms, 0
BTFSS 3, 0
GOTO a1_Loop2
BSF PORTA, 2
CLRF r_Clk1_For2HzOutput_ms

GOTO Start
END ; directive 'end of program'

>With this code it does Not blink:

Start
MOVLW D'200'
SUBWF r_Clk1_For2HzOutput_ms, 0
BTFSS 3, 0
GOTO Start

MOVLW 0x04
XORWF PORTA, 1 ;<-- Must examine why this is Not working!!!
;OMIT: clrb PORTA.2
CLRF r_Clk1_For2HzOutput_ms
a1_Loop2
MOVLW D'200'
SUBWF r_Clk1_For2HzOutput_ms, 0
BTFSS 3, 0
GOTO a1_Loop2
BSF PORTA, 2
CLRF r_Clk1_For2HzOutput_ms

GOTO Start
END ; directive 'end of program'

>With this code it still blinks:

Start
MOVLW D'200'
SUBWF r_Clk1_For2HzOutput_ms, 0
BTFSS 3, 0
GOTO Start

MOVLW 0x04
XORWF PORTA, 1 ;<-- Must examine why this is Not working!!!
BCF PORTA, 2
CLRF r_Clk1_For2HzOutput_ms
a1_Loop2
MOVLW D'200'
SUBWF r_Clk1_For2HzOutput_ms, 0
BTFSS 3, 0
GOTO a1_Loop2
BSF PORTA, 2
CLRF r_Clk1_For2HzOutput_ms

GOTO Start
END ; directive 'end of program'
What am I doing wrong?

Note:
(1) I am shutting down the comparator with this statement in the init
procedure:
MOVLW H'07' ; CMCON=7 set comperators off
MOVWF CMCON
(2) This is the config:
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF &
_WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON &
_HS_OSC & _PWRTE_ON & _WDT_OFF
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF &
_WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON &
_HS_OSC & _PWRTE_ON & _WDT_OFF
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF

Thanks
Roger
Thanks Guys but don't bother, I've found the problem: Needed to clear
the 'ANSEL' register also in the Init section of the code.

--- In p..., "Roger_4U" wrote:
>
> Hi I am new to the 16F88 chip and I am trying to run some code that
> previously worked on a 16F628. The code is to simply cause an LED to
> blink on/off after a delay period.
>
> >With this code it blinks:
>
> Start
> MOVLW D'200'
> SUBWF r_Clk1_For2HzOutput_ms, 0
> BTFSS 3, 0
> GOTO Start
>
> BCF PORTA, 2
> CLRF r_Clk1_For2HzOutput_ms
> a1_Loop2
> MOVLW D'200'
> SUBWF r_Clk1_For2HzOutput_ms, 0
> BTFSS 3, 0
> GOTO a1_Loop2
> BSF PORTA, 2
> CLRF r_Clk1_For2HzOutput_ms
>
> GOTO Start
> END ; directive 'end of program'
>
> >With this code it does Not blink:
>
> Start
> MOVLW D'200'
> SUBWF r_Clk1_For2HzOutput_ms, 0
> BTFSS 3, 0
> GOTO Start
>
> MOVLW 0x04
> XORWF PORTA, 1 ;<-- Must examine why this is Not working!!!
> ;OMIT: clrb PORTA.2
> CLRF r_Clk1_For2HzOutput_ms
> a1_Loop2
> MOVLW D'200'
> SUBWF r_Clk1_For2HzOutput_ms, 0
> BTFSS 3, 0
> GOTO a1_Loop2
> BSF PORTA, 2
> CLRF r_Clk1_For2HzOutput_ms
>
> GOTO Start
> END ; directive 'end of program'
>
> >With this code it still blinks:
>
> Start
> MOVLW D'200'
> SUBWF r_Clk1_For2HzOutput_ms, 0
> BTFSS 3, 0
> GOTO Start
>
> MOVLW 0x04
> XORWF PORTA, 1 ;<-- Must examine why this is Not working!!!
> BCF PORTA, 2
> CLRF r_Clk1_For2HzOutput_ms
> a1_Loop2
> MOVLW D'200'
> SUBWF r_Clk1_For2HzOutput_ms, 0
> BTFSS 3, 0
> GOTO a1_Loop2
> BSF PORTA, 2
> CLRF r_Clk1_For2HzOutput_ms
>
> GOTO Start
> END ; directive 'end of program'
> What am I doing wrong?
>
> Note:
> (1) I am shutting down the comparator with this statement in the init
> procedure:
> MOVLW H'07' ; CMCON=7 set comperators off
> MOVWF CMCON
> (2) This is the config:
> __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF &
> _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON &
> _HS_OSC & _PWRTE_ON & _WDT_OFF
> __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
> __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF &
> _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON &
> _HS_OSC & _PWRTE_ON & _WDT_OFF
> __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
>
> Thanks
> Roger
>
----- Original Message -----
From: "Roger_4U"
To:
Sent: Friday, May 25, 2007 12:52 AM
Subject: [piclist] Re: Don't understand why PORTA pin isn't working like
before
> Thanks Guys but don't bother, I've found the problem: Needed to clear
> the 'ANSEL' register also in the Init section of the code.

That can be even more confusing if you use the MPLAB debugger; it sets
analogue inputs to digital by default, so a program can work OK when it's
being debugged and stops working when programmed into the device.

Leon

Leon Heller
Amateur radio call-sign G1HSM
Yaesu FT-817ND transceiver
Suzuki SV1000S motorcycle
l...@btinternet.com
http://webspace.webring.com/people/jl/leon_heller/
> ----- Original Message -----
> From: "Roger_4U"
> To:
> Sent: Friday, May 25, 2007 12:52 AM
> Subject: [piclist] Re: Don't understand why PORTA pin isn't working like
> before
>> Thanks Guys but don't bother, I've found the problem: Needed to clear
>> the 'ANSEL' register also in the Init section of the code.
>
> That can be even more confusing if you use the MPLAB debugger; it sets
> analogue inputs to digital by default, so a program can work OK when it's
> being debugged and stops working when programmed into the device.

Oh yes, and don't forget to set the CMCON register to turn off the
blasted comparators or nothing else will work there either. For some
reason the PIC always defaults to using the comparators. I'm sure
someone out there actually uses these (I never have) because Microchip
puts them into everything and defaults them on...

DLC
> Leon
>
> Leon Heller
> Amateur radio call-sign G1HSM
> Yaesu FT-817ND transceiver
> Suzuki SV1000S motorcycle
> l...@btinternet.com
> http://webspace.webring.com/people/jl/leon_heller/
>
> to unsubscribe, go to http://www.yahoogroups.com and follow the
> instructions
> Yahoo! Groups Links