newbie to interrupts...
johnny_b
Posts: 28
Hi guys,
I just moved some simple projects from stamp to sx. This is the first time I am attempting to use interrupts.
For the trial, I used a serial (custom) 2x16 LCD, with some text displaying, and I wanted to use 3 buttons
connected to 3 interrupt ports, each one lighting·a LED when pressed, LED off when depressed, continuously
and realtime, independently from the scrolling text. Simple and have no meaning, I know , but just for
trying them... Anyway, it did not work. So where did I go wrong? (.sxb attached)
Please help!!!
br, Johnny
(ps. sorry for custom LCD commands...)
I just moved some simple projects from stamp to sx. This is the first time I am attempting to use interrupts.
For the trial, I used a serial (custom) 2x16 LCD, with some text displaying, and I wanted to use 3 buttons
connected to 3 interrupt ports, each one lighting·a LED when pressed, LED off when depressed, continuously
and realtime, independently from the scrolling text. Simple and have no meaning, I know , but just for
trying them... Anyway, it did not work. So where did I go wrong? (.sxb attached)
Please help!!!
br, Johnny
(ps. sorry for custom LCD commands...)
Comments
let me look at it alittle more.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
DTQ
1. Yes, you need to take care of de-bounce. Switches 'bounce' on-off-on-off for a few milliseconds when activated. The symptom you should see with your current code is when you press the button the led's flicker for a bit, then stabilize randomly on or off.
2. I don't know what you are using for a voltage source for your buttons -- you can't just connect them between the SX pin an +5, you also need a 'pull-down' resistor to give you a 'hard' zero. See the "Button" command in the BS2 PBasic manual for a suggested circuit.
you're right, this is the symptom, it flickers randomly. what's more interesting, that sometimes a different led is also activated...????? (trial2.sxb)
the tricky part in this design that some pins on port B are not interrupts, and I do not really know, how to separate them from each other?
and what are these
WKPND_B = %00000000
WKED_B = %11111111
WKEN_B = %00011111
lines mean at all? do I set their values bit-by-bit, or what? the values in the code were obtained by trying several possible combinations
please explain it to me like to a 6 year old
johnny
1) The SX has programmable internal pullup resistors. (MODE $0E)
2) The random action on some inputs when activating other inputs is usually due to the lack of pullups (or pulldowns)
3) When you enable interrupts, using the MODE $0B, you define what inputs will be interrupt enabled.· (eg. MOV !rb, #%11111110 enables interrupt only on rb.0 )
4) See SX-Key Development System Manual Section 10.