#include <reg52.h>#include <stdio.h> //初始化串行口
void InitCom(unsigned char BaudRate){unsigned char THTL;switch (BaudRate){case 1: THTL = 0xE8; break; //波特率1200case 2: THTL = 0xF3; break; //波特率2400case 3: THTL = 0xFA; break; //波特率4800case 4: THTL = 0xFD; break; //波特率9600default: THTL = 0xFD;}EA=1;ET1=0;ES=1;TR1 = 1; //启动定时器
SCON = 0x50; //串口方式1,允许接收TMOD = 0x20; //定时器1定时方式2TCON = 0x40; //设定时器1开始计数TH1 = THTL;TL1 = THTL;PCON = 0x00; //波特率加倍控制,SMOD位RI = 0; //清收发标志TI = 0;
}
void main() { int i,j; char c='A'; InitCom(2);
while(1) { TI=0; P0=c; SBUF=c; while(!TI); TI=0; for(j=0;j<25;j++) for(i=0;i<5000;i++); c++; if(c=='Z'+1) c='A'; } }
void intrr() interrupt 4 { char temp; temp=SBUF; P2=temp; RI=0; }
#include
#include
//åå§å串è¡å£
bit flag;
void main()
{
InitCom(2);//åå§å
while(1)
{
if(flag==1)
{
char temp;
ES=0;
temp=SBUF;
P2=temp;
RI=0;
ES=1;
}
}
}
void intrr() interrupt 4
{
flag=1;
}
æç¨åºæ¹æåªæ¥æ¶pcæºåéçæ°æ®ï¼å¯æ°ç 管ä¸ç´æ¾ç¤ºçæ¯FF
不行 情况是一样的~~