#include <reg52.h>
#include<stdlib.h>
#define uint unsigned long
#define uchar unsigned char
sbit led1 = P2^0; // 0 light
sbit led2 = P2^1;
sbit led3 = P2^2;
sbit led4 = P2^3;
uchar code table[]={0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
uint num,a;
sbit Key=P3^5;
void delayms(unsigned char t)
{
unsigned char i;
while(t--)
{
for(i=0;i<255;i++)
{
}
}
}
void display(unsigned long cnt)
{
led1=0;
P0=table[(cnt%10000)/1000];
delayms(1);
P0=0XFF;
led1=1;
led2=0;
P0=table[(cnt%1000)/100];
delayms(1);
P0=0XFF;
led2=1;
led3=0;
P0=table[(cnt%100)/10];
delayms(1);
P0=0XFF;
led3=1;
led4=0;
P0=table[cnt%10];
delayms(1);
P0=0XFF;
led4=1;
}
void main(void)
{
unsigned char cnt=0;
SCON = 0x50;
TMOD |= 0x20;
TH1 = 0xFD;
TR1 = 1;
delayms(1);
while(1)
{display(cnt);
if(Key==0)
{
delayms(10);
if(Key==0)
{
SBUF=cnt;
cnt++;
while(TI==0);
TI=0;
while(Key==0);
}
}
}
} 我按独立按键,从1 按到21但是显示的却是下面的数字,求大佬指教,怎么可以在电脑上显示按键次数呢!
|