#include <LPC21xx.H>
void init_serial (void);
int putchar(int ch);
int getchar (void);
void display_string(char*);
int main(void)
{ char *str;
VPBDIV = 0x02; // Divide Pclk by two
str = "This is a UART Program";
init_serial();
display_string(str);
putchar('\r');
putchar('\n');
while(1)
{
putchar(getchar()+1); // Echo terminal
}
}
void init_serial (void)
{
PINSEL0 = 0x00000005; // Enable RxD0 and TxD0
U0LCR = 0x00000083; //8 bits, no Parity, 1 Stop bit
U0DLL = 0x000000C3; //9600 Baud Rate @ 30MHz VPB Clock
U0LCR = 0x00000003;
}
int putchar (int ch)
{
while (!(U0LSR & 0x20));
return (U0THR = ch);
}
int getchar (void)
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void display_string(char *str)
{
while(*str)
putchar(*str++);
}
void init_serial (void);
int putchar(int ch);
int getchar (void);
void display_string(char*);
int main(void)
{ char *str;
VPBDIV = 0x02; // Divide Pclk by two
str = "This is a UART Program";
init_serial();
display_string(str);
putchar('\r');
putchar('\n');
while(1)
{
putchar(getchar()+1); // Echo terminal
}
}
void init_serial (void)
{
PINSEL0 = 0x00000005; // Enable RxD0 and TxD0
U0LCR = 0x00000083; //8 bits, no Parity, 1 Stop bit
U0DLL = 0x000000C3; //9600 Baud Rate @ 30MHz VPB Clock
U0LCR = 0x00000003;
}
int putchar (int ch)
{
while (!(U0LSR & 0x20));
return (U0THR = ch);
}
int getchar (void)
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void display_string(char *str)
{
while(*str)
putchar(*str++);
}
Comments
Post a Comment