#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit wl=P2^1;
sbit dl=P2^0;
sbit K0=P2^7;
sbit K1=P1^0;
sbit K2=P1^1;
sbit K3=P1^2;
sbit K4=P1^3;
sbit K5=P1^4;
sbit K6=P1^5;
sbit K7=P1^6;
sbit K8=P1^7;
sbit sound=P2^2;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
uchar num,num1=120,ge,shi,bai,n,m;
void delay(uint z)//任意延时
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void fmq() //
{
uchar i;
for(i=0;i<100;i++)
{
sound = ~sound;
delay(2);
}
sound = 0;
//sound=0;
//delay(500);
//sound=1;
}
void shuma(uchar ge,uchar shi,uchar bai)//数码管显示
{
dl=1;
P3=table[bai];
dl=0;
wl=1;
P3=0XFE;
wl=0;
delay(500);
dl=1;
P3=table[shi];
dl=0;
P3=0XFF;
wl=1;
P3=0XFD;
wl=0;
delay(500);
dl=1;
P3=table[ge];
dl=0;
P3=0XFF;
wl=1;
P3=0XFB;
wl=0;
delay(500);
}
void scan() //按键扫描
{
if(K0==0)
{
delay(5);
if(K0==0)
{
m++;
TR0=1;//中断开启
P0=0XFF;
fmq();
}
}
if(K1==0)
{
delay(5);
if(K1==0)
{
P0=0XFE;
fmq();
delay(2000);
P0=0XFF;
}
}
if(K2==0)
{
delay(5);
if(K2==0)
{
P0=0XFD;
fmq();
delay(2000);
P0=0XFF;
}
}
if(K3==0)
{
delay(5);
if(K3==0)
{
P0=0XFB;
fmq();
delay(2000);
P0=0XFF;
}
}
if(K4==0)
{
delay(5);
if(K4==0)
{
P0=0XF7;
fmq();
delay(2000);
P0=0XFF;
}
}
if(K5==0)
{
delay(5);
if(K5==0)
{
P0=0XEF;
fmq();
delay(2000);
P0=0XFF;
}
}
if(K6==0)
{
delay(5);
if(K6==0)
{
P0=0XDF;
fmq();
delay(2000);
P0=0XFF;
}
}
if(K7==0)
{
delay(5);
if(K7==0)
{
P0=0XBF;
fmq();
delay(2000);
P0=0XFF;
}
}
if(K8==0)
{
delay(5);
if(K8==0)
{
P0=0X7F;
fmq();
delay(2000);
P0=0XFF;
}
}
}
void main()
{
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
P0=0XFF;
while(1)
{
if(m==3)
{
m=0;
TR0=0;
wl=1;
P3=0XFF;
wl=0;
num1=120;
}
scan();
}
}
void timer() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num==20)
{
num=0;
num1--;
if(num==30)//倒计时30秒响铃
fmq();
if(num1==0)
{
TR0=0;
num1=0;
}
bai=num1/100;
shi=num1%100/10;
ge=num1%10;
shuma(ge,shi,bai);
}
}
文章评论(0条评论)
登录后参与讨论