PDA

View Full Version : toggling bits



tazntex
- 4th February 2008, 22:05
Hello Everyone,
If I send the value of a variable out ,
SEROUT SerPin,N2400,[PreAmble,Synch,PORTB]' sending Pic
and I receive it,
SERIN serpin,N2400,[9],PORTB' on the receiving Pic
PORTB.0 if it is a 1, I want PORTB.0 on the receiving Pic to stay a 1 and all of the other bits to be the rest of what it received so I can set PORTB. I would like PORTB.0 to remain High until it received another 1 on bit0. In this way I can keep a master relay on and PORTB bits 1-7 will change state as the data is received. If PORTB is my variable, and I create a another variable, car var PORTB.0 Will everytime PORTB is received does the value of car change its value or can I hold car value until PORTB.0 =1? So if PORTB.0 becomes a 1 again I want the value of car to be 0 so I can turn off the relay. Thanks

Darrel Taylor
- 5th February 2008, 21:13
If I understood the question correctly, this might work ...

RXchar VAR BYTE

SERIN serpin,N2400,[9], RXchar

IF RXchar.0 = 1 THEN TOGGLE PORTB.0
PORTB = (PORTB & 1) | (RXchar & $FE)

tazntex
- 5th February 2008, 22:42
I will give it a try, Thank you!!