基于51单片机的电子记分牌C程序编程
时间:12-01
来源:互联网
点击:
#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--);
}
51单片机电子记分牌C程序编 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)