Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how define baud rate in hi-tech c compiler?

Status
Not open for further replies.

cheekang

Newbie level 6
Joined
Jan 28, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,374
hi i in trouble in define the baud rate for PIC 16F877A in hi-tech c compiler:
below are some code that i get from cytron website:
Code:
SPBRG=0x0A;					// set baud rate as 115200 baud
	BRGH=1;

i don't know how they get "SPBRG=0x0A" (set baud rate as 115200 baud), can somebody help me to explain this?

i am using PIC 16F877A in hi-tech c compiler, external oscillator that connect to PIC are 4MHz, and for uart baud rate setting = 115200 baud.

kindly advice. thanks a lot
 

The answer is is in section 10 of the 16F877A data sheet. The baud rate clock is divided down from the main system clock so you must know that first in order to calculate the division ratio in SPBRG. The BRGH bit just alters the way the divider works to cater for a wider range of clock and baud rates.

Brian.
 

You can also use the following SPBRG Calculator, after reading the section of the devices datasheet to which Brian is referring.

SPBRG Calculator


The SPBRG Calculator also displays the percent error from the desired to actual BAUD rate calculated.

Not all BAUD rates offer a low enough percent error to be effectively utilized.

BigDog
 

The answer is is in section 10 of the 16F877A data sheet. The baud rate clock is divided down from the main system clock so you must know that first in order to calculate the division ratio in SPBRG. The BRGH bit just alters the way the divider works to cater for a wider range of clock and baud rates.

Brian.

hi may make sure my calculation is correct or not:
i using oscillator 20Mhz, and desired baud rate is 115200bps..

after calculate:
i get the x value (SPBRG) = 9.85 (around 10)

so if in hex form, i will get 0A.
what mean with code bellow?
SPBRG=0x0A

why it write in 0x0A?

---------- Post added at 20:19 ---------- Previous post was at 20:03 ----------

and if i using 4Mz oscillator, the SPBRG i get is =1 .
so i need to write in
SPBRG = 0x01? or
SPBRG = 1?
or other?
kindly advice.
thanks
 

Your figures are correct but beware that with the 4MHz clock the error is about 8% which will almost certainly cause problems. As a rule of thumb, the safe error limit is about 2%

The '0x' in front of the number just means the following characters are in hexadecimal (base 16) radix. 0x0A is equivalent to 10 in decimal. It is quite normal for programmers to write in hexadecimal 'hex' because it's easier to visualize the bit pattern of a hex number than it's equivalent decimal version. Think of hex as a shorthand way of writing in binary, each of the characters decodes to 1 of 16 easy to remember bit patterns.

Brian.
 

hi all... thanks for all the comment and idea!!! thanks a lot
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top