I got serin to partially work on the receiver side (with and without wireless). The problem I am having now is it seems like after I decode it I have about 4 extra bits at the end of my decoded sequence. How do I get rid of it?
Here is my revised code:
------------------------------------------------------------------------------------------------------------------
'Transmitter Code
Include "Modedefs.bas"
v var word 'v is a byte to be encoded
counter var byte 'counter is a byte
encoded var word 'encoded is a word sized variable that holds the encoded byte v
'Code to be transmitted
v = %1101 '1101 in Binary
'Manchester Encoding
For counter = 0 to 3 'number of bits to be encoded (4 bits)
If v.0[counter]=0 Then encoded.0[counter*2]=0 'if it is a zero make the first bit 0 encoded.0[counter*2+1]=1 'make the second bit 1
Else
encoded.0[counter*2]=1 'if it is a 1 make the first bit 1
encoded.0[counter*2+1]=0 'make the second bit 0
EndIf
Next counter
'Serial Out
serout PORTB.0, t2400, [$55,$55, $55, $aa, encoded] 'serial out in pin 0 using non-inverted 2400 bps to encoded
--------------------------------------------------------------------------------------------------------------------------------
'Receiver Code
Include "Modedefs.bas"
s var word 's is a byte to be encoded
B0 var byte 'B0 is a byte
B1 var byte 'B1 is a byte
counter var byte
encoded1 var word 'encoded1 word sized variable that holds the encoded byte v
action var byte 'action variable
alert var byte 'alert variable
B0=1 'hardwired address
B1=1 'hardwired address
'Decoding
waitfor55:
serin PORTB.0, t2400, encoded1: if encoded1 = $55 then goto waitfor55
waitforaa:
serin PORTB.0, t2400, encoded1: if encoded1 = $aa then goto waitforaa
serin PORTB.0, t2400, encoded1 'serial in to pin 0, a non-inverting 2400 bps to encoded1
serout PORTB.3, t2400, [encoded1]
loop:
For counter = 0 to 3
s.0[counter]=encoded1.0[counter*2] 'proceed through counter and copy encoded1 to s
Next counter
goto loop
End
serout PORTB.3, t2400, [s] 'serial out to pin 3, a non-inverting 2400 bps, to s
'Tracking code
If (s.2==0) & (s.3==0) Then 'If the code matches 00 then it is in the tracking mode
If (s.0==B0) & (s.1==B1) Then 'If the address matches then
s.2=1 'Change the third bit to 1
action = s.2 'action becomes 1
alert = 0 'alert becomes 0
serout PORTB.1, t2400, [s] 'Send the changed word back, serial out to pin 1, a non-inverting 2400 bps, to s
Else
s.2=0 'Since the addresses does not match do not change anything
action = s.2 'action becomes 0
alert = 0 'alert becomes 0
serout PORTB.1, t2400, [s] 'Send the changed word back, serial out to pin 1, a non-inverting 2400 bps, to s
Endif
Endif
'Tracking and Finding code
If (s.2==0) & (s.3==1) Then 'If the code matches 01 then it is in the tracking and finding mode
If (s.0==B0) & (s.1==B1) Then 'If the address matches then
s.2=1 'Change the third bit to 1
action=s.2 'action becomes 1
alert=1 'alert becomes 1
serout PORTB.1, t2400, [s] 'Send the changed word back, serial out to pin 1, a non-inverting 2400 bps, to s
High 2
Else
s.2=0 'Since the address does not match do not change anything
action=s.2 ;action becomes 0 and alert is also 0
alert=0
serout PORTB.1, t2400, [s] 'Send te changed word back, serial out to pin 1, a non-inverting 2400 bps, to s
Endif
Endif
[QUOTE=oneohthree;35632]Here is my revised code:
That code is entirely TOO complicated for the job you are trying to get done...
Hang tight for a bit...
'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.
This is a part of the 2 way paging system that I am doing for a project. Basically what I am trying to do is take 4 bits from the transmitter that I get at the receiver end and do some operations on it. I am assuming that the first two bits are the address and the last two bits are the mode. There are two modes tracking and finding. In each case, I am first checking the last two bits to see which mode it is. After I do that, I am checking if the first two bits of address matches. If the address matches, it will change the third bit (kind of like an acknowledgement) and output the result somewhere. If it does not match it will not change the code and output it back. In the find mode, it does the same thing except it will make a pin high in order to set off an alert like a LED. Is this making any sense?
Ok, that makes a bit more sense....
A bit (pun intended) simpler, maybe????......
Take a sent byte...invert it and send it back as some sort of acknowledge.
For instance: (using 4 bits, $5, $A, $0, $F, are already taken, so can't use those)
Send $1, return $E, acknowledged
Send $2, return $D, and so on...
Anything else returned would be 'not' acknowledged...
Leaves you with $1,2,3,4,6,7 for send codes ($E,D,C,B,9,8 for returned codes).... if 6 codes is enough for you...
That way you could set the 'address' for each pager/receiver with 3 DIP switches (with 2 unused combo's)...
Bookmarks