两个按键,每按下一次对应的计分器加1
单片机源程序如下:
#include
#define uint unsigned int
#define uchar unsigned char
#define dat P0
code uchar d[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint second=0,minter=0,hour=0;
uint mge,mshi,hshi,hge;
static char court=0;
sbit q1=P2^0;
sbit q2=P2^1;
sbit q3=P2^2;
sbit q4=P2^3;
sbit q5=P2^4;
sbit q6=P2^5;
sbit q7=P2^6;
sbit q8=P2^7;
sbit key1=P3^2;
sbit key2=P3^3;
void delay(uint number)
{
uchar i,j;
for(i=0;i
}
void int11() interrupt 1 using 2
{
TH0=0x5c;
TL0=0xb0;
//court++;
}
void int0() interrupt 0 using 1 minter++;
if(minter==99)
minter=0;
}
void int1() interrupt 2 using 1
{
hour++;
if(hour==99)
hour=0;
}
void main()
{
TMOD=0X01;
TH0=0x5c;
TL0=0xb0;
ET0=1;
EX0=1;
EX1=1;
IT0=1;
IT1=1;
EA=1;
TR0=1;
while(1)
{
mshi=minter/10;
mge=minter%10;
hshi=hour/10;
hge=hour%10;
dat=d[mge];
q8=1;
delay(2);
q8=0;
dat=d[mshi];
q7=1;
delay(2);
q7=0;
dat=0xbf;
q6=1;
delay(2);
q6=0;
dat=0xbf;
q5=1;
delay(2);
q5=0;
dat=0xbf;
q4=1;
delay(2);
q4=0;
dat=0xbf;
q3=1;
delay(2);
q3=0;
dat=d[hge];
q2=1;
delay(2);
q2=0;
dat=d[hshi];
q1=1;
delay(2);
q1=0;
if(court==20)
{court=0;
minter++;
if(minter==99)
{minter=0;
hour++;
if(hour==99)
hour=0;
}}}}
全部资料51hei下载地址:
计分器3.rar
(61.05 KB, 下载次数: 4)