View previous topic :: View next topic |
Author |
Message |
Guest
|
usart config at runtime |
Posted: Tue Feb 14, 2006 10:30 am |
|
|
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
|
|
Posted: Tue Feb 14, 2006 10:56 am |
|
|
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
|
|
Posted: Tue Feb 14, 2006 3:46 pm |
|
|
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
|
|
Posted: Tue Feb 14, 2006 3:54 pm |
|
|
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
|
|
Posted: Wed Feb 15, 2006 5:07 am |
|
|
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
|
|
|
|