PDA

View Full Version : Parity Modes



Sphere
- 28th April 2006, 18:28
I need to output different parity modes using one pic i.e. 9600 8N1 9600 8E1 9600 8O1 from my understanding of the PBP manual I can only choose between even, odd or none using the define command. Im still new to all this serial stuff so I would appreciate if someone could confirm this for me.
Thanks Sphere.

Darrel Taylor
- 29th April 2006, 00:14
Hi Sphere,

If I understand correctly, you want to change parity modes at Run-Time?

If so, then you are correct. Using either HSEROUT or SEROUT2 you can only change them at Compile-Time.

If you generate your own parity, and manipulate the registers manually, you can use the USART in 9-bit mode to get the 8E1 and 8O1, and turn off 9-bit mode for 8N1.
<br>

Sphere
- 29th April 2006, 00:27
Thanks for the reply, you where correct about changing parity modes at Run-Time? but still being relativity green around the ears regarding pbp how do I do this.

Thanks Sphere.

Darrel Taylor
- 29th April 2006, 05:09
Well, first let's look at how the parity works.

It's calulated by counting the number of 1's in the byte. For instance the letter "J" which is 01001010, 3 bits are a 1.

If using EVEN parity, the parity bit will be set to 0, since 3 is not an even number. ODD parity would be 1, if used.

For the letter "K" 01001011, 4 bits are a 1. So EVEN parity = 1, ODD = 0.

As for sending that via the USART ...
First, set up SPBRG, TXSTA and RCSTA like normal. (many other posts here show how to do that)

Set TXSTA.6 (TX9) to 1. &nbsp; Selects 9-bit transmission
The parity bit goes in TXSTA.0 (TX9D) &nbsp; 9th bit of Transmit Data
Then put the byte to be sent in TXREG
and away she goes.

Sphere
- 29th April 2006, 11:12
Ill give it a go over the weekend.
Thanks again Sphere.