单片机STC-89C52RC 通过发送按键字符在串口助手里显示,求程序,急用,在线等……
就是在单片机上按下1键在串口调试助手里显示1,按下2键显示2,以此类推,共四个按键。波特率9600....
就是在单片机上按下1键在串口调试助手里显示1,按下2键显示2,以此类推,共四个按键。波特率9600.
展开
展开全部
#include<reg51.h>
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
main()
{
TMOD=0x20;
SCON=0x50;
TH1=0xfd;
TL1=0xfd;
TR1=1;
while(1)
{
if(key1==0){while(key1==0);SBUF='1',while(!TI);TI=0;}
if(key2==0){while(key2==0);SBUF='2',while(!TI);TI=0;}
if(key3==0){while(key3==0);SBUF='3',while(!TI);TI=0;}
if(key4==0){while(key4==0);SBUF='4',while(!TI);TI=0;}
}
}
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
main()
{
TMOD=0x20;
SCON=0x50;
TH1=0xfd;
TL1=0xfd;
TR1=1;
while(1)
{
if(key1==0){while(key1==0);SBUF='1',while(!TI);TI=0;}
if(key2==0){while(key2==0);SBUF='2',while(!TI);TI=0;}
if(key3==0){while(key3==0);SBUF='3',while(!TI);TI=0;}
if(key4==0){while(key4==0);SBUF='4',while(!TI);TI=0;}
}
}
更多追问追答
追答
#include
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
main()
{
TMOD=0x20;
SCON=0x50;
TH1=0xfd;
TL1=0xfd;
TR1=1;
while(1)
{
if(key1==0){while(key1==0);SBUF='1';while(!TI);TI=0;}
if(key2==0){while(key2==0);SBUF='2';while(!TI);TI=0;}
if(key3==0){while(key3==0);SBUF='3';while(!TI);TI=0;}
if(key4==0){while(key4==0);SBUF='4';while(!TI);TI=0;}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询