新闻中心

EEPW首页>嵌入式系统>设计应用> 利用串口输入整数简单代码

利用串口输入整数简单代码

作者: 时间:2016-11-30 来源:网络 收藏
一开始想利用中断,最终还是利用代码。



#include
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//数码表
uchar num1; //显示十位
uchar num0; //显示个位
//---------------------------------
void delay(uint k) //延时
{
while(k--);
}
//-----------------------------
void main()
{
uchar j;
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SCON=0x50;
while(1)
{
while(RI==1)//输入第一个数字
{
j=SBUF;
num1=j-0;
RI=0;
while(RI==0); // 输入第二个数字
j=SBUF;
num0=j-0;
RI=0;
}
P0=tab[num1];
P2=0xfd;
delay(100);
P0=tab[num0];
P2=0xfe;
delay(100);
}
}


评论


技术专区

关闭