Basic Stamp Multi-tasking
Michael Garkie
Posts: 3
Hi,
I am new to the forum, and have been playing around with Stamps for a week or so. I have a question:
If my stamp is listening for an RS232 command with SERIN, how do I do other things, like blink LED's while it's waiting?
Is there any way to make a button command command or anything else interrupt the SERIN waiting for an incoming string?
Thanks
Mike Garkie
Garkie Digital
I am new to the forum, and have been playing around with Stamps for a week or so. I have a question:
If my stamp is listening for an RS232 command with SERIN, how do I do other things, like blink LED's while it's waiting?
Is there any way to make a button command command or anything else interrupt the SERIN waiting for an incoming string?
Thanks
Mike Garkie
Garkie Digital
Comments
serin pin, baud, [noparse][[/noparse]data]
Try this:
Start:
serin pin, baud, 1000, blink,[noparse][[/noparse]data]
'if you get serin then do what you want
blink:
high led
pause 200
low led
goto start
if no serin within 1 second, program jumps to blink:, blinks led once, then goes back to serin.· The jump to blink will cost you about 200ms.· If that is too long you can shorten the blink time to 100.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
New Combo LCD Backpack
http://hometown.aol.com/newzed/index.html
Post Edited (Newzed) : 11/7/2004 7:36:49 PM GMT
Beyond that, there are programming schemes that can make the BASIC Stamp (or any single-tasking controller) "appear" to be doing many things at once. The key is to setup a task-manager that handles important things through every program loop iteration, then divide the other task on each successive loop.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Thanks.
As you can see, you put your important task in the top part of the main loop.· After it's done, the program will call on a task based on the value of 'state.'· Within each task subroutine, the task code is handle, then the next task is pointed to -- unless there is some problem that needs to be dealt with first.· By breaking the program into small subroutine tasks, you can make things quite flexible and efficient.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
I'll try these routines today. Also, I read a thread in the archives about character buffer chips for the stamps. The MAX3100 and a PIC with code by S. Parkis were mentioned. If I used a chip like this ahead of the stamp, could it hold incoming characters and then signal the stamp when there was someting to read by SERIN?
Thanks,
Mike Garkie
Garkie Digital
http://www.wd5gnr.com/suart.htm·-- past project of the month.
Al Williams
AWC
http://www.awce.com
·
Note that the Stamp SERIN command also has a hardware flow control option. If the device that your Stamp is talking to can also do hardware flow control, the wait and response can be very tight.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com