
Originally Posted by
oneohthree
'Transmitter Code
Include "Modedefs.bas"
main:
v var byte : counter var byte : encoded var byte : v = %1100
'Manchester encoding
For counter = 0 to 3
If v.0[counter]=0 Then
encoded.0[counter*2]=0 : encoded.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
Else
encoded.0[counter*2]=1 : encoded.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
EndIf
Next counter : serout PORTB.0, n2400, [ $55 , $55 , $55 , $55 , $55 , $55 ,$aa , encoded ] 'send out code
write 0, encoded
High 1
Pause 1000
Low 1
goto main
'Receiver Code
Include "Modedefs.bas"
s var byte : B0 var byte : B1 var byte : 's is byte to be encoded, B0 and B1 is byte
counter var byte : cnt55 var byte : cntaa var byte 'counter is byte and cnt55 is byte
encoded1 var byte : action var byte : alert var byte : B0=1 : B1=1
'encoded1 word sized variable that holds encoded byte v, alert variable, action variable, B0 and B1 hardwired address
s=0: encoded1=0
main:
cnt55 = 0 : cntaa = 0 'counter for $55 & $aa is zero
waitfor55:
serin PORTB.0, t2400, encoded1 'take in data at pin 0 and place in encoded1
if encoded1 = $55 then
cnt55 = cnt55 + 1 '$55 read, increase cnt55 by 1
if cnt55 > 3 then goto waitforaa 'if $55 occurs more than 3 times 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, n2400, encoded1
if encoded1 <> $aa then
cntaa = cntaa + 1
if cntaa > 5 then goto main 'restart, incorrect leader bit
endif
serin PORTB.0, n2400, encoded1 : serout PORTB.4, n2400, [encoded1] 'take in from pin 0 to encoded 1 output to pin 3 contens in encoded1
write 0,encoded1
High 7
Pause 10000
Low 7
'Decoding
For counter=0 to 3:s.0[counter]=encoded1.0[counter*2]:Next counter
serout PORTB.3, n2400, [s] 'Ouptut decoded message
write 1, s
High 6
Pause 10000
Low 6
'Tracking code
If (s.2==0) & (s.3==0) Then 'if the code matches 00
If (s.0==B0) & (s.1==B1) Then 'if the address matches then
s.2=1: action = s.2: 'set the third bit to 1 and send it back
alert = 0:
serout PORTB.1, n2400, [s] 'output to pin 1 value in s
Else
s.2=0: action = s.2: 'do not change anything and send back
alert = 0:
serout PORTB.2, n2400, [s] 'output to pin 1 value in s
Endif
Endif
'Tracking and Finding code
If (s.2==0) & (s.3==1) Then 'if code matches 01 then
If (s.0==B0) & (s.1==B1) Then 'If the address matches then
s.2=1: action=s.2: 'set the third bit to 1 and send back
alert=1:
serout PORTB.6, n2400, [s]: 'output to pin 1 value in s
High 2 'set alert to 1 and make pin 2 high.
Else
s.2=0: action=s.2: 'do not change anything and send back
alert=0:
serout PORTB.5, n2400, [s] 'output to pin 1 value in s
Endif
Endif
Bookmarks