It's potentially possible to do Manchester Encoding and Decoding using a PICAXE, but you won't have very fast baud rates, and there will be an issue of timing accuracy. One example of Manchester Encoding is as follows ...
Code:
' Send byte in b0 through output pin 1
SYMBOL DOUT = pin1
SYMBOL DPIN = 1
OUTPUT DPIN
b0 = $A5
FOR b1 = 1 TO 8
DOUT = bit7
PAUSE 10
TOGGLE DPIN
PAUSE 10
b0 = b0 * 2
NEXT
Code:
1 0 1 0 0 1 0 1
_____ _____ _____ _____
Data : |_____| |_____._____| |_____| :
: : : : : : : : :
:__ : __:__ : __: __:__ : __:__ :
Dout | |__:__| |__:__| |__| |__:__| |__:
1 0 0 1 1 0 0 1 0 1 1 0 0 1 1 0
This uses a mapping of 0->01 and 1->10, and msb first.
Reading is a little more complex and requires looking for transitions on the DOUT line, you need to have a mechanism to stop that first edge seen on DOUT being treated as a transition when it doesn't indicate a bit. Manchester encoding usually has a continuous bit stream or preamble to allow the receiver to sync up properly.
The real question is; why do you need to use Manchester Encoding at all ?
Standard SERIN and SEROUT will be much quicker and probably just as reliable. If it's because there's a wireless medium bewteen the two, there are other ways to make sure that an [almost] even number of one and zero bits are sent to keep the DC offset close to zero; the easiest being to simply send the data twice, the second time inverted, receiving is a simple case of reading both bytes and discarding the second.
It would also be possible to use this method with nibbles or with alternatinge bits, but the encoding and decoding gets much more complex and time consuming.
Edited by - hippy on 6/27/2005 12:18:20 PM