#include <reg52.h>
unsigned char LEDBuf[6] ;
unsigned char s=100; //1秒间中断次数
unsigned char Hour=0;
unsigned char Second=0;
unsigned char Minute=0;
unsigned char LEDMAP[]={0X3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71} ;
Delay() //延时
{unsigned char c;
for(c=10;c>0;c--)
;
}
void DisplayLED() //动态显示共阴
{ unsigned char i;
unsigned char pos,k;
pos=0x20;
for(i=0;i<6;i++)
{ k=pos;
P1=~k;
P0=0x00;
P0=LEDBuf[i];
Delay();
pos>>=1; //移为
}
}
void t0() interrupt 1 //T0中断
{ s--; //1秒间中断次数
if(s==0)
{ s=100;
Second++;
if(Second==60)
{Second=0;
Minute++;
if(Minute==60)
{Minute=0;
Hour++;
if(Hour==24)
{ Hour=0; }
}
}
}
}
void main()
{
TMOD = 0x01; //方式1
TH0 = 0xD8; //中断初值 0.01毫秒
TL0 = 0xF0;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1)
{
LEDBuf[5]=LEDMAP[Hour/10];
LEDBuf[4]=LEDMAP[Hour%10] ;
LEDBuf[3]=LEDMAP[Minute/10] ;
LEDBuf[2]=LEDMAP[Minute%10] ;
LEDBuf[1]=LEDMAP[Second/10] ;
LEDBuf[0]=LEDMAP[Second%10];
DisplayLED(); //调显示
}
}
此帖出自
小平头技术问答
一周热门 更多>