Here's a simple set of manchester encode/decode routines.
Code:
inbyte VAR BYTE
outword VAR WORD
inword VAR WORD
outbyte VAR BYTE
i VAR BYTE
Begin:
CLEAR
inbyte = 12 ' byte for test
GoSub Encode ' convert to Manchester word
inword = outword
GoSub Decode ' convert from Manchester word
outbyte = 0
goto begin
Encode:
For i = 0 to 7 ' loop for 8-bits
outword.0[(i*2)] = ~inbyte.0[i] ' Get bit value for bits 0,2,4,6,8,10,14 in outword
outword.0[(i*2)+1] = inbyte.0[i]' Get bit value for bits 1,3,5,7,9,11,13,15 in outword
Next i '
Return
Decode::
For i = 0 to 7 ' loop for 8-bits
outbyte.0[i] = ~inword.0[i<<1] ' outbyte bits 0-7 = inword bits 0,2,4,6,8,10,14
Next i ' Inverts each 2nd bit position in inword I.E. 01 = 0, 10 = 1
Return
Bookmarks