Program problem with a delauy
Newzed
Posts: 2,503
This post will read better if you expand the screen.
I have a menu-driven program that, among other things, returns the temperture from 3 locations if I press "N".· I wanted to introduce a delay so that if no menu option was selected within 5 minutes, the program would automatically execute the "N" routine.· I wrote the following:
PRI getChoice : selectedOption
· repeat
··· rxtime(2)
···· if rxtime(25000) == 0
······ senddata("Q")··· '"N" routine
······ waitcnt(clkfreq/10 + cnt)····
······ senddata("Q")
······ recdata
······ start
··· repeat until selectedOption := key.key··
··· if (selectedOption => "a") and (selectedOption =< "z"")························
····· selectedOption -= 32··· '32 = ("a" - "A")·
···· ' Convert letters to··uppercase·····························
· until (lookdown (selectedOption : "TGNRS"))
PUB rxtime(ms) : rxbyte | t
'' Wait ms milliseconds for a byte to be received
'' returns·0 if no byte received, $00..$FF if byte
· t := cnt
· repeat until (rxbyte := key.key) or (cnt - t) / (clkfreq / 1000) > ms
With the above, the program waits for about 25 seconds.· If there is no key press within that time, then it executes the "N" routine.· The program will not execute an rxtime of greater than 25000 because a 32 bit compare is only good for about 50/2 seconds.
Can anyone·modify the above so that I can get a wait period of up to 5 minutes?· If I want to select another menu option during the 25 seconds wait, I can do·so, ·but I have to press the selected key twice.· I can live with that if there is no alternative.
Sid
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
I have a menu-driven program that, among other things, returns the temperture from 3 locations if I press "N".· I wanted to introduce a delay so that if no menu option was selected within 5 minutes, the program would automatically execute the "N" routine.· I wrote the following:
PRI getChoice : selectedOption
· repeat
··· rxtime(2)
···· if rxtime(25000) == 0
······ senddata("Q")··· '"N" routine
······ waitcnt(clkfreq/10 + cnt)····
······ senddata("Q")
······ recdata
······ start
··· repeat until selectedOption := key.key··
··· if (selectedOption => "a") and (selectedOption =< "z"")························
····· selectedOption -= 32··· '32 = ("a" - "A")·
···· ' Convert letters to··uppercase·····························
· until (lookdown (selectedOption : "TGNRS"))
PUB rxtime(ms) : rxbyte | t
'' Wait ms milliseconds for a byte to be received
'' returns·0 if no byte received, $00..$FF if byte
· t := cnt
· repeat until (rxbyte := key.key) or (cnt - t) / (clkfreq / 1000) > ms
With the above, the program waits for about 25 seconds.· If there is no key press within that time, then it executes the "N" routine.· The program will not execute an rxtime of greater than 25000 because a 32 bit compare is only good for about 50/2 seconds.
Can anyone·modify the above so that I can get a wait period of up to 5 minutes?· If I want to select another menu option during the 25 seconds wait, I can do·so, ·but I have to press the selected key twice.· I can live with that if there is no alternative.
Sid
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
Comments
repeat ms
rxbyte := key.key
if rxbyte
quit
waitcnt(clkfreq/1000 + cnt)
This assumes that a 1 millisecond sampling rate of the keyboard is fast enough. You can wait 2^32 milliseconds, a long time.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
That's what I get for being in a hurry and using the quick reply.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·