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

usart config at runtime

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








usart config at runtime
PostPosted: Tue Feb 14, 2006 10:30 am     Reply with quote

I am trying to change the usart configuration (PIC16F913) at run time
reading the new settings from a register.
I can modify the baud rate but not the parity.
Here the function I use.
How can I do it ?


void configUart(void)
{
unsigned char br_n = 0;
unsigned char pr_n = 0;

br_n = reg[BR_ADDR] ;

pr_n = reg[PAR_ADDR] ;

switch (pr_n)
{
case 0:
#use rs232(parity=n,xmit=PIN_C6,rcv=PIN_C7,bits=8,enable=PIN_C5,errors)
break;
case 1:
#use rs232(parity=e,xmit=PIN_C6,rcv=PIN_C7,bits=8,enable=PIN_C5,errors)
break;
case 2:
#use rs232(parity=o,xmit=PIN_C6,rcv=PIN_C7,bits=8,enable=PIN_C5,errors)
break;
default:
#use rs232(parity=e,xmit=PIN_C6,rcv=PIN_C7,bits=8,enable=PIN_C5,errors) // Default Parity Even
}

switch (br_n)
{
case 0:
set_uart_speed (4800);
break;
case 1:
set_uart_speed (9600);
break;
case 2:
set_uart_speed (19200);
break;
case 3:
set_uart_speed (28800);
break;
case 4:
set_uart_speed (33600);
break;
case 5:
set_uart_speed (57600);
break;
default:
set_uart_speed (9600); // Default Baud Rate 9600
}
}
Alex N



Joined: 10 Feb 2006
Posts: 16

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 10:56 am     Reply with quote

Is it enough for your task to make some output streams with different settings and switch between them at runtime?
gian793



Joined: 14 Feb 2006
Posts: 1

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 3:46 pm     Reply with quote

After calling my function I need to make output streams and also to read from uart. I think there's something wrong in using #use rs232 statement but...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 3:54 pm     Reply with quote

The #use rs232() statement creates one instance of the CCS
library code, based on the parameters that you specify.
It doesn't change parameters at runtime in a single instance
of the code, which is what you're hoping it does.
Guest








PostPosted: Wed Feb 15, 2006 5:07 am     Reply with quote

o.k the code I have written was wrong.
Any suggest to cope with the problem of changing the parity at run time?
Can I write a routine that do it?
The only way is to avoid getc() and putc() functions and handle the uart registers directly?
Alex N



Joined: 10 Feb 2006
Posts: 16

View user's profile Send private message

PostPosted: Wed Feb 15, 2006 8:01 am     Reply with quote

This is a similar topic:
http://www.ccsinfo.com/forum/viewtopic.php?t=22062
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