Code Help Please!!!
Archiver
Posts: 46,084
Hi All:
It's not that I haven't tried . I have been at it for over 30 hours on a
small bit of code for my project and cannot get this right. I know it is
probably real simple but I am brain dead on this section.
Let me explain. This code is for a home alarm system. I have 48 input
indicators all looked at by a shift in. all the incomming bits work fine.
I have 16 for burglar 16 for fire and 16 for status. Only 7 of the 16
Status bits are used the rest are spare.
Bit 0 of the Status is if the house armed (Alarm is active and turned on)
Bit 1 of the status is if the rear building armed.
The armed (active) condition of these 2 bits are low High if the alarm is
not set.
Once any one of these bits go active (low) (usually for hours at a time) the
program is to issue a serout command of 5 characters. by serout
16,16624,[noparse][[/noparse]"SHBA",cr] or a SRBA standing for Status H/R BA burglar active to
the PC.
This command should only be issued ONCE and not issued again till the bit
status again goes to 0 (low again) This way I don't have a continuous stream
of data to the PC.
I am looking at these bits with the IF INSTATUS.BITx command. x being a 0 or
1 (I see them OK with the debug and changing correctly)
One extra additional part of the program in fact the next subroutine after
the beast above checks the house and the rear building to issue a S H/R CL
command (House or Rear is clear if the conditions are NO house fire or NO
house burglar or NO house trouble or (NO house burglar armed).** The
previous routine I am having trouble with. Again the same routine is
checked for the Rear Building.
I am not a newbie and feel like a real dummy asking for help on this.
However after 30 hours and yelling at the dog twice fI igured I would rather
admit defeat and ask you all for help because Marcus (dog) cannot take more
yelling at..
Thanks
Rick
It's not that I haven't tried . I have been at it for over 30 hours on a
small bit of code for my project and cannot get this right. I know it is
probably real simple but I am brain dead on this section.
Let me explain. This code is for a home alarm system. I have 48 input
indicators all looked at by a shift in. all the incomming bits work fine.
I have 16 for burglar 16 for fire and 16 for status. Only 7 of the 16
Status bits are used the rest are spare.
Bit 0 of the Status is if the house armed (Alarm is active and turned on)
Bit 1 of the status is if the rear building armed.
The armed (active) condition of these 2 bits are low High if the alarm is
not set.
Once any one of these bits go active (low) (usually for hours at a time) the
program is to issue a serout command of 5 characters. by serout
16,16624,[noparse][[/noparse]"SHBA",cr] or a SRBA standing for Status H/R BA burglar active to
the PC.
This command should only be issued ONCE and not issued again till the bit
status again goes to 0 (low again) This way I don't have a continuous stream
of data to the PC.
I am looking at these bits with the IF INSTATUS.BITx command. x being a 0 or
1 (I see them OK with the debug and changing correctly)
One extra additional part of the program in fact the next subroutine after
the beast above checks the house and the rear building to issue a S H/R CL
command (House or Rear is clear if the conditions are NO house fire or NO
house burglar or NO house trouble or (NO house burglar armed).** The
previous routine I am having trouble with. Again the same routine is
checked for the Rear Building.
I am not a newbie and feel like a real dummy asking for help on this.
However after 30 hours and yelling at the dog twice fI igured I would rather
admit defeat and ask you all for help because Marcus (dog) cannot take more
yelling at..
Thanks
Rick
Comments
hugs102@b... writes:
> Once any one of these bits go active (low) (usually for hours at a time) the
> program is to issue a serout command of 5 characters. by serout
> 16,16624,[noparse][[/noparse]"SHBA",cr] or a SRBA standing for Status H/R BA burglar active to
> the PC.
>
>
Eric, could you say something like
if bit = 1 then somewhere - (somewhere being a label that will let you skip
the serout)
Hear you got about 8 inches of snow !! We don't have that in Central Florida.
Take care
Sid
[noparse][[/noparse]Non-text portions of this message have been removed]
>program is to issue a serout command of 5 characters. by serout
>16,16624,[noparse][[/noparse]"SHBA",cr] or a SRBA standing for Status H/R BA burglar active to
>the PC.
>
>This command should only be issued ONCE and not issued again till the bit
>status again goes to 0 (low again) This way I don't have a continuous stream
>of data to the PC.
>
>I am looking at these bits with the IF INSTATUS.BITx command. x being a 0 or
>1 (I see them OK with the debug and changing correctly)
Hi Eric,
The trick is to keep track of the old state of the bits. Detect
change in state using the operators ^ (XOR, so the result bits is 1
only if the two input bits, the new and the old, are different),
along with & (AND which can distinguish a change from 1->0 from a
change 0->1).
oldinstatus var byte
instatus var byte
changeinstatus var byte
initial:
oldinstatus=instatus ' initial state of all bits?
mainloop:
changeinstatus = instatus ^ oldinstatus & oldinstatus
' contains non zero bits only if there is a change from 1->0
' on any bit
branch changeinstatus, [noparse][[/noparse]nochange]
gosub processchangestatus
nochange:
oldinstatus=instatus ' update the state variable
' and so on
goto mainloop
processchangestatus:
' come to this subroutine if there has been a change 1->0 on any bit
branch changeinstatus.bit0,[noparse][[/noparse]nextbit1]
serout 16,16624,[noparse][[/noparse]"SHBA",cr] ' do this if bit0 changes from 1->0
nextbit1:
branch changeinstatus.bit0,[noparse][[/noparse]nextbit2]
serout 16,16624,[noparse][[/noparse]"SRBA",cr] ' do this if bit1 changes from 1->0
nextbit2:
' and so on through all relevant bits
return ' to "nochange"
I hope that helps, both you, and poor beleaguered Marcus!
-- Tracy
> Hi All:
>
> It's not that I haven't tried . I have been at it for over 30 hours on a
> small bit of code for my project and cannot get this right. I know it is
> probably real simple but I am brain dead on this section.
I'm not sure if your problem is grasping the bit twiddling or
doing the stamp basic... but I think xor might be handy for you.
I'd consider something like this... (I'm just going to quickly
psudocode it). Hopefully it'll give you some new ideas.
hold = status
loop:
get status
if (status ^ hold) 'XOR check for change in status bits
{
hold = status ' save new status
if not status ' if either status bit is 0
{
send status to pc
}
}
goto loop
Michael Burr
Thanks so very much!!!!!! It was the XOR with the & that helped solve it.
Marcus sends 2 BIG LICKS. and I send my sincere THANKS SO MUCH and Happy
Holidays
Eric
Original Message
From: "Tracy Allen" <tracy@e...>
To: <basicstamps@yahoogroups.com>
Sent: Saturday, December 07, 2002 2:39 PM
Subject: Re: [noparse][[/noparse]basicstamps] Code Help Please!!!
> >Once any one of these bits go active (low) (usually for hours at a time)
the
> >program is to issue a serout command of 5 characters. by serout
> >16,16624,[noparse][[/noparse]"SHBA",cr] or a SRBA standing for Status H/R BA burglar active
to
> >the PC.
> >
> >This command should only be issued ONCE and not issued again till the bit
> >status again goes to 0 (low again) This way I don't have a continuous
stream
> >of data to the PC.
> >
> >I am looking at these bits with the IF INSTATUS.BITx command. x being a 0
or
> >1 (I see them OK with the debug and changing correctly)
>
> Hi Eric,
>
> The trick is to keep track of the old state of the bits. Detect
> change in state using the operators ^ (XOR, so the result bits is 1
> only if the two input bits, the new and the old, are different),
> along with & (AND which can distinguish a change from 1->0 from a
> change 0->1).
>
> oldinstatus var byte
> instatus var byte
> changeinstatus var byte
>
> initial:
> oldinstatus=instatus ' initial state of all bits?
>
> mainloop:
> changeinstatus = instatus ^ oldinstatus & oldinstatus
> ' contains non zero bits only if there is a change from 1->0
> ' on any bit
> branch changeinstatus, [noparse][[/noparse]nochange]
> gosub processchangestatus
> nochange:
> oldinstatus=instatus ' update the state variable
> ' and so on
> goto mainloop
>
> processchangestatus:
> ' come to this subroutine if there has been a change 1->0 on any bit
> branch changeinstatus.bit0,[noparse][[/noparse]nextbit1]
> serout 16,16624,[noparse][[/noparse]"SHBA",cr] ' do this if bit0 changes from 1->0
> nextbit1:
> branch changeinstatus.bit0,[noparse][[/noparse]nextbit2]
> serout 16,16624,[noparse][[/noparse]"SRBA",cr] ' do this if bit1 changes from 1->0
> nextbit2:
> ' and so on through all relevant bits
> return ' to "nochange"
>
> I hope that helps, both you, and poor beleaguered Marcus!
>
> -- Tracy
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
Between you and Tracy it is working great. I thank you again for your input
Eric
Original Message
From: "Michael Burr" <mburr@b...>
To: <basicstamps@yahoogroups.com>
Sent: Saturday, December 07, 2002 2:42 PM
Subject: Re: [noparse][[/noparse]basicstamps] Code Help Please!!!
> Eric Adams wrote:
>
> > Hi All:
> >
> > It's not that I haven't tried . I have been at it for over 30 hours on
a
> > small bit of code for my project and cannot get this right. I know it
is
> > probably real simple but I am brain dead on this section.
>
> I'm not sure if your problem is grasping the bit twiddling or
> doing the stamp basic... but I think xor might be handy for you.
> I'd consider something like this... (I'm just going to quickly
> psudocode it). Hopefully it'll give you some new ideas.
>
> hold = status
> loop:
> get status
> if (status ^ hold) 'XOR check for change in status bits
> {
> hold = status ' save new status
> if not status ' if either status bit is 0
> {
> send status to pc
> }
> }
> goto loop
>
>
> Michael Burr
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>