I am trying to make a 2 way paging system with a TLP-434, RLP-434, TLP-315 and RLP-315. The 434 MHz is the uplink and 315 MHz is the downlink. The uplink works perfectly since it always receives data and does operations on it. But the downlink does not work fully, there are instances where the microcontroller on the receiver side does not receive a signal and sometimes it receives it. I have to send the same code at the receiver (microcontroller attached to the RLP-434 with an output to the TLP-315) The microcontroller I am using is the PIC16F88. I have starred (**) the portions that I think might be having problems with. The code I am using is down below:
TRANSMITTER (WORKS):
'IEEE Encoding
'Transmitter Code
Include "Modedefs.bas"
'trisb = 0
main:
u var byte : counter var byte : encode var byte : u = %1101
'u is the byte containing the input in binary, counter is a byte that describes the amount of bits to encode
'encode is the variable holding the encoded value
'Manchester encoding
For counter = 0 to 3
If u.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 : serout PORTB.0, n2400, [ $55 , $55 ,$55, $55, $aa , encode ] 'send out preamble and encoded from Port B Pin 0
write 0, encode 'Write to EEPROM Location 0
High 1 'High on Port B Pin 1
Pause 1000 'Pause
Low 1 'Low on Port B Pin 1
goto main
RECEIVER (RLP-434 output to TLP-315) (works but not sure about serout)
'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 counter = 0 to 10 'Send three times
serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $aa , encode ] 'send out preamble and encode on PORTB pin 2
Next counter '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, $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, $aa , encode2 ] 'send out preamble and encode on PORTB pin 2
Next counter3 'Next number
goto Clr
Endif
End
RECEIVER (after RLP-315, downlink) (works sometimes)
'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] 'send out preamble and code on PORTB pin 1
goto Clr
End
Bookmarks