Freddie Leaf wrote: > > (I'm resending with the proper topic denotion in the subject..) > > Hi Piclist, > I'm looking for an algorithm or code (PIC Assembly or C) that decodes > Manchester encoded data coming into the PIC via the serial port or a dedicated > pin. I understand how Manchester works but I am not sure of the best approach > to decoding incoming data. I searched the PICList archive and did not find > anything specific enough or the links no longer worked. Thank you in advance. This may help... ; ; ------------------------------------------- ; SUBROUTINE: CONVERT BYTE TO MANCHESTER WORD ; ------------------------------------------- ; Data to convert is in W ; Result is in ManchH and ManchL ; ToManch movwf Temp1 ; save data byte movlw 8h movwf BCount ; 8 bits per byte ManLoop rlf Temp1 btfsc STATUS,C goto BitIsOne ; ; Bit to convert = 0 - place 01 into manchester bytes ; bcf STATUS,C rlf ManchL rlf ManchH bsf STATUS,C rlf ManchL rlf ManchH goto DecMLoop ; ; Bit to convert = 1 - place 10 into manchester bytes ; BitIsOne bsf STATUS,C rlf ManchL rlf ManchH bcf STATUS,C rlf ManchL rlf ManchH DecMLoop decfsz BCount ; do for 8 bits goto ManLoop return ; ; ------------------------------------------- ; SUBROUTINE: CONVERT MANCHESTER WORD TO BYTE ; ------------------------------------------- ; Data to convert is in ManchH and ManchL ; Data is returned in Temp1 ; ManchH and ManchL remain same value ; FromManch movf ManchH,W movwf DataH movf ManchL,W movwf DataL movlw 8h ; 8 bit pairs to convert movwf BCount ; ; BIT PATTERN 10 - RESULT BIT = 1 ; BIT PATTERN 01 - RESULT BIT = 0 ; DeManLoop rlf DataL ; 1st bit determines result bit rlf DataH rlf Temp1 rlf DataL ; skip unused 2nd bit rlf DataH decfsz BCount ; do for 8 bit pairs goto DeManLoop return -- Best regards Tony mICros http://www.bubblesoftonline.com mailto:sales@bubblesoftonline.com -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.