I rarely use manchester, but here's a simple version you can run with a
terminal program to see how it works. You can easily change it to work
with serial comms between two PIC via RF.
You still want to include a preamble & synch byte before each packet.
The assembler routine is a slightly modified version of one done by Les
Johnson a long time ago, and it's very fast.
This version is for an 18F. Just make the rotate instruction change as shown
to use it on a 12F or 16F part. You'll want to change banka to bank0 also.
Here's the output;Code:; Compile with MPASMWIN X VAR BYTE Y VAR BYTE BitCount VAR BYTE banka system ' Bank0 system so we don't need an underscore ByteIn VAR BYTE banka system ' to access BASIC variables from assembler ByteOut VAR BYTE banka system Manch VAR WORD banka system ' Holds manchester encoded word Temp VAR WORD banka system ' Temp var CRC VAR BYTE system Enc_Dat VAR WORD[6] ' Holds 6 manchester encoded words GOTO Main ' Jump over encode/decode routines ASM ; Note: For 14-bit core just change Rlcf to Rlf ; Manchester encode routine _Encode Movlw 8 Movwf BitCount E_Repeat Rlcf ByteIn,F Btfss STATUS,C Goto BitClr BitSet Rlcf Manch,F Rlcf Manch+1,F bcf STATUS,C Rlcf Manch,F Rlcf Manch+1,F Goto E_Loop BitClr Rlcf Manch,F Rlcf Manch+1,F bsf STATUS,C Rlcf Manch,F Rlcf Manch+1,F E_Loop Decfsz BitCount,F Goto E_Repeat Return ENDASM ASM ; Manchester decode routine. _Decode Movf Manch+1,W Movwf Temp+1 Movf Manch,W Movwf Temp Movlw 8 Movwf BitCount Repeat Rlcf Temp,F Rlcf Temp+1,F Rlcf ByteOut,F Rlcf Temp,F Rlcf Temp+1,F Decfsz BitCount,F Goto Repeat Return ENDASM Main: ' Manchester encode ASCII characters "A" to "F" Y = 0 ' Start array index pointer at 0 FOR X = "A" to "F" ByteIn = X CALL Encode Enc_Dat[Y] = Manch HSEROUT ["Encoded ",X," = ",IBIN8 X," = ",IBIN16 Enc_Dat[Y],13,10] Y = Y + 1 ' Increment array index pointer NEXT X ' Decode & print results FOR Y = 0 to 5 Manch = Enc_Dat[Y] CALL Decode HSEROUT ["Decoded ",IBIN16 Manch," = ",ByteOut,13,10] NEXT Y PAUSE 10000 GOTO Main END
Encoded A = %01000001 = %0110010101010110
Encoded B = %01000010 = %0110010101011001
Encoded C = %01000011 = %0110010101011010
Encoded D = %01000100 = %0110010101100101
Encoded E = %01000101 = %0110010101100110
Encoded F = %01000110 = %0110010101101001
Decoded %0110010101010110 = A
Decoded %0110010101011001 = B
Decoded %0110010101011010 = C
Decoded %0110010101100101 = D
Decoded %0110010101100110 = E
Decoded %0110010101101001 = F
Manchester does have its advantages, but I rarely use it. A big factor is
getting the receiver/transmitter in synch.
Like in my previous post, I would definitely use a preamble followed by a
synch character. That really makes a big difference.




Bookmarks