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

help! how can I change baud rate?

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







help! how can I change baud rate?
PostPosted: Thu Jun 19, 2008 7:00 am     Reply with quote

hello,

I have a stupid problem and I don't find how to resolve it:

I use a 16f876a and I need to change baud rate during the use

I try it
Code:
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

//later
#asm
bcf 0x03,5
bsf 0x03,6  ;banque 1

bcf 0x98,2 ;low speed

movlw 64

movwf 0x99 ; 64 in SPBRG for 4800 baud

bcf 0x03, 5
bcf 0x03,6
#endasm


but the baud rate is not change

can you explain me how to do??

thanks

spilz
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Jun 19, 2008 7:19 am     Reply with quote

How about using a second #use RS232 line? There is also a set_uart_speed() function in my version 3.242 compiler. What compiler version and which PIC are you using?
_________________
The search for better is endless. Instead simply find very good and get the job done.
spilz
Guest







PostPosted: Thu Jun 19, 2008 7:31 am     Reply with quote

I am using v4.065

there is only one uart in this pic, and if I use for exemple :

Code:
if(i==1){
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)}
else{
#use rs232(baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)}

it's always the same baud rate whatever i value.
Ttelmah
Guest







PostPosted: Thu Jun 19, 2008 8:44 am     Reply with quote

The 'point' about a second #use RS232, is you declare it as a second stream, then you can putc/getc, to this stream when you want one rate, and to the other for the second rate. The #use RS232, will _always_ use the value declared in the _last_ definition 'passed' (does not listen to run time tests), unless you use a stream designator. You can have multiple #use RS232 declarations, by branching in a different way (a search here will find references to this).
set_uart_speed, is the easiest way to do this if you only want to change speeds (the second stream is the only way to support things like parity changes as well).
If you want to access the SPBRG register directly, just use the #byte directive. You are accessing bank 1. The BRG, is address 19, in bank 1, not 99. The compiler is smart enough to do this, if you simply tell it to access address 0x99 (it'll automatically bank switch, unless you use the 'ASIS' directive.
So the 'C' way to do what is in your assembler is:
Code:

#byte SPBRG=0x99
#byte TXSTA=0x98
#bit BRGH=TXSTA.2


BRGH=0; //select /64 prescaler
SPBRG=64; //set clock to Fosc/(64*65) - 4800bs for 2MHz Fosc

The easiest way to change the speed is:
Code:

//Or (the simplest).

If (i==1) set_uart_speed(115200);
else set_uartspeed(4800);


Now, if your master oscillator is 2Mhz (as your code suggests), I'm surprised the compiler doesn't complain when you try to select 115200bps. this is not achievable from a 2MHz clock with acceptable accuracy (normally you can reckon on anything beyond about 4% error, will fail to work). If your clock is not 2MHz, rethink your calculations....

Best Wsihes
Guest








PostPosted: Fri Jun 20, 2008 12:54 am     Reply with quote

thanks, it works fine

spilz
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