select problem
hijker
Posts: 10
hello, who can tell me what's wrong with the select statement.
I can't get it to work.
' {$STAMP BS2}
commando var byte
commando = 2
select commando
case 1
TOGGLE 15
case 2
TOGGLE 14
case 3
TOGGLE 13
case 4
TOGGLE 12
case else
HIGH 15:HIGH 14:HIGH 13:HIGH 12
endselect
I can't get it to work.
' {$STAMP BS2}
commando var byte
commando = 2
select commando
case 1
TOGGLE 15
case 2
TOGGLE 14
case 3
TOGGLE 13
case 4
TOGGLE 12
case else
HIGH 15:HIGH 14:HIGH 13:HIGH 12
endselect
Comments
SELECT/CASE is a farily new addition to the PBASIC command set. You must instruct the Stamp Editor to use the latest rules and conventions, if you use newer commands. Place the following after the $STAMP directrive in your program:
' {$PBASIC 2.5}
per the information found in the online PBASIC Help file.
Regards,
Bruce Bates
HIGH OUTD
where OUTD represents pins 15, 14, 13, 12 as·a group.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ken
Post Edited (KenM) : 7/24/2005 2:22:32 PM GMT
·· Something to be aware of when using OUT commands.· First of all, unlike TOGGLE and HIGH, the OUT commands (Such as OUTD) do not make the pins outputs.· In his code if the commando variable doesn't equal any of the first case statements, none of the pins would be HIGH then.· With the value he has preset only that one selected pin would be an output.
·· The idea is sound, all you would have to do is make sure that the direction registers·are set first to ensure these pins were outputs (DIRD = %1111).
NOTE:· I see your post has been edited, making part of mine no longer make sense...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 7/28/2005 3:05:29 AM GMT
' {$PBASIC 2.5}
every thing works fine.
· HIGH OUTD
is bogus -- that is, it will not do what you want (make pins P12..P15 all high).· Remember that HIGH will accept a variable as its pin parameter, and OUTD is a nib variable.· So the command above will read the value of OUTD and set that single pin HIGH.
If the pins are already outputs, you can do this:
· OUTD = %1111
If the pins haven't been defined as outputs, you'll need two lines:
· DIRD = %1111
· OUTD = %1111
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ken