PDA

View Full Version : BS2sx



leshea2
08-18-2005, 04:44 AM
How would I add another line of code to this command, if I want to make the BS2sx stamp flash an LED on and off once, to confirm the this part of the code,

Send_Msg:
DO
READ eePntr, char
eePntr = eePntr + 1
IF (char = 0) THEN EXIT
SEROUT Sout, Baud, [char]
LOOP
RETURN


was successful executed ?

Thanks !


' {$STAMP BS2sx}
' {$PBASIC 2.5}

Sout PIN 0

Baud CON 17405

eePntr VAR Word
char VAR Byte

Msg1 DATA "Call 18004459889 at 4:35 p.m.", 0


Main:
eePntr = Msg1
GOSUB Send_Msg
END


Send_Msg:
DO
READ eePntr, char
eePntr = eePntr + 1
IF (char = 0) THEN EXIT
SEROUT Sout, Baud, [char]
LOOP
RETURN

Jon Williams
08-18-2005, 05:02 AM
Is this a trick question?...

Success:
· HIGH Led
· PAUSE 100
· LOW Led

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

leshea2
08-18-2005, 05:23 AM
So will this code work, I mean will both of the commands in this code work ?



' {$STAMP BS2sx}
' {$PBASIC 2.5}

Sout PIN 0

Baud CON 17405

eePntr VAR Word
char VAR Byte

Msg1 DATA "Call 18004459889 at 4:35 p.m.", 0


Main:
eePntr = Msg1
GOSUB Send_Msg
END


Send_Msg:
DO
READ eePntr, char
eePntr = eePntr + 1
IF (char = 0) THEN EXIT
SEROUT Sout, Baud, [char]
LOOP
RETURN

HIGH Led
PAUSE 100
LOW Led

END

Paul Baker
08-18-2005, 05:31 AM
No,


HIGH Led
PAUSE 100
LOW Led

is never executed since the above function has been RETURNed from and the code never jumps to the LED flashing code. Additionally you have not specified which pin Led is defined as. Either create a new subroutine and GOSUB to it after you've "GOSUB Send_Msg" or just place the code itself after GOSUB Send_Msg, or place the code before the RETURN. Somewhere the execution of your program·must flow through the commands in order for them to be performed, what you have done is created a "dead code" section, meaning you have valid code that is never called or executed.

You seem to be fundamentally confused on some basic aspects of programming, Please read "What's a Microcontroller" in the Downloads>Stamps In Class section. It is a primer on using the basic stamp and covers alot of the fundamental topics you are confused about.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10

Post Edited (Paul Baker) : 8/17/2005 10:34:58 PM GMT

leshea2
08-18-2005, 05:46 AM
Will this work or should I put the Flash LED code before the loop command reference ?

' {$STAMP BS2sx}
' {$PBASIC 2.5}

Sout PIN 0

Baud CON 17405

eePntr VAR Word
char VAR Byte

Msg1 DATA "Call 18004459889 at 4:35 p.m.", 0


Main:
eePntr = Msg1
GOSUB Send_Msg
END


Send_Msg:
DO
READ eePntr, char
eePntr = eePntr + 1
IF (char = 0) THEN EXIT
SEROUT Sout, Baud, [char]
LOOP

HIGH 0
PAUSE 1000
LOW 0
PAUSE 1000

END

Paul Baker
08-18-2005, 05:48 AM
dagnabit stupid anti-spam filter, Id swear thats longer than 20 seconds.

Jon and I have been bumping heads answering the question, we kept editing our two posts simulataneously adding the same info, anyways to recap (since the post has been edited and Jon has since removed his).

This code should work:

' {$STAMP BS2sx}
' {$PBASIC 2.5}

Sout PIN 0

Led· PIN 2

Baud CON 17405

eePntr VAR Word
char VAR Byte

Msg1 DATA "Call 18004459889 at 4:35 p.m.", 0


Main:
eePntr = Msg1
GOSUB Send_Msg
END


Send_Msg:
DO
READ eePntr, char
eePntr = eePntr + 1
IF (char = 0) THEN EXIT
SEROUT Sout, Baud, [char]
LOOP
HIGH Led
PAUSE 100
LOW Led
RETURN

END

place your LED on pin 2 or redefine the pin in the code.

Also Jon suggested using·"DEBUG char"·function in place of··"SEROUT Sout, Baud, [char]", this will output the data to your debug terminal instead of the serial line thereby verifying the data would be sent correctly on the serial line.


<EDIT> Your adjusted code doesn't have a return anymore, the code will work, but it is not good programming practice to not RETURN from a GOSUB </EDIT>

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10

leshea2
08-18-2005, 05:53 AM
Thanks for all you help !

P.S.
Can I use GOTO main: instead of RETURN

Paul Baker
08-18-2005, 05:57 AM
Oh and please please please read "What's a Microcontroller", quite a few of us start to get a bit testy being asked questions that are answered in free downloadable documents.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10

Jon Williams
08-18-2005, 11:39 AM
Yes, please do read WAM.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax