|
#include "UART.h"
unsigned char DATE[10];
unsigned char i=0;
bit busy;
void Init_Uart() //UART初始化
{
T2L=(65536-(FOSC/4/BAUD));
T2H=(65536-(FOSC/4/BAUD))>>8;
SCON=0X50; //8位可变波特率
AUXR=0X15; //T2工作在1T模式; 用定时器T2作为波特率发生器
AUXR1=0x40;
ES=1;
EA=1;
}
void senddate(unsigned char dat) //发送字节
{
while(busy);
SBUF=dat;
busy=1;
}
void sendstring(unsigned char *s) //发送字符串
{
while(*s!='\0')
{
senddate(*s++);
}
}
void UART()interrupt 4 //UART中断
{
if(RI)
{
RI=0;
DATE[i++]=SBUF;
if(i==8)
{
i=0;
}
}
if(TI)
{
TI=0;
busy=0;
}
}
|
-
1.JPG
(61.46 KB, 下载次数: 99)
|