金牌会员
- 积分
- 1115
- 金钱
- 1115
- 注册时间
- 2011-10-19
- 在线时间
- 256 小时
|
楼主 |
发表于 2013-6-7 10:46:06
|
显示全部楼层
今天出炉的:SMG精准时钟(24小时制),三键实现时间调整,并带位闪特效:
#include "reg52.h"
#define uchar unsigned char
#define uint unsigned int
#define DM  0
#define WM  2
uchar code SMG_DM[]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code SMG_WM[]={0x00,0x20,0x40,0x60,0x80,0xA0};
sbit K1=P3^2;
sbit K2=P1^1;
sbit K3=P3^4;
sbit BEEP=P3^5;
uchar cnt=0;
bit sec_flg=0; // 0:1秒未到。
char sec,min,hour; // 时,分,秒。
uchar dis[6];
uchar status=0; // 初态:禁止调时。
bit ss_flag = 0;
//-------------------------------------------------
void delay(uint t)
{
while(t--);
}
//==================================================
void T0_init()
{
TMOD=0x01;
TH0=0x3C;
TL0=0xB0;
EA=1;
ET0=1;ET1=1;
TR0=1;TR1=1;
 T1=1;
}
//==============================================================================================
void main()
{
T0_init();
RD=0;
// D1=0,D2=1;
while(1)
{
if((sec_flg)&&(status==0))
{
sec_flg=0;
sec++;
if(sec>59) sec=0,min++;
if(min>59) min=0,hour++;
if(hour>23) hour=0;
}
dis[0]=sec%10;
dis[1]=sec/10;
dis[2]=min%10;
dis[3]=min/10;
dis[4]=hour%10;
dis[5]=hour/10;
if(status!=0)
{
if(!K1)
{
while(!K1);
BEEP=0,delay(1000),BEEP=1;
switch(status)
{
case 1: hour++;
if(hour>23)
hour=0;
break;
case 2: min++;
if(min>59)
min=0;
break;
case 3: sec++;
if(sec>59)
sec=0;
break;
default: break;
}
}
if(!K2)
{
while(!K2);
BEEP=0,delay(1000),BEEP=1;
switch(status)
{
case 1: hour--;
if(hour<0)
hour=23;
break;
case 2: min--;
if(min<0)
min=59;
break;
case 3: sec--;
if(sec<0)
sec=59;
break;
default: break;
}
}
}
if(!K3)
{
while(!K3);
BEEP=0,delay(1000),BEEP=1;
status++;
if(status>3)
status=0;
}
}
}
//===============================================================================================
void T0_isr(void) interrupt 1
{
TH0=0x3C;
TL0=0xB0;
cnt++;
if(cnt>=20)
{
cnt=0;
sec_flg=1;
}
}
//----------------------------------------------------------------------------------------------
void T1_isr(void) interrupt 3
{
static uchar counter;
uint ct;
TH1=0xFC;
TL1=0x18;
ct++;
if(ct>3000)
{
ct=0;
ss_flag=!ss_flag;
}
if(status!=0)
{
switch(counter)
{
case 5:
if(status==1)
{
if(ss_flag)
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[5]; DM=SMG_DM[dis[5]];
}
else
{
DM=0xFF;WM=(WM&0x1F)|SMG_WM[5];DM=0xFF;
}
}
else
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[5]; DM=SMG_DM[dis[5]];
}
break;
case 4:
if(status==1)
{
if(ss_flag)
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[4]; DM=SMG_DM[dis[4]]&0x7F;
}
else
{
DM=0xFF;WM=(WM&0x1F)|SMG_WM[4];DM=0xFF;
}
}
else
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[4]; DM=SMG_DM[dis[4]]&0x7F;
}
break;
case 3:
if(status==2)
{
if(ss_flag)
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[3]; DM=SMG_DM[dis[3]];
}
else
{
DM=0xFF;WM=(WM&0x1F)|SMG_WM[3];DM=0xFF;
}
}
else
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[3];DM=SMG_DM[dis[3]];
}
break;
case 2:
if(status==2)
{
if(ss_flag)
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[2]; DM=SMG_DM[dis[2]]&0x7F;
}
else
{
DM=0xFF;WM=(WM&0x1F)|SMG_WM[2];DM=0xFF;
}
}
else
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[2]; DM=SMG_DM[dis[2]]&0x7F;
}
break;
case 1:
if(status==3)
{
if(ss_flag)
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[1]; DM=SMG_DM[dis[1]];
}
else
{
DM=0xFF;WM=(WM&0x1F)|SMG_WM[1];DM=0xFF;
}
}
else
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[1]; DM=SMG_DM[dis[1]];
}
break;
case 0:
if(status==3)
{
if(ss_flag)
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[0];DM=SMG_DM[dis[0]];
}
else
{
DM=0xFF;WM=(WM&0x1F)|SMG_WM[0];DM=0xFF;
}
}
else
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[0];DM=SMG_DM[dis[0]];
}
break;
default: break;
}
}
else
{
if((counter==2)||(counter==4))
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[counter];DM=SMG_DM[dis[counter]]&0x7F;
}
else
{
DM=0xFF; WM=(WM&0x1F)|SMG_WM[counter];DM=SMG_DM[dis[counter]];
}
}
counter++;
if(counter>5)
counter=0;
} |
|