Keil™, An ARM® Company

Discussion Forum

using PCA FOR baud rate generation i am acing problem

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
geetha s
Posted
16-Jul-2008 01:29
Toolset
C51
New! using PCA FOR baud rate generation i am acing problem

HEllo we are using silabs c8051f340 controller.we try to implement software uart using programle counter arrays(PCA)for baud rate generation and i am not able get to desired baudrate .we are using internal clk of 12000000 and baudrate is 9600 please try to give sloution

Read-Only
Author
chandra vel
Posted
17-Jul-2008 10:32
Toolset
C51
New! RE: using PCA FOR baud rate generation i am acing problem

void UART0_Init (void)
{ SCON0 = 0x10; // SCON0: 8-bit variable bit rate // level of STOP bit is ignored // RX enabled // ninth bits are zeros // clear RI0 and TI0 bits if (SYSCLK/BAUDRATE/2/256 < 1) { TH1 = -(SYSCLK/BAUDRATE/2); CKCON &= ~0x0B; // T1M = 1; SCA1:0 = xx CKCON |= 0x08; } else if (SYSCLK/BAUDRATE/2/256 < 4) { TH1 = -(SYSCLK/BAUDRATE/2/4); CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 01 CKCON |= 0x09; } else if (SYSCLK/BAUDRATE/2/256 < 12) { TH1 = -(SYSCLK/BAUDRATE/2/12); CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 00 } else { TH1 = -(SYSCLK/BAUDRATE/2/48); CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 10 CKCON |= 0x02; }

TL1 = TH1; // init Timer1 TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit autoreload TMOD |= 0x20; TR1 = 1; // START Timer1 TI0 = 1; // Indicate TX0 ready
}

Read-Only
Author
Per Westermark
Posted
17-Jul-2008 13:49
Toolset
C51
New! RE: using PCA FOR baud rate generation i am acing problem

5 points for unreadable code.

What was wrong with posting the code according to the Keil instructions? Would that have made the code too easy to read?

Read-Only
Author
stephen phillips
Posted
18-Jul-2008 11:36
Toolset
C51
New! RE: using PCA FOR baud rate generation i am acing problem

Wow that came out to one line this is kind of what it was supposed to be I think.

void UART0_Init (void)
{
SCON0 = 0x10; // SCON0: 8-bit variable bit rate
// level of STOP bit is ignored
// RX enabled
// ninth bits are zeros
// clear RI0 and TI0 bits
if (SYSCLK/BAUDRATE/2/256 < 1) {
TH1 = -(SYSCLK/BAUDRATE/2);
CKCON &= ~0x0B; // T1M = 1;
SCA1:0 = xx CKCON |= 0x08;
}
else
if (SYSCLK/BAUDRATE/2/256 < 4)
{
TH1 = -(SYSCLK/BAUDRATE/2/4);
CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 01
CKCON |= 0x09;
}
else
if (SYSCLK/BAUDRATE/2/256 < 12)
{
TH1 = -(SYSCLK/BAUDRATE/2/12);
CKCON &= ~0x0B;
// T1M = 0; SCA1:0 = 00
}
else
{
TH1 = -(SYSCLK/BAUDRATE/2/48);
CKCON &= ~0x0B;
// T1M = 0; SCA1:0 = 10
CKCON |= 0x02;
}

TL1 = TH1; // init Timer1
TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit autoreload
TMOD |= 0x20;
TR1 = 1; // START Timer1
TI0 = 1; // Indicate TX0 ready
}


Dubious translation caveats added.

Stephen

Next Thread | Thread List | Previous Thread Start a Thread | Settings