I have been reading many post on manchester encoding/decoding and have been trying to get this code to work. Before I was just sending the state of portb out and receiving it in and it was working, but would miss bits. So after reading about Melanie's, Bruce and Ioannis (I hope thats the correct spelling), post I tried Ioannis version. It seems to be clearer than most, but now nothing works. Any suggestions?

Here is the code I've been experimenting with:

Serial Transmitter
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
' Watchdog Timer
@ DEVICE pic16F628a, PWRT_ON
' Power-On Timer
@ DEVICE pic16F628a, MCLR_ON
' Master Clear Options (Internal)
@ DEVICE pic16F628a, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F628a, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F628a, CPD_OFF
' Data Memory Code Protect
' Set to CPD_OFF for Development Copy
' Set to CPD_ON for Release Copy
@ DEVICE pic16F628a, PROTECT_OFF

define osc 4
include "bs2defs.bas"
CMCON=%00000111
i var byte
encoded var word
dgood var porta.2
serpin var porta.3
nokey con %11111111
synch con 254
keyin var portb
mydata var byte
trisb = %11111111
trisa = %00010111
ro VAR PORTB.0
ri VAR PORTB.1
bkl VAR PORTB.2
es VAR PORTB.3
rb VAR PORTB.4
lb VAR PORTB.5
bl VAR PORTB.6
na VAR PORTB.7



findkey:
if rn = 0 then sw1
if lb = 0 then sw2
if ri = 0 then sw3
if ro = 0 then sw4
if es = 0 then sw0
if bl = 0 then sw5
if bkl = 0 then sw6


goto findkey
sw0:
mydata = %0100
goto dout
sw1:
mydata = %0101
goto dout
sw2:
mydata = %0110
goto dout
sw3:
mydata = %0010
goto dout
sw4:
mydata = %0001
goto dout
sw5:
mydata = %0111
goto dout
sw6:
mydata = %0011
goto dout



dout:
low dgood
pause 100
For i=0 TO 7
IF mydata.0[i]=0 Then
encoded.0[i*2]=0
encoded.0[i*2+1]=1
Else
encoded.0[i*2]=1
encoded.0[i*2+1]=0
EndIF
Next i
Return
serout serpin,N2400,[$55,$55,$55,$55,$55,synch,encoded]
if keyin = nokey then x2
goto findkey

x2:
high dgood
mydata = %00000000
serout serpin,N2400,[$55,$55,$55,$55,$55,synch,encoded]
goto findkey
end



Serial Receiver
INCLUDE "bs2defs.bas"
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
' Watchdog Timer
@ DEVICE pic16F628a, PWRT_ON
' Power-On Timer
@ DEVICE pic16F628a, MCLR_ON
' Master Clear Options (Internal)
@ DEVICE pic16F628a, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F628a, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F628a, CPD_OFF
' Data Memory Code Protect
' Set to CPD_OFF for Development Copy
' Set to CPD_ON for Release Copy
@ DEVICE pic16F628a, PROTECT_OFF
DEFINE OSC 4
mydata VAR byte
encoded var word
serpin VAR porta.1 'serial input pin
PORTA = 0
PORTB = 0
trisa = %00000010
trisb = %10000000
CMCON=%00000111
i var byte
PAUSE 50 ' settle time

loop:
gosub loop1
branch mydata, [rly1,rly2,rly3,rly4,rly5,rly6,rly7]
GOTO loop

rly1:
toggle 0
pause 250
goto loop

rly2:
HIGH 1
pause 50
if mydata <> %0101 then low 1
GOTO loop

rly3:
HIGH 2
pause 50
if mydata <> %0110 then low 2
GOTO loop

rly4:
HIGH 3
pause 50
if mydata <> %0010 then low 3
GOTO loop

rly5:
HIGH 4
pause 50
if mydata <> %0001 then low 4
GOTO loop

rly6:
toggle 5
pause 250
GOTO loop

rly7:
TOGGLE 6
PAUSE 250
GOTO loop



loop1:
SERIN serpin,N2400,[254],encoded
For i=0 TO 7
IF encoded.0[i*2]=0 Then
IF encoded.0[i*2+1]=1 Then
mydata.0[i]=0
EndIF
Else
mydata.0[i]=1
EndIF
Next
Return

Thank you all for you help.