C:\Documents and Settings\leovine\桌面各位大师好,我是初学者,在写一个串口1发送的程序,程序如下,不知道为何显示乱码。
#include <LPC213x.H>
#define UART_BPS 9600
#define Fpclk 11059200
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
void DelayNS(uint32 dly)
{
uint32 i;
for(;dly>0;dly--)
for(i=0;i<50000;i++);
}
void UART1_init(void)
{
uint16 Fdiv;
U1LCR=0x83;
Fdiv=(Fpclk/16)/UART_BPS;
U1DLM=Fdiv/256;
U1DLL=Fdiv%256;
U1LCR=0x03;
}
void UART1_SendByte(uint8 data)
{
U1THR=data;
while((U1LSR&0x40)==0);
}
void UART1_SendStr(uint8 const *str)
{
while(1)
{
UART1_SendByte(*str++);
if(*str=='\0') break;
}
}
int main(void)
{
PINSEL0=0x50000;
UART1_init();
while(1)
{
UART1_SendStr("welcome to SHU LV JIAN smart home!\n");
DelayNS(100);
}
return(0);
}
|