利用串口輸入整數(shù)簡(jiǎn)單代碼
#include
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//數(shù)碼表
uchar num1; //顯示十位
uchar num0; //顯示個(gè)位
//---------------------------------
void delay(uint k) //延時(shí)
{
while(k--);
}
//-----------------------------
void main()
{
uchar j;
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SCON=0x50;
while(1)
{
while(RI==1)//輸入第一個(gè)數(shù)字
{
j=SBUF;
num1=j-0;
RI=0;
while(RI==0); // 輸入第二個(gè)數(shù)字
j=SBUF;
num0=j-0;
RI=0;
}
P0=tab[num1];
P2=0xfd;
delay(100);
P0=tab[num0];
P2=0xfe;
delay(100);
}
}
評(píng)論