CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

rs232 stream parity bit problem in 18f8720

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
micro



Joined: 10 Sep 2003
Posts: 13

View user's profile Send private message

rs232 stream parity bit problem in 18f8720
PostPosted: Mon Feb 07, 2005 8:29 am     Reply with quote

I wrote a simple code snipped for 18f8720 like below. Although I mentioned "Odd Parity" in built in definition , output data has not odd parity. How do I send data with odd parity ?

#use rs232 (baud=9600, PARITY=N, xmit=PIN_C6, rcv=PIN_C7,ERRORS,stream = PORT1)
#use rs232 (baud=9600, PARITY=O, xmit=PIN_G1, rcv=PIN_G2,ERRORS,stream = PORT2)

void main()
{
while(1)
{
fputc(0x25,PORT2);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 07, 2005 12:51 pm     Reply with quote

I looked at the ASM code generated by the compiler for your example.
It sends out 9 bits of data. The first 8 bits are the data byte, and the
9th bit is the parity bit.

Remember that for Odd parity, if the parity of your data byte is odd,
then the parity bit will be set = 0. If the parity of your data byte
is even, then the parity bit is set = 1. In other words, the value
of the parity bit is set so that the overall parity of the 9-bit stream is odd.

Your data is 0x25, which has three 'one' bits, which is odd parity.
So the the 9th bit will be set = 0, in order to make the parity of the
entire 9-bit stream be odd.

I used PCH vs. 3.188 to compile the code for a 18F8720 for my tests.
----------
Does this explanation help, or were you possibly expecting the compiler
to generate 7 bits of data and use the 8th bit for parity ?
micro



Joined: 10 Sep 2003
Posts: 13

View user's profile Send private message

I tried this
PostPosted: Wed Feb 09, 2005 1:02 am     Reply with quote

When I wrote this code snipped, I tried it using a PC sw that observes the PC's COM port. The PIC programmed with this code sends the string I want and my PC sw is set 9600,odd parity,8 bit data 1 stop bit. In this condition, I realise that some data in string sometimes corrupts. For example When I send a stream like (0x50, 0x20 ,0xFA), stream sometimes appear like (0x3F 0x20 0xFA). But If I use none parity option in PC sw (a kind of terminal program etc.), all stream looks like allways as it should be and correct. How can I explain and take over this problem ??
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group