基于51单片机的电子记分牌C程序编程
2015-05-13 来源:51hei
#include
sbit r1=P2^0;
sbit r2=P2^1;
sbit h1=P3^0;
sbit h2=P3^1;
void delay(unsigned char x);
char scank();
void display(char);
unsigned char dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0XD8,0x80,0x90};
void main()
{
char num=0,keynum;
while(1)
{
keynum=scank();
num=num+keynum;
if(num<0) num=99;
if(num>99) num=0;
display(num);
}
}
char scank()
{
char i=0;
if(h1==0)
{ delay(3);
if(h1==0)
{ while(!h1);
i=1;
}
}
if(h2==0)
{ delay(3);
if(h2==0)
{ while(!h2);
i=-1;
}
}
return i;
}
void display(char num)
{
r1=1;r2=0;
P0=dispcode[num/10];
delay(10);
r1=0;r2=0;
r1=0;r2=1;
P0=dispcode[num%10];
delay(10);
r1=0;r2=0;
}
void delay(unsigned char x)
{
unsigned char a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
相关文章
最新器件