Spin programming question, pretty basic
iQuit
Posts: 78
I was wondering if the call to scan in the code listed below, can cause problems with the stack of the propeller.
Scan is called within getkey, and Display, so does the stack get, somehow, out of sync? The reason for call was to avoid going back to main
each time. I've done this sort of thing with the BS2, but am new to the propeller. And when learning something new, it's kind of easy to flow off
on some strange tangent that the experienced wouldn't even consider.
Thank you.
P.S. Don't know why the font below is large. Tried to edit it several times to no avail.
VAR
Byte key
PUB Main '++++++++++++++++++
pst.Start(115_200)
pst.clear
DIRa[noparse][[/noparse]0..4]~ 'pins 0-3 used as bin input, pin 4 used as data avial.
Scan
PUB Scan '
waitcnt(clkfreq/5 + cnt)
repeat
if INa 'data available from 8870
getkey
waitcnt(clkfreq/1000 + cnt)
PUB getkey '
key := INa[noparse][[/noparse]3..0] 'set key to pins 0 - 3
if key == 10 '10 equates to zero
key := 0
case key
11: pst.char("*") 'star key
pst.newline
Scan
12: pst.char("#") 'pound key
pst.newline
Scan
Display
PUB Display '
pst.dec(key)
pst.newline
Scan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"She may not be very pretty now, but she was somebody's baby once." Bugs Bunny
Post Edited (iQuit) : 4/17/2010 5:53:28 AM GMT
Scan is called within getkey, and Display, so does the stack get, somehow, out of sync? The reason for call was to avoid going back to main
each time. I've done this sort of thing with the BS2, but am new to the propeller. And when learning something new, it's kind of easy to flow off
on some strange tangent that the experienced wouldn't even consider.
Thank you.
P.S. Don't know why the font below is large. Tried to edit it several times to no avail.
VAR
Byte key
PUB Main '++++++++++++++++++
pst.Start(115_200)
pst.clear
DIRa[noparse][[/noparse]0..4]~ 'pins 0-3 used as bin input, pin 4 used as data avial.
Scan
PUB Scan '
waitcnt(clkfreq/5 + cnt)
repeat
if INa 'data available from 8870
getkey
waitcnt(clkfreq/1000 + cnt)
PUB getkey '
key := INa[noparse][[/noparse]3..0] 'set key to pins 0 - 3
if key == 10 '10 equates to zero
key := 0
case key
11: pst.char("*") 'star key
pst.newline
Scan
12: pst.char("#") 'pound key
pst.newline
Scan
Display
PUB Display '
pst.dec(key)
pst.newline
Scan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"She may not be very pretty now, but she was somebody's baby once." Bugs Bunny
Post Edited (iQuit) : 4/17/2010 5:53:28 AM GMT
Comments
12 to an *, and the number 13 to the # for display. I'll use the actual values in the actual code--no display needed there.
I will clean it up for the final version, thanks.
So do you think that my original concern is not an issue? The stack?
Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"She may not be very pretty now, but she was somebody's baby once." Bugs Bunny
You don't seem to understand what my question is. I know that this is not optimal in its execution, but it does work. Works quite well for what I need it to do.
My real question is concerning the stack; pushing and popping to and from it. It seems that if i call Scan from several different methods, that the implied return
for that method is never implimented? And if so, does this mess-up the stack?
My question is more about how the calls and returns are handled in Spin than it is about my code's syntax.
Of course, the syntax, as I know, can cause funny behavior. But it does behave as expected. Once I have all of the pieces in place, I can optimize the code by
using what you mentioned. If you don't mind, that is.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"She may not be very pretty now, but she was somebody's baby once." Bugs Bunny