您的位置 首页 芯闻

根据51单片机的电子记分牌C程序编程

includereg52h>sbitr1=P2^0;sbitr2=P2^1;sbith1=P3^0;sbith2=P3^1;voiddelay(unsignedcharx);charscank(

#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–);

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/news/xinwen/317451.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部