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 CCS Technical Support

PIC16F877A RS232

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



Joined: 16 Oct 2008
Posts: 59

View user's profile Send private message

PIC16F877A RS232
PostPosted: Sun Jan 04, 2009 2:37 pm     Reply with quote

Hello,

I have a (simple i hope) question about the RS232.
I have a 20Mhz quartz with the PIC16F877A. Can i use any baud rate for the RS232 ?

Can i use :

#use rs232(baud=9600,Xmit=PIN_...
#use rs232(baud=4800,Xmit=PIN_...
#use rs232(baud=57600,Xmit=PIN_...

Or does is it specific on the quartz used ?

Thank you Rolling Eyes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 04, 2009 2:57 pm     Reply with quote

Download the PicBaud program. Unzip it and put it on your desktop:
http://www.micromagicsystems.com/#/picbaud/4523812801
(Warning: This web page plays a sound).

Then put in various crystal frequencies and baud rates and see how
much error exists for each combination. Error values for BRGH = 0 and
BRGH = 1 will be given. Just use whichever one is the smallest.
Then consider that the maximum error should be less than 2%
(or better, keep it less than 1%).
magestik



Joined: 16 Oct 2008
Posts: 59

View user's profile Send private message

PostPosted: Sun Jan 04, 2009 3:10 pm     Reply with quote

So when i enter 20Mhz with 2800bps, it says :

BRGH = 0
BAUD : 2790
ERROR : -0.35%
SPBRG : 111

BRGH = 1
BAUD : TOO LOW
ERROR :
SPBRG :

Does it mean i can't use 2800bps ?
I'm new with this notions Embarassed

For BRGH = 1 i get BAUD = Too low until 7200bps :(
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 04, 2009 3:27 pm     Reply with quote

Quote:
Does it mean i can't use 2800bps ?

No. It just won't work for BRGH=1. It works fine for BRGH=0.
The error is only -.035%. It will work well.
Ttelmah
Guest







PostPosted: Sun Jan 04, 2009 3:55 pm     Reply with quote

Remember also the compiler will automatically select the best combination for you. The point about the program (for CCS users), is that it allows you to test if there _is_ a combination that will work. So long as one combination exists, with an error of a couple of percent or lower, things will be OK.
Try with (for example), a 4MHz crystal, and 115200bps, to find a combination that _won't_ work. The problem is that if the error number goes over about 3%, the serial _will_ be unreliable.
For your crystal, there are few normally used rates that will be problematical, except very _low_ ones. For instance, 50bps won't be doable.
With lower clock rates problems are more common (as with the example already given).

Best Wishes
magestik



Joined: 16 Oct 2008
Posts: 59

View user's profile Send private message

PostPosted: Sun Jan 04, 2009 4:28 pm     Reply with quote

Yeah so much more for me to learn about PICs and CCS Smile
Does it mean CCS will set BRGH automatically, or do i have to set it myself ?
I never set BRGH when using #use rs232 Confused
Ttelmah
Guest







PostPosted: Mon Jan 05, 2009 3:07 am     Reply with quote

CCS sets it automatically.
Basically it does exactly the arithmetic involved in the picbaud program during compilation, and takes the combination that gives the lowest error, automatically setting the bits for you.
There have in the past been some faults in the selection of the combinations, but for the last year or more, CCS has got it 'right'.

Best Wishes
magestik



Joined: 16 Oct 2008
Posts: 59

View user's profile Send private message

PostPosted: Mon Jan 05, 2009 7:21 am     Reply with quote

Yeah it works, thank you very much ;)
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