PDA

View Full Version : SEROUT or HSEROUT "ODD" parity



RFsolution
- 28th November 2006, 17:17
Hi all

I'm suffering with a serout routine where I have to use ODD parity

I'm using a 16F876A with several SEROUT and SEROUT2 ports

some are 8N1 , 1 is 8O1

If I use the define command: Define ser2_odd = 1

Then all my serout2s are ODD parity

Do i need to put this define infront of each Serout2 command ?

What if I want to use ODD parity with serout instead of serout2 ?

Thanks

RFsolution
- 5th December 2006, 23:22
Still suffering, anyone who can help me ?

I have the ODD parity working on 1 Serout2 pin, but I also need to do
some other serout2's on other pins but with parity none

Anyone ?

Darrel Taylor
- 6th December 2006, 00:40
The SER2_ODD define only changes the way the parity works for SERIN/OUT2. (EVEN or ODD)

To select parity mode, you use bit 13 of the mode number. 1=parity, 0=noparity.

So, if the parity is not turned on for that specific SEROUT2 statement, the SER2_ODD define will not have any effect.

RFsolution
- 6th December 2006, 10:39
Thanks Darrel , I will give it a try

Sphere
- 8th December 2006, 20:36
Darrel if you have time, how do you work out which is bit 13 of the mode number. I have a similar problem but I need to use even and none.

Thanks Sphere....

Darrel Taylor
- 9th December 2006, 08:35
The easiest way will be to bug mister_e for his latest PicMultiCalc. Don't tell him I said that. :)

But until then, here's how to do it manually... First calculate the BAUD part for the lower 12 bits.

(1,000,000 / baud) -20

So for 9600 baud that's

(1,000,000 / 9600) -20 = 84     9600 baud, NO parity, TRUE

Now, bit 13 is equal to 8192 (2 to the 13th power [2^13])

If you want parity to be turned ON, add 8192 to the baud.

84 + 8192 = 8276     9600 baud, with parity, TRUE

Note that this only turns the parity ON and OFF, it doesn't select EVEN or ODD.
EVEN is the default parity mode, but if you want ODD parity then you have to set the SER2_ODD define.

Then there's bit 14, which determines the polarity.
2 to the 14th power [2^14] = 16,384

If you add 16,384 to the previous number, the polarity will be Inverted.
8276 + 16,384 = 24,660 &nbsp; &nbsp; 9600 baud, with parity, INVERTED<HR>
Now how do we do that without having to do the math ourselves...
Well, we can let the compilers do it for us.
And for good measure, we'll let it figure out the numbers for bit13 and 14 too.
<font color="#000000"><b>Parity </b><font color="#008000"><b>CON </b></font><b>1 </b>&lt;&lt; <b>13
Inverted </b><font color="#008000"><b>CON </b></font><b>1 </b>&lt;&lt; <b>14

</b><font color="#000080">@MODE = (1000000 / 9600) - 20 + _Parity + _Inverted </font>
<b>MODE </b><font color="#008000"><b>CON </b></font><b>EXT</b>OR, if using multiple protocols...
<font color="#000080">@MODE1 = (1000000 / 9600) - 20 + _Parity + _Inverted </font><font color="#0000FF"><b><i>; 9600, with parity, inverted
</i></b></font><b>MODE1 </b><font color="#008000"><b>CON </b></font><b>EXT

</b><font color="#000080">@MODE2 = (1000000 / 19200) - 20 + _Inverted </font><font color="#0000FF"><b><i>; 19200, no parity, inverted
</i></b></font><b>MODE2 </b><font color="#008000"><b>CON </b></font><b>EXT</b>Then to use them later...
<font color="#008000"><b>SEROUT2 </b></font><b>PORTB</b>.<b>0</b>, <b>MODE1</b>, [<font color="#FF0000">&quot;Hello World!&quot;</font>] <font color="#0000FF"><b><i>; Mode 1, 9600, with parity, inverted

</i></b></font><font color="#008000"><b>SEROUT2 </b></font><b>PORTB</b>.<b>1</b>, <b>MODE2</b>, [<font color="#FF0000">&quot;Just 5 more minutes&quot;</font>] <font color="#0000FF"><b><i>; Mode 2, 19200, no parity, inverted</i></b></font><hr> OR, you can just go here and look them up in a table. :)

http://www.melabs.com/resources/ser2modes.htm
<br>

Sphere
- 9th December 2006, 11:08
What more can I say other than give that man a cigar. Now I can use one pic chip instead of two. Thanks for your time.

Sphere....

mister_e
- 9th December 2006, 11:34
The easiest way will be to bug mister_e for his latest PicMultiCalc. Don't tell him I said that. :)


I didn't saw, i didn't heard that :D