Stopping repeated messages
Currently the pic we are working with monitors pin status and sends a simple string out when one of them is pulled high. The problem I am having now is that the pic repeats the proper code over and over while the pin is still high. I need a suggestion on how to get the pic to send the message once and then go back to monitoring the rest of the pins even while the first one is high and NOT repeat the first one or any other that is triggered more then once. I need it to be able to repeat the same procedure for other pins if they also go high. Once the pins go low, it can go back to normal.
If it would be easier, it is being sent to a VB application and I can deal with it on that side if the coding would be easier.
Code:
Basic idea of what I have now.
:Watch
if Portb.1 then Alarm1
if Portb.2 then Alarm2
if Portb.3 then Alarm3
Goto Watch
:Alarm1
HSerout [Blah Blah]
goto watch
Re: Stopping repeated messages
set a flag to indicate the old status of the port pin. If the port goes high, and the flag is low, send the alarm and set the flag high. If the flag is high, ignore the port. When the port goes low, clear the flag
Re: Stopping repeated messages
What about setting a variable in the EEPROM that is checked when sent to Alarm1 and if it is already set return to Watch? Have it monitor for pin low as well as high and clear the value in memory if low?
Re: Stopping repeated messages
Quick reply CNC. Thank you.
Re: Stopping repeated messages
EEPROM will get pretty tired of all the writes. If you don't need it to be persistent when powered off, just use ram
Re: Stopping repeated messages
I'm still learning Picbasic but could you give me an example of setting a simple flag? Something like Zone1Alarm = True when triggered then Zone1Alarm = false when cleared.
Re: Stopping repeated messages
I usually have at least 1 byte dedicated to flagss, so
then to set up the flags its just this:
Code:
alarm1F var myflags.0
alarm2F var myflags.1
alarm3F var myflags.2
...
then to use them it is this simple:
Code:
alarm1F = 1
alarm2F = 0
...
or
myflags = 0 'this clears all flags
then for you case:
Code:
if portb.0 then
gosub alarm1
else
alarm1F = 0
endif
...
return
alarm1:
if alarm1F then return
alarm1F = 1
hser bla bla bla
hope that helps :)
Re: Stopping repeated messages