I'll give it a shot with a simple ON INTERRUPT version.
There must be ten gozillion ways to do something like this, even without an interrupt, butCode:x var BYTE Switch VAR BIT TRISA = $FF TRISC = 0 ANSEL = 0 ' A/D disabled (all digital) ANSELH = 0 IOCA.3 = 1 ' int-on-change enabled for RA3 INTCON = %10001000 ' enable global & int-on-change interrupts Switch = 1 ON INTERRUPT GOTO MyISR mainloop: x = 1 loops: PORTC = x pause 500 if switch = 1 then if x == 8 then goto mainloop else x = x << 1 goto loops endif else if x == 1 then x = 8 goto loops else x = x >> 1 goto loops endif endif GOTO mainloop ' just in case DISABLE MyISR: WHILE PORTA.3=0 ' wait for button release (so we can clear the int flag & be WEND ' sure it interrupts on a high-to-low transition) Switch = ~Switch ' toggle Switch INTCON.0 = 0 ' clear interrupt flag bit RESUME END
it's still handy to at least learn about interrupts.
Note that you could also do something similar by just monitoring the interrupt flag-bit with
global interrupts disabled. You just need to get a tad more creative...;o}
Tap & release the button as fast as you can to see how quickly it reacts.




Bookmarks