Also, should I continue to serout more than once at my receiver microcontroller (RLP-434 output to TLP-315)?
Also, should I continue to serout more than once at my receiver microcontroller (RLP-434 output to TLP-315)?
I increased the amount of $55 at the receiver (to transmit) and kept the amount of $55 that the other receiver needs to detect the same, it seems to be working every time. Also, the data that it is receiving is correct also. So, it seems to be working.
I updated my code and tested it out. But, I noticed that my code does not work in every case. There is one code that only works for one combination (1101) and nothing else. While there is another code that works for other cominbations (0101,0100,1100) but not one cominbation (1101). What I mean by work is it serouts to the 315 MHz transmitter and lights LEDs at the microcontroller after the 315 MHz receiver. When I serout I send about 8-9 $55, then a $aa, then my encoded data. At the microcontroller after the 315 MHz receiver, I tell it to look for 4 $55 instead of the 8 $55 I sent. I am not sure why this behaves weirdly.
Receiver (after 434 MHz receiver and before 315 MHz transmitter) code 1
(works ONLY for 1101)
'IEEE encoding
Include "Modedefs.bas"
'trisb = 0
s var byte : B0 var bit : B1 var bit : encode var byte: encode2 var byte 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
counter var byte : ct55 var byte: counter2 var byte'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
'counter2 counts the number of times acknowledge light blinks.
encode1 var byte : action var byte : alert var byte : action2 var byte: B0=1 : B1=1: counter3 var byte
'encode1 byte sized variable that holds encoded byte s, alert variable, action variable used for trakcing mode, action2 used for track and find mode, B0 and B1 are the hardwired address
c var byte: d var byte: e var byte: s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0
'c (track mode), d (track and find) and e(address) are bytes; initialize all values to zero
'encode holds the encoded variable after ack made in track mode, encode2 holds the encoded variable after ack made in track and find mode.
Main:
Clr:
s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0 'initialize variables to zero
Maina:
ct55 = 0 'counter for $55 is zero
Wait55:
serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
If encode1 = $55 Then
ct55 = ct55 + 1 '$55 read, increase ct55 by 1
If ct55 = 4 Then goto Waitaa 'if $55 occurs 4 times in a row check for $aa
Else
goto maina 'if not $55, reset counter at main and restart
Endif
goto wait55
Waitaa:
serin PORTB.0, n2400, encode1 'wait for $aa
If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
write 0,encode1 'write to EEPROM Location 0
'High 2 'High on Port B Pin 2
'Pause 2000 'Pause
'Low 2 'Low on Port B Pin 2
'Decoding
For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
write 1, s 'write to EEPROM Location 1
'High 6 'High on Port B Pin 6
'Pause 2000 'Pause
'Low 6 'Low on Port B Pin 6
e = s 'Copy s to byte e
If ((e.3=B0) and (e.2=B1)) Then 'Check if address matches (first two bits)
goto L3 'if it matches go to L3
Else
write 2,s 'Write to EEPROM Location 2
High 3 'High on Port B Pin 2
Pause 2000 'Pause
Low 3 'Low on Port B Pin 2
goto Clr
Endif
L3:
'Tracking mode (mode is based on last two bits)
c=s: d=s: 'Copy s to byte c and s to byte d
If ((c.1=0) and (c.0=0)) Then
action=s: 'Copy s to action byte
action.1=1'set the third bit of action1 to 1 and send it back
'alert = 0: 'set alert to 0
write 3, action 'Write to EEPROM Location 3
High 6 'High on Port B in 1
Pause 2000 'Pause
Low 6 'Low on Port B in 1
'Manchester Encoding
For counter = 0 to 3
If action.0[counter]=0 Then
encode.0[counter*2]=0 : encode.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
Else
encode.0[counter*2]=1 : encode.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
EndIf
Next counter :
write 8, encode 'Write encode to EEPROM Location 8
Low 4 'Low on Port B Pin 4
For counter = 0 to 5 'Blink LED 5 times
Pause 400 'Pause
High 4 'High on Port B Pin 4
Pause 400 'Pause
Low 4 'Low on Port B Pin 4
Next counter 'Back to beginning of loop
For counter3 = 0 to 50 'Send three times
serout PORTB.2, n2400, [ $55, $55, $55, $55, $55, $55, $55, $55, $55, $aa , encode ] 'send out preamble and encode on PORTB pin 2
Next counter3 'Next number
goto Clr
Endif
'Tracking and Finding mode (is based on last two bits)
If ((d.1=0) and (d.0=1)) Then
action2=s 'Copy s to action2 byte
action2.1=1 'set the third bit of action2 to 1 and send back
'alert=1
write 4, action2 'Write to EEPROM Location 4
High 5 'High on Port B Pin 4
Pause 2000 'Pause
Low 5 'Low on Port B Pin 4
'Manchester Encoding
For counter = 0 to 3
If action2.0[counter]=0 Then
encode2.0[counter*2]=0 : encode2.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
Else
encode2.0[counter*2]=1 : encode2.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
EndIf
Next counter :
'serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $aa , encode2 ] 'send out preamble and code to Port B Pin 2
write 9, encode2 'Write encode2 to EEPROM Location 9
Low 4 'Low on Port B Pin 4
For counter2 = 0 to 5 'Blink LED 50 times
Pause 400 'Pause
High 4 'High on Port B Pin 4
Pause 400 'Pause
Low 4 'Low on Port B Pin 4
Next counter2 'Back to beginning of loop
Low 1 'Low on Port B Pin 4
For counter = 0 to 50 'Blink LED 50 times
Pause 400 'Pause
High 1 'High on Port B Pin 1
Pause 400 'Pause
Low 1 'Low on Port B Pin 1
Next counter: 'Back to beginning of loop
For counter3 = 0 to 5 'Send data times
serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $55, $55, $55, $aa , encode2 ] 'send out preamble and encode on PORTB pin 2
Next counter3 'Next number
goto Clr
Endif
End
Receiver (after 434 MHz receiver and before 315 MHz transmitter) code 1
(works for 0101, 0100, 1100)
'IEEE encoding
Include "Modedefs.bas"
'trisb = 0
s var byte : B0 var bit : B1 var bit : encode var byte: encode2 var byte 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
counter var byte : ct55 var byte: counter2 var byte'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
'counter2 counts the number of times acknowledge light blinks.
encode1 var byte : action var byte : alert var byte : action2 var byte: B0=1 : B1=1: counter3 var byte
'encode1 byte sized variable that holds encoded byte s, alert variable, action variable used for trakcing mode, action2 used for track and find mode, B0 and B1 are the hardwired address
c var byte: d var byte: e var byte: s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0
'c (track mode), d (track and find) and e(address) are bytes; initialize all values to zero
'encode holds the encoded variable after ack made in track mode, encode2 holds the encoded variable after ack made in track and find mode.
Main:
Clr:
s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0 'initialize variables to zero
Maina:
ct55 = 0 'counter for $55 is zero
Wait55:
serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
If encode1 = $55 Then
ct55 = ct55 + 1 '$55 read, increase ct55 by 1
If ct55 = 4 Then goto Waitaa 'if $55 occurs 4 times in a row check for $aa
Else
goto maina 'if not $55, reset counter at main and restart
Endif
goto wait55
Waitaa:
serin PORTB.0, n2400, encode1 'wait for $aa
If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
write 0,encode1 'write to EEPROM Location 0
'High 2 'High on Port B Pin 2
'Pause 2000 'Pause
'Low 2 'Low on Port B Pin 2
'Decoding
For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
write 1, s 'write to EEPROM Location 1
'High 6 'High on Port B Pin 6
'Pause 2000 'Pause
'Low 6 'Low on Port B Pin 6
e = s 'Copy s to byte e
If ((e.3=B0) and (e.2=B1)) Then 'Check if address matches (first two bits)
goto L3 'if it matches go to L3
Else
write 2,s 'Write to EEPROM Location 2
High 3 'High on Port B Pin 2
Pause 2000 'Pause
Low 3 'Low on Port B Pin 2
goto Clr
Endif
L3:
'Tracking mode (mode is based on last two bits)
c=s: d=s: 'Copy s to byte c and s to byte d
If ((c.1=0) and (c.0=0)) Then
action=s: 'Copy s to action byte
action.1=1'set the third bit of action1 to 1 and send it back
'alert = 0: 'set alert to 0
write 3, action 'Write to EEPROM Location 3
High 6 'High on Port B in 1
Pause 2000 'Pause
Low 6 'Low on Port B in 1
'Manchester Encoding
For counter = 0 to 3
If action.0[counter]=0 Then
encode.0[counter*2]=0 : encode.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
Else
encode.0[counter*2]=1 : encode.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
EndIf
Next counter :
write 8, encode 'Write encode to EEPROM Location 8
Low 4 'Low on Port B Pin 4
For counter = 0 to 5 'Blink LED 5 times
Pause 400 'Pause
High 4 'High on Port B Pin 4
Pause 400 'Pause
Low 4 'Low on Port B Pin 4
Next counter 'Back to beginning of loop
For counter3 = 0 to 50 'Send three times
serout PORTB.2, n2400, [ $55, $55, $55, $55, $55, $55, $55, $55, $55, $aa , encode ] 'send out preamble and encode on PORTB pin 2
Next counter3 'Next number
goto Clr
Endif
'Tracking and Finding mode (is based on last two bits)
If ((d.1=0) and (d.0=1)) Then
action2=s 'Copy s to action2 byte
action2.1=1 'set the third bit of action2 to 1 and send back
'alert=1
write 4, action2 'Write to EEPROM Location 4
High 5 'High on Port B Pin 4
Pause 2000 'Pause
Low 5 'Low on Port B Pin 4
'Manchester Encoding
For counter = 0 to 3
If action2.0[counter]=0 Then
encode2.0[counter*2]=0 : encode2.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
Else
encode2.0[counter*2]=1 : encode2.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
EndIf
Next counter :
'serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $aa , encode2 ] 'send out preamble and code to Port B Pin 2
write 9, encode2 'Write encode2 to EEPROM Location 9
Low 4 'Low on Port B Pin 4
For counter2 = 0 to 5 'Blink LED 50 times
Pause 400 'Pause
High 4 'High on Port B Pin 4
Pause 400 'Pause
Low 4 'Low on Port B Pin 4
Next counter2 'Back to beginning of loop
Low 1 'Low on Port B Pin 4
For counter = 0 to 10 'Blink LED 50 times
Pause 400 'Pause
High 1 'High on Port B Pin 1
Pause 400 'Pause
Low 1 'Low on Port B Pin 1
Next counter: 'Back to beginning of loop
For counter3 = 0 to 50 'Send data times
serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $55, $55, $55, $55, $aa , encode2 ] 'send out preamble and encode on PORTB pin 2
Next counter3 'Next number
goto Clr
Endif
End
Receiver code for microcontroller after the 315 MHz receiver.
'IEEE encoding
Include "Modedefs.bas"
'trisb = 0
s var byte : B0 var bit : B1 var bit : 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
counter var byte : ct55 var byte: 'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
encode1 var byte : B0=0 : B1=1
'encode1 byte sized variable that holds encoded byte s, B0 and B1 are the hardwired address
e var byte: s=0: encode1=0:e=0
' e are bytes; initialize s, encode1, and e values to zero
'encode1 holds the encoded variable received.
Main:
Clr:
s=0: encode1=0: e=0: 'encode2=0 'initialize variables to zero
Maina:
ct55 = 0 'counter for $55 is zero
Wait55:
serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
If encode1 = $55 Then
ct55 = ct55 + 1 '$55 read, increase ct55 by 1
If ct55 = 4 Then goto Waitaa 'if $55 occurs 4 times in a row check for $aa
Else
goto maina 'if not $55, reset counter at main and restart
Endif
goto wait55
Waitaa:
serin PORTB.0, n2400, encode1 'wait for $aa
If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
write 0,encode1 'write to EEPROM Location 0
High 7 'High on Port B Pin 7
Pause 2000 'Pause
Low 7 'Low on Port B Pin 7
'Decoding
For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
write 1, s 'write to EEPROM Location 1
High 6 'High on Port B Pin 6
Pause 2000 'Pause
Low 6 'Low on Port B Pin 6
e=s
If ((e.1==1)) Then 'Acknowledgment received because third bit is 1
goto L4 'Jump to L4
Else
write 2,s 'Write to EEPROM Location 2
High 2 'High on Port B Pin 2
Pause 2000 'Pause
Low 2 'Low on Port B Pin 2
goto Clr
Endif
L4:
write 3, e 'Write to EEPROM Location 3
High 1 'High on Port B in 1
Pause 2000 'Pause
Low 1 'Low on Port B in 1
serout PORTB.3, n2400, [e.3] 'send out first bit from PORTB Pin 3
serout PORTB.4, n2400, [e.2] 'send out second bit from PORTB Pin 4
goto Clr
Should I change my preamble to a different byte such as $66, $66, $66, $66, $bb,... or should I increase the size?
Bookmarks