Simple PIC program not working

Thread Starter

tigerapna

Joined Dec 14, 2011
73
I am just trying to turn on the LED when the button is pressed but the LED already remains on without a press button.

What am I doing wrong?

Rich (BB code):
Start:
     bsf     STATUS,RP0       ; select Register Page 1
     bcf     TRISC,0             ; make IO Pin C0 an output
     bsf     TRISA,RA3          ;make IO pin RA3 an input
     bcf     STATUS,RP0       ; back to Register Page 0
     bcf     PORTC,0
loop:    
     btfss   PORTA,RA3
     bsf     PORTC,0          ; turn on LED C0 (DS1)
     goto    loop                
     end
 
Last edited:

c0de3

Joined May 1, 2009
50
I am just trying to turn on the LED when the button is pressed but the LED already remains on without a press button.

What am I doing wrong?

Rich (BB code):
Start:
     bsf     STATUS,RP0       ; select Register Page 1
     bcf     TRISC,0             ; make IO Pin C0 an output
     bsf     TRISA,RA3          ;make IO pin RA3 an input
     bcf     STATUS,RP0       ; back to Register Page 0
     bcf     PORTC,0
loop:    
     btfss   PORTA,RA3
     bsf     PORTC,0          ; turn on LED C0 (DS1)
     goto    loop                
     end

Check the datasheet, what else does RA3 do? Is it perhaps a reset pin or anything like that?
 

t06afre

Joined May 11, 2009
5,934
Most PICs have some kind of analog input functions. And thye are turned on as default after power on on reset. A pin with an analog function will always read '0' What PIC are you using?
 

Thread Starter

tigerapna

Joined Dec 14, 2011
73
Most PICs have some kind of analog input functions. And thye are turned on as default after power on on reset. A pin with an analog function will always read '0' What PIC are you using?
I'm using 16F690.

I am powering it from the PICKIT 2, could this overide signals?
 

t06afre

Joined May 11, 2009
5,934
I'm using 16F690.

I am powering it from the PICKIT 2, could this overide signals?
In the 16f690 demokit the button is conected to RA3 pin which also is MCLR pin. And PICKIT 2 take control over this pin. You can control the MCLR pin from MPLAB. If you are using the Low pin count demo card. It comes with 12 lessons. Have you looked at them? Also then posting code please post the full code included the __config() setting. As this is important
 

Thread Starter

tigerapna

Joined Dec 14, 2011
73
In the 16f690 demokit the button is conected to RA3 pin which also is MCLR pin. And PICKIT 2 take control over this pin. You can control the MCLR pin from MPLAB. If you are using the Low pin count demo card. It comes with 12 lessons. Have you looked at them? Also then posting code please post the full code included the __config() setting. As this is important
Yes, I looked through most of them but couldn't figure out why I couldn't use RA5 and RA2 as inputs. I looked up on google and people said PICKIT 2 takes over the signals when not powering from external VDD.

I am using RB7 and RB6 as inputs and its working fine.

I can move on with my code :D.

Thank you for the help with all my posts.
 
Top