/*
此代码为一个单片机简单通信程序,程序实现功能为PC机向单片机发A然后单片机向PC会B,程序仅供大家参考。
*/
#include
sfr AUXR = 0x8E;
void InitUART(void)
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xDC;
TL1 = TH1;
PCON = 0x00;
EA = 1;
ES = 1;
TR1 = 1;
}
void SendOneByte(unsigned char c)
{
SBUF = c;
while(!TI);
TI = 0;
}
void main(void)
{
AUXR = AUXR|0x40; // T1, 1T Mode
InitUART();
}
void UARTInterrupt(void) interrupt 4
{
static number;
if(RI)
{
RI = 0;
number = SBUF;
number = number+1;
SendOneByte(number);
}
else
TI = 0;
}