'Transmitter Code
Include "Modedefs.bas"
v var byte : counter var byte : encoded var byte : v = %1101
main:
For counter = 0 to 3
If v.0[counter]=0 Then
encoded.0[counter*2]=0
Else
encoded.0[counter*2]=1 : encoded.0[counter*2+1]=0
EndIf
Next counter : serout PORTB.0, t2400, [ $55 , $55 , $55 , $aa , encoded ]
goto main
'Receiver Code
Include "Modedefs.bas"
s var byte : B0 var byte : B1 var byte : counter var byte : cnt55 var byte
encoded1 var byte : action var byte : alert var byte : B0=1 : B1=1
main:
cnt55 = 0
waitfor55:
serin PORTB.0, t2400, encoded1
if encoded1 = $55 then
cnt55 = cnt55 + 1 'got $55, inc cnt55 by 1
if cnt55 = 3 then goto waitforaa 'if we got 3 in a row check for $aa
else
goto main 'if not $55, reset counter at main and restart
endif
goto waitfor55
waitforaa:
serin PORTB.0, t2400, encoded1
if encoded1 <> $aa then goto main 'restart, didn't get right leader
serin PORTB.0, t2400, encoded1 : serout PORTB.3, t2400, [encoded1]
For counter=0 to 3:s.0[counter]=encoded1.0[counter*2]:Next counter
serout PORTB.3, t2400, [s]
'Tracking code
If (s.2==0) & (s.3==0) Then
If (s.0==B0) & (s.1==B1) Then
s.2=1:action = s.2:alert = 0:serout PORTB.1, t2400, [s]
Else
s.2=0:action = s.2:alert = 0:serout PORTB.1, t2400, [s]
Endif
Endif
'Tracking and Finding code
If (s.2==0) & (s.3==1) Then
If (s.0==B0) & (s.1==B1) Then 'If the address matches then
s.2=1:action=s.2:alert=1:serout PORTB.1, t2400, [s]:High 2
Else
s.2=0:action=s.2:alert=0:serout PORTB.1, t2400, [s]
Endif
Endif
Your logic for getting the leader bytes and stuff was messed up, so I rewrote it a bit.
But I still think this is entirely too convoluted.
What exactly are you trying to do? Because this seems a bit goofy to me, all this bit manipulation and such. Even though it's a short program, it just seems to me like you'll get yourself stuck in future trying to figure out what you were trying to do in the first place.
Bookmarks