PDA

View Full Version : Stopping repeated messages



GatorGuy
- 20th October 2011, 19:14
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.



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

cncmachineguy
- 20th October 2011, 19:16
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

GatorGuy
- 20th October 2011, 19:16
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?

GatorGuy
- 20th October 2011, 19:17
Quick reply CNC. Thank you.

cncmachineguy
- 20th October 2011, 19:19
EEPROM will get pretty tired of all the writes. If you don't need it to be persistent when powered off, just use ram

GatorGuy
- 20th October 2011, 19:24
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.

cncmachineguy
- 20th October 2011, 19:34
I usually have at least 1 byte dedicated to flagss, so


myflags var byte

then to set up the flags its just this:


alarm1F var myflags.0
alarm2F var myflags.1
alarm3F var myflags.2
...

then to use them it is this simple:


alarm1F = 1
alarm2F = 0
...

or
myflags = 0 'this clears all flags


then for you case:


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 :)

GatorGuy
- 20th October 2011, 19:40
Pure Gold! Thank you!