Mike Keitz wrote:

{Quote hidden}>

>If you can transmit 8 bits, you just need to prepare 8-bit data for

>transmission so the low 7 bits are your data and the eighth bit is a

>parity bit.

>

>First, make a copy of your data into another register so the parity

>routine can work on it:

>

> movfw serdata

> andlw b'01111111' ;Keep only 7 bits

> movwf parity ;Store for parity generator.

>

>If you know that the unused eighth bit of 'serdata' will be 0, you can

>omit the anding it off. It's also possible to use it to make the parity

>generator make either even or odd parity but that's kind of an advanced

>thing to think about.

>

>Now I'll slightly modify the recently discussed optimized xor parity

>generator so it computes the [even] parity into the high bit of 'parity'

>(instead of the low bit as the earlier versions did).

>

> swapf parity,w ;Align bits 3210 over 7654

> xorwf parity,f ;xor 7^3 6^2 5^1 4^0

> rlf parity,w ;Align (6^2) over (7^3), (4^0)^(5^1)

> xorwf parity,f

> btfsc parity,5 ;xor last 2 results together

> comf parity,f ;bit 7=((6^2)^(7^3))^((4^0)^(5^1))

>

>At this point, bit 7 of 'parity' is the parity bit you need to send, and

>the rest are garbled. All that remains is to merge it into 'serdata'.

>This is kind of a trick method that works regardless of the value of bit

>7 of serdata.

>

> movfw parity

> xorwf serdata,w

> andlw b'10000000'

> xorwf serdata,f

>

>[[If you know that bit 7 of serdata is 0, then a simpler or would work

to

{Quote hidden}>merge the two:

> movfw parity

> andlw b'10000000' ;Keep only the valid parity bit

> iorwf serdata,f ]]

>

>Now if you send the 8 bit data in serdata, the receiver can interpret it

>as 7 bits with even parity.

>

>I assume at some point you're going to want the PIC to check the parity

>of data that it received. It's real simple, just receive the data as 8

>bits, make a copy into 'parity', and process it through the parity

>generator above. If bit 7 of the result is 0, the data has proper even

>parity.

Thanks Mike (and to everybody else who answered). This routine seems to

work just great! Although maybe one day when I have more time on my

hands, I will work out why it actually works (this project has to be in

in a few days time and I think you just might have saved my bacon!)

Thanks,

Brian.