newbie needs help
I am working on a game that has a count down timer that counts down from 30 seconds.· I have done this through simply adding a pause of 1000 to the program.· It works fine....but while the program is paused, I can not have any inputs be detected.·
My question is there a way to have the counter work seperately from the main program so it does not interfere with the I/Os or do I need to add an external clock?
Thanks in advance for your help.
Zach
·
My question is there a way to have the counter work seperately from the main program so it does not interfere with the I/Os or do I need to add an external clock?
Thanks in advance for your help.
Zach
·
Comments
Robert
Thanks for the quick reply. Pardon my ignorance, but I am not literate in programming and know just a little bit about it.
I have little idea on how to put this into code. Any help would be great.
Zach
Do you have the SX-Key software installed with SX/B? If so look under help, SX/B Help, then example projects. There is one there for a clock/timer that will probably provide an excellent start. I thought I remembered seeing one there and after looking it seems to be closer to what you're looking for than I thought it would.
While you're there take a look at the other examples. They will definitely help you get started.
Good luck on your project.
Robert
I've attached a fairly simple program that does "background" timing. Since you're new it may take some time to come to grips with, but it won't take too long to figure out what's going on. Keep in mind that whenever you do background stuff (with an interrupt), built-in functions that are time-sensitive are adversely affected. In the program I've included a subroutine that replaces PAUSE should you need to do timed delays while the counter is running, or even after the counter is stopped. As with PAUSE, you can't check inputs while DELAY_MS is running, but the counter is still updated if you need that to happen.
You'll see by the listing that you start you timer with the SET_TIMER subroutine and then you can check it at any time for being zero. The demo program starts the timer and watches for it to time out (hit zero) or a button press before lighting an LED. The program is running nicely on my PDB (a great leaning tool for the SX -- get one if you can).
Post Edited (JonnyMac) : 2/22/2008 5:23:15 PM GMT
Thank you very much for the program. I am going to give it a shot on Monday and see what happens. I will most likely have a question or two.
Thanks again,
Zach