📄 main.c
字号:
#include "lpc21xx.h"
#include "my_type.h"
void DelayNS(uint32 dly)
{
uint32 i;
for(;dly>0;dly--)
for(i=0;i<50000;i++);
}
void UART0_Ini(void)
{
U0LCR=0x83; //DLAB=1,可设置波特率
U0DLL=9; //外部晶振频率11.0592,外部总线频率用默认值 Startup.s中Configuration Wizard中不要了PLL和MAM两个 19200
U0DLM=0x00;
U0LCR=0x03;
}
void sendbyte(uint8 data)
{
uint32 i;
U0THR=data; //发送数据
while((U0LSR&0x40)==0); //等待数据发送完毕
// 注意:这里要延时一下下的!
for(i=0; i<5; i++);
}
void sendstring(uint8 const *str)
{
while(1)
{
if(*str=='\0')
{
sendbyte('\r');
sendbyte('\n');
break;
}
sendbyte(*str++); //发送数据
}
}
char receivedata(void)
{
while(!(U0LSR&0x01));
return U0RBR;
}
// 这是一种方法
/*
void display(void)
{
uint8 data = 0;
uint8 p1,p2;
data = receivedata();
p1=(data/16)%16;
if (p1>=10) // 十六进制的高位
sendbyte((data >> 4) + 55); // high
else
sendbyte((data >> 4) + 48); // low
p2=data%16; // 低位
if (p2>=10)
sendbyte((data & 0x0f) + 55); // high
else
sendbyte((data & 0x0f) + 48); // low
sendbyte(' ');
} */
int main(void)
{
uint8 const SEND_STRING[]="I am Late Lee\n";
uint8 const data[]={"0123456789ABCDEF"};
uint8 temp;
PINSEL0=0x00000005; //设置I/O连接到UART0
PINSEL1=0x00000000;
UART0_Ini();
DelayNS(1);
sendstring(SEND_STRING);
DelayNS(10);
while(1)
{
// display();
temp=receivedata();
// 这也是一种方法
if (temp) // 有就显示,没有就不显示
{
sendbyte(data[temp>>4]);
sendbyte(data[temp&0x0f]);
sendbyte(0x20);
temp=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -