Hi,
I'm really struggling to follow that code with port bits being read into WORD variables and vice versa. I understand that you want to know WHY your code doesn't work but, and please don't take this the wrong way, that's just WAY to convoluted IMHO.
The following compiles OK for a 12F675 but I have not tested it. Please see if you can follow the logic behind it, then try it on the actual hardware.Now, this is ALSO a bit convoluted and can certainly be made more "compact" but I wanted to keep it as simple as possible for starters. Let me know if you try it out.Code:LED1 var GPIO.0 ' Alias GPIO.0 to LED1 LATCH1 var GPIO.1 ' Alias GPIO.1 to LATCH1 PB1 Var GPIO.2 ' Alias GPIO.2 to push button LED2 var GPIO.5 ' Same as aboove for second "port" LATCH2 var GPIO.4 PB2 var GPIO.3 Debounce VAR BYTE ' Counter for the debounce rotutine. ANSEL = 0 ' Set all digital CMCON = 7 ' Analog comparators off GPIO = 0 ' All outputs OFF TRISIO = %11001100 ' Set ins and outs '------------------------------------------------------------------------------- Main: IF PB1 = 0 THEN ' Button 1 pressed? TOGGLE LED1 TOGGLE LATCH1 Debounce = 0 ' Clear counter variable While Debounce < 99 ' Signal must be stable for 100 counts in a row. IF PB1 = 1 THEN ' Button is released (or bouncing). Debounce = Debounce + 1 ELSE Debounce = 0 ' If button still active, clear counter. ENDIF PAUSEUS 100 ' 100 counts * 100us = 10ms "silence" before continuing WEND ENDIF '------------------------------------------------------------------------------- IF PB2 = 0 THEN ' Button 2 pressed? TOGGLE LED2 TOGGLE LATCH2 Debounce = 0 ' Clear counter variable While Debounce < 99 ' Signal must be stable for 100 counts in a row. IF PB2 = 1 THEN ' Button is released (or bouncing). Debounce = Debounce + 1 ELSE Debounce = 0 ' If button still active, clear counter. ENDIF PAUSEUS 100 ' 100 counts * 100us = 10ms "silence" before continuing WEND ENDIF '------------------------------------------------------------------------------- Goto Main
/Henrik.




Bookmarks