I've tried several things with the registers, but no luck. I've also added a sub to make it behave the way it should:
Code:
#config
__CONFIG _CP_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT& _MCLRE_OFF
#endconfig
ADCON1 = %00000000
ANSEL = %00000100
CMCON = 0
TRISA = %11001100
TRISC = %00000000
LED var PORTA.1
PUSHBUTTON var PORTA.3
led = 1
pause 100
led = 0
pause 100
led = 1
pause 100
led = 0
main:
if PUSHBUTTON = 0 then
toggle LED
pause 25
gosub buttonrelease
pause 25
endif
goto main
end
buttonrelease:
do until PUSHBUTTON = 1
pause 10
loop
return
It still does the same thing. The LED flashes on power up. The button works once. And then it locks up. And I've tried several other "lower level" ways of making the LED toggle instead of the TOGGLE statement. It's always the same. Here's something interesting, though. If I change the code to just make the LED come on when the button is pressed instead of trying to toggle it like so:
Code:
main:
if PUSHBUTTON = 0 then
LED = 1
elseif PUSHBUTTON = 1 then
LED = 0
endif
goto main
end
Everything works perfectly! So I'm assuming the problem isn't with the MCLR pin or the registries. Do I need to define the oscillator?
Bookmarks