Hi fratello,
Thanks for the link.
Regards,
mike
It’s a flip-flop, so if you do it in software a flip-flop might as well be 1 bit of memory.
You’re going to want to look a the LED in a real program and know if it’s on or off,
so will usually want to store the LED state which would usually represent some program state.
Code:flipflop var bit ‘ 1 = LED is on 0 = LED is off debounce var byte ‘ button debounce counter flipflop = 0 ‘ start with LED off at power up, or on if you want to debounce = 0 ‘ reset debounce counter trisb.0 = 1’ button pin input trisb.7 = 0’ LED pin output cycle: 'program cycle if debounce > 199 then if portb.0 = 1 then flipflop = 1 debounce = 0 else flipflop = 0 debounce = 0 endif endif if flipflop = 1 then ‘ set LED to flip flop state portb.7 = 1 else portb.7 = 0 endif if debounce < 200 then ‘ increment button debounce counter debounce = debounce + 1 endif goto cycle ‘ repeat loop forever
But that's only using 1 button Art not 2 as in the title of the thread.....
Dave Purola,
N8NTA
EN82fn
Whoops!
No need to accommodate contact bounce for the buttons then.
Code:flipflop var bit ‘ 1 = LED is on 0 = LED is off flipflop = 0 ‘ start with LED off at power up, or on if you want to trisb.0 = 1’ buttonA pin input ON trisb.1 = 1’ buttonB pin input OFF trisb.7 = 0’ LED pin output cycle: 'program cycle if portb.0 = 1 then flipflop = 1 ‘ set memory bit endif if portb.1 = 1 then flipflop = 0 ‘ reset memory bit endif portb.7 = flipflop ‘ set LED on or off goto cycle ‘ repeat loop forever
Now, Thats nice and easy. The only thing I would change is not having a variable for the state of the output pin but reading the output state.
Dave Purola,
N8NTA
EN82fn
In the long run, for midrange pics that don’t have a port latch register,
we should be using a byte port latch to avoid RWM error if time allows.
So it would go, write single bit to port latch byte, write entire port latch byte to port, read back bit from port latch byte.
Not that I can say I’ve ever encountered a problem I’d put down to RWM error.
Bookmarks