#include <reg52.h>
#define guan P1
#define wei P3
#define uchar unsigned char
#define uint unsigned int
uint m=0;
uchar a1,a0,k=0,j,k,s=60;
sbit beep=P3^7;
unsigned char code weiyu[]={0xdf,0xf1,0xfd}; //代码与P3对应做位处理,显示相应的位
//ge = P3^1; 1111 1101 // shi = P3^0;1111 1110//bai = P3^6;1011 1111
unsigned char code table[]={0xFC, 0x60, 0xDA, 0x8F, 0xCC, 0xED, 0xFD, 0x07, 0xFF, 0xEF};//共阴极数码管码表
void delay(unsigned char xms)
{
for(j=xms;j>0;j--)
for(k=125;k>0;k--);
}
void display1(uchar wei1,uchar shu)
{
wei=0xff;
P1=table[shu];
wei=wei&weiyu[wei1];
delay(5);
}
void display(uchar a,uchar b)
{
display1(2,a);
display1(3,b);
}
void main()
{
TMOD=0x01;
ET0=1;
TR0=1;
EA=1;
while(1)
{
if(m==20)
{
m=0;
s--;
}
a1=s/10;
a0=s%10;
display(a1,a0);
if(s==0)
{
TR0=0;
beep=0;
}
}
}
void TO_TIMER () interrupt 1
{
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
m++;
}
|