#include ***it a=P1^0; //led1 ***it b=P1^1; ***it c=P1^2; ***it d=P1^3; ***it h1=P0^0; //红外对管 ***it h2=P0^1; //红外对管 ***it h3=P0^4; //红外对管 int go,back,left,right,clean,clean_over,xunji,xunji_over; int flag_uart=0; int flag_on=0; void UsartConfiguration(); //串口初始化 void main() { UsartConfiguration(); while(1) { if(flag_uart==1) { ES=0; flag_uart=0; switch(flag_on) { case 1: go=1; break; case 2: back=1; break; case 3: left=1; break; case 4: right=1; break; case 5: clean=1; break; case 6: xunji=1; break; case 7: clean_over=1; break; case 8: xunji_over=1; break; } ES=1; flag_on=0; } if(go==1) a=0; } } //串口初始化 void UsartConfiguration() { SCON=0X50; //设置为工作方式1 TMOD=0X20; //设置计数器工作方式2 PCON=0X80; //波特率加倍 TH1=0XFd; //计数器初始值设置,注意波特率是9600 TL1=0XFd; ES=1; //打开接收中断 EA=1; //打开总中断 TR1=1; //打开计数器 } //串口中断:中断入口号4 void Usart() interrupt 4 { int receiveData; receiveData=SBUF;//出去接收到的数据 RI = 0;//清除接收中断标志位 //new flag_uart = 1; if(receiveData==97) flag_on=1; else if(receiveData=='i') flag_on=2; else if(receiveData=='j') flag_on=3; else if(receiveData=='k') flag_on=4; else if(receiveData=='l') flag_on=5; else if(receiveData=='m') flag_on=6; else if(receiveData=='n') flag_on=7; else if(receiveData=='o') flag_on=8; SBUF=receiveData; //将接收到的数据放入到发送寄存器 while(!TI); //等待发送数据完成 TI=0; //清除发送完成标志位 } |
更多回帖