#include<LPC21xx.h>
typedef unsigned char uchar;
typedef unsigned int uint;
void delay()
{
uint i = 0xfff;
while(i --);
}
void UART0_Init(void)
{
VPBDIV = 0; // 1/4 CCLK = PCLK
U0LCR = 0x83; // DLAB = 1,可设置波特率
U0DLL = 0x12;
U0DLM = 0x00;
U0LCR = 0x03; //8bit
}
void UART0_SendByte(uchar data)
{
uchar i;
U0THR = data; // 发送数据
while( (U0LSR&0x40)==0 ); // 等待数据发送完毕
{
for(i=0; i<5; i++);
}
}
uchar UART0_RecByte()
{
while(!(U0LSR&0x01));
return U0RBR;
}
/*
int main(void)
{
uchar data = 0x03;
UART0_Init();
PINSEL0 = 0X00000005; //UART0
while(1)
{
delay();
UART0_SendByte(data);
}
}
*/
int main(void)
{
uint data;
UART0_Init();
PINSEL0 = 0X00000005;
IODIR0 = 0XFFFFFFFF;
IOSET0 = 0XFFFFFFFF;
while(1)
{
data = (uint)UART0_RecByte();
IOSET0 = data << 2;
IOCLR0 = ~(data << 2);
}
}
评论0