#include<reg51.h>
#include <absacc.h>
#define PORT XBYTE [0x7fff]
unsigned char code Tab[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //0~9段码
unsigned char cf[4]={1,2,3,4};
sbit sw=P3^0;//数码管动态显示的位选定义
sbit gw=P3^1;
void disp(unsigned char i)
{
PORT=~i;
}
void delay(unsigned char j) //0.01s*j
{
unsigned char m,n;
for(;j>0;j--)
{
for(m=0;m<20;m++)
for(n=0;n<250;n++);
}
}
void bcdm(unsigned char q) //数码管显示的十位和个位
{
cf[0]=q/10;
cf[1]=q%10;
}
void smgdjs(unsigned char q) //数码管倒计时
{
unsigned char a;
while(q)
{
bcdm(q);
for(a=0;a<50;a++)
{
sw=0;gw=1;
P1=Tab[cf[0]];
delay(1);
sw=1;gw=0;
P1=Tab[cf[1]];
delay(1);
}
q--;
}
}
void hds(void) //黄灯闪烁
{
unsigned char k,a,l;
for(k=5;k>0;k--)
{
bcdm(k);
disp(0x12);
for(a=0;a<50;a++)
{
sw=0;gw=1;
P1=Tab[cf[0]];
delay(1);
sw=1;gw=0;
P1=Tab[cf[1]];
delay(1);
}
disp(0x0);
for(a=0;a<50;a++)
{
sw=0;gw=1;
P1=Tab[cf[0]];
delay(1);
sw=1;gw=0;
P1=Tab[cf[1]];
delay(1);
}
}
}
void main(void)
{
unsigned char p;
disp(0x21);
delay(10);
while(1)
{
disp(0x09);
p=10;
smgdjs(p);
hds();
disp(0x24);
smgdjs(p);
// delay(50);
hds();
}
}
|