
VMX51C1020
_________________________________________________________________________________________________
www.ramtron.com
page 40 of 80
Example of UART0 Setup and Use
In order to use UART0, the following operations
must be performed:
o
Enable the UART0 Interface
o
Set I/O Pad direction
TX= output, RX=Input
o
Enable Reception (if required)
o
Configure the Uart0 controller S0CON
The following are configuration and transmission
code examples for UART0.
//----------------------------------------------------------------------------------------//
// UART0 CONFIG with S0REL
//
// Configure the UART0 to operate in RS232 mode at 19200bps
// with a crystal of 14.7456MHz
//
//----------------------------------------------------------------------------------------//
void uart0ws0relcfg()
{
P3PINCFG |= 0x01;
DIGPWREN |= 0x01;
S0RELL = 0xF4;
S0RELH = 0x03;
S0CON = 0x50;
// Uart0 in mode1, 8 bit, var. baud rate
U0BAUD = 0x80;
//Set S0REL is source for UART0
//Baud rate clock
}//end of uart0ws0relcfg() function
//----------------------------------------------------------------------------------------//
// UART0 CONFIG with Timer 1
//
// Configure the UART0 to operate in RS232 mode at 19200bps
// with a crystal of 14.7456MHz
//
//----------------------------------------------------------------------------------------//
void uart0wTimer1cfg()
{
P3PINCFG |= 0x01;
DIGPWREN |= 0x01;
TMOD &= 0x0F;
TMOD =0x20;
//Set Timer 1, Gate 0, Mode 2
TH1 = 0xFE;
TCON &= 0x0F;
TCON =0x40;
U0BAUD = 0x00;
// pads for uart 0
// enable uart0/timer1
//com speed = 19200bps
// pads for uart0
// enable uart0/timer1
//Com Speed = 19200bps
//Start Timer 1
//Set Timer 1 Baud rate
//generator for UART0
PCON = 0x00;
S0CON = 0x50;
//Set SMOD = 0
// Config Uart0 in mode 1,
//8 bit, variable baud rate
//----------------------------------------------------------------------------------------//
// Txmit0()
//
// One Byte transmission on UART0
//----------------------------------------------------------------------------------------//
// - Constants definition
sbit UART_TX_EMPTY = USERFLAGS^1;
void txmit0( unsigned char charact){
S0BUF = charact;
USERFLAGS = S0CON;
//Wait TX EMPTY flag to be raised
while (!UART_TX_EMPTY) {USERFLAGS = S0CON;} S0CON =
//clear both R0I & T0I bits
S0CON & 0xFD;
}//end of txmit0() function
See the Interrupt section for example of setup of
UART0 interrupts
}//end of uart1Config() function