#include<reg52.h>
#include<stdio.h>
volatile unsigned char UartIsSending;//volatile防止该变量所在语句被优化,问:静态的不行?全局变量不行?
char putchar (char ucWriteData)//函数重写
{
SBUF=ucWriteData;
UartIsSending=1;
while(UartIsSending);
return ucWriteData;
}
volatile unsigned char UartIsSending;
void UartIsr(void) interrupt 4
{
if(TI) //发送中断
{
UartIsSending=0;
TI=0;
}
if(RI) //接收中断
{
RI=0;
}
}
void serial_init ()
{
SCON = 0x50;
TMOD |= 0x20;
TH1 = 0xf3;
TL1 = 0xf3;
TR1 = 1;
ES=1;
}
void Delay(void)
{
unsigned char ucDelayCount;
for(ucDelayCount=0; ucDelayCount<0xFF; ucDelayCount++)
{
;
}
}
void main(void)
{
serial_init();
EA = 1;
while(1)
{
putchar('8');
putchar('\n');
Delay();
printf("welcome to 21ic \n");
}
}
这个在keil仿真中跑的一点问题都没有 但是串口小助手就是乱码,求解释…… |