📄 uart.c
字号:
#include "config.h"
//#include "type.h"
/*
*********************************************************************************************************
** 函数名称 :UART0_SendByte()
** 函数功能 :向串口发送字节数据,并等待发送完毕,查询方式。
** 入口参数 :dat 要发送的数据
** 出口参数 :无
*********************************************************************************************************
*/
void printc (uint8 dat)
{
U0THR = dat;
while ((U0LSR & 0x40) == 0); // 等待数据发送完毕
}
void printd(uint16 a)
{
uint8 not0=0,temp,temp2;
uint16 temp0,temp1;
temp0 = a%10000;
temp1 = temp0%1000;
temp2 = temp1%100;
temp = a/10000;
if(temp)
{
not0=1;
printc(0x30+temp);
}
//发万位
temp = temp0/1000;
if(not0)
printc(0x30+temp);
else if(temp)
{
printc(0x30+temp);
not0=1;
}
//发千位
temp = temp1/100;
if(not0)
printc(0x30+temp);
else if(temp)
{
printc(0x30+temp);
not0=1;
}
//发百位
temp = temp2/10;
if(not0)
printc(0x30+temp);
else if(temp)
{
printc(0x30+temp);
not0=1;
}
//发十位
printc(0x30+temp2%10);
//发个位
}
void printh(uint8 a) {
printc(0x30);
printc('x');
if((a/16)>9)
printc(a/16+0x37);
else
printc(a/16+0x30);
if((a%16)>9)
printc(a%16+0x37);
else
printc(a%16+0x30);
}
void prints(char *pt,uint8 a) {
while(*pt!=0) {
if(*pt=='%'){
pt++;
if(*pt=='d')
printd(a);
else if(*pt=='h')
printh(a);
else
printc(*pt);
pt++;
}
printc(*pt++);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -