I can't make it work with the BUTTON command.
So I tried the other way and use the simple IF..THEN command.
But again, I have the same unexpected result. The Led starts to blink when I press the button. As I release the button, it never "toggles" as I want it to do.
Since this program behavior is the same in both cases (BUTTON and IF..THEN commands), I assume something is wrong with some register settings.
I was thinking about a bouncing problem, but I'm not sure about that.
Here is my code; where do I miss something?
'PIC 16F88
'Button is on PORTB.3 (Pin 9) Pressed = 0V
'Led is on PORTB.4 (Pin 10)
OSCCON = %01100000 'Internal RC set to 4MHZ
TRISB = %00001000 'RB3 is an Input, all others are Outputs
'----------------------------------------------------------------
' IF..THEN
MAIN:
IF PORTB.3 = 0 then SWITCH_LED
goto main
SWITCH_LED:
pause 100 'Debounce
toggle PORTB.4
goto main
end
'----------------------------------------------------------------
' BUTTON
'BVar var byte
'BVar = 0
'
'MAIN:
' BUTTON 9, 0, 255, 255, BVar, 0, SWITCH_LED
' goto main
'
'SWITCH_LED:
' pause 100 'Debounce
' toggle PORTB.4
' goto main
END
Bookmarks