標(biāo)題: 基于c51單片機(jī)的簡易搶答器 [打印本頁]

作者: vhvhg    時間: 2021-12-7 09:20
標(biāo)題: 基于c51單片機(jī)的簡易搶答器
#include  <reg51.h>
#define   u8   unsigned  char
#define   u16  unsigned  int

sbit  P23=P1^0;
sbit  P24=P1^1;
sbit  P25=P1^2;
sbit  P28=P1^7;
sbit  key=P3^1;

u16 duanma[]={0xc0,0xf9,0xa4,0xb0,0x99,
              0x92,0x82,0xf8,0x80,0x90};


void delay(u16 num)

{
   u16 x,y;       
  for(x=num;x>0;x--)
  for(y=110;y>0;y--);
}
                          
void main()
{u8  a,b;
a=5,b=5;
P0=duanma[a];
P2=duanma[b];
while(1)
{
if(P23==0)
{delay(10);
if(P23==0)
{P28=0;
while(!P28){if(P24==0)
{delay(10);
if(P24==0)
{
P28=1;
a++;
P0=duanma[a];
}
} while(!P24);

if(P25==0)
{delay(10);
if(P25==0)
{
P28=1;
b++;
P2=duanma[b];
}
}while(!P25);}
}
}

if(P24==0)
{
delay(10);
if(P24==0)
{
P28=1;
a=a-1;
P0=duanma[a];
}
}while(!P24);

if(P25==0)
{
delay(10);
if(P25==0)
{
P28=1;
b=b-1;
P2=duanma[b];
}
}while(!P25);

if(a==0|a==9|b==0|b==9)
{
key=0;
}
}
}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1