标题:
超级省电的时钟制作 最省电时可达3mA [修正BUG]
[打印本页]
作者:
51hei丽人
时间:
2016-6-21 01:00
标题:
超级省电的时钟制作 最省电时可达3mA [修正BUG]
最近终于有时间发图片了:
样子:
显示月份:
省电模式:
背面走线图
数码管底部暗藏IC:
/***********************************************************************
作者:TZR
版本:CK3148 (ver2.0)
功能: 1 显示时间
2 显示日期
3 计算年份
4 闹钟功能
5 超小体积设计(电池最大……)
6 整点报时
7(重点改进点)超省电设计,正常工作电流在9~12mA之间,最省电时电流可达3mA!闹钟鸣响时电流在15mA~18mA左右。
8.增加省电模式,模式下耗电<3.3mA,数码管不显示,走时仍然继续,闹钟,整点报时仍然运行。(闹钟会中断省电模式)
日志:V1:实现走时功能,程序整体不稳定,闹钟和整点报时功能不正常。
V1.2:修正闹钟和整点报时BUG,修正出现“0月0日的”BUG,修正年份显
V2:改进了程序,作品变得相当省电,耗电量相比之前下降一半,最省电时可达3mA.
V2.2:增加省电模式。修正程序稳定性差,整点报时不兼容“省电模式”的问题。
省电原理:LED显示屏低频闪烁,闪烁期间单片机进入空闲模式,使用定时器中断唤醒单片机,并产生时钟。
***************************************************************************/
#include <stc12c2052ad.h>
unsigned char hour;
unsigned char min;
unsigned char sec;
unsigned char st;
unsigned char t;
unsigned char alh;
unsigned char alm;
unsigned char yearH;
unsigned char yearL;
unsigned char month;
unsigned char beepc;
unsigned char day;
unsigned char mo;
unsigned bm[12]={1,0,1,0,1,0,1,1,0,1,0,1};
bit am;
sbit mode=P1^7;
sbit chan=P1^6;
sbit beep=P3^7;
sbit v4=P1^5;
sbit c=P1^4;
sbit b=P1^3;
sbit v3=P1^2;
sbit v2=P1^1;
sbit d=P1^0;
sbit e=P3^0;
sbit f=P3^1;
sbit h=P3^2;
sbit g=P3^3;
sbit a=P3^4;
sbit v1=P3^5;
#define close v1=0;v2=0;v3=0;v4=0;
#define led0 a=1;b=1;c=1;d=1;e=1;f=1;g=1;h=1;
#define num0 a=1;b=0;c=0;d=0;e=0;f=0;g=0;
#define num1 a=1;b=1;c=1;e=1;f=1;d=0;g=0;
#define num2 f=0;e=0;d=0;c=0;a=0;
#define num3 g=0;f=0;d=0;c=0;a=0;
#define num4 g=0;d=0;b=0;a=0;
#define num5 g=0;f=0;c=0;b=0;a=0;
#define num6 c=0;b=0;e=0;f=0;g=0;a=0;
#define num7 c=0;d=0;g=0;
#define num8 a=0;b=0;c=0;d=0;e=0;f=0;g=0;
#define num9 a=0;b=0;c=0;d=0;f=0;g=0;
//CLKS0=1;
void delay (unsigned int a){
unsigned int i;
while(--a >= 0){
for(i = 0; i < 300; i++);
}
}
void paint(unsigned char i){
if(i==0){num0;}
if(i==1){num1;}
if(i==2){num2;}
if(i==3){num3;}
if(i==4){num4;}
if(i==5){num5;}
if(i==6){num6;}
if(i==7){num7;}
if(i==8){num8;}
if(i==9){num9;}
}
void main (void){
P3M0=0x00;
P3M1=0x80;
mode=0;
beep=0;
beepc=0;
chan=0;
mo=0;
EA=1;
ET0=1;
st=0;
close;
led0;
hour=11;
min=59;
alh=12;
alm=00;
sec=59;
TH0=0x00;
TL0=0x00;
TR0=1;
t=1;
am=1;
yearH=20;
yearL=11;
month=4;
day=23;
while(1){
if(mo==0){
if(mode==1){
delay(20);
if(mode==1){
mo++;
}
while(mode==1);
}
if(chan==1){
delay(20);
if(chan==1){
beep=0;
beepc=0;
while(chan==1);
}
}
if(sec%10==8 || sec%10==9){
led0;
paint(day%10);//0001
close;
v1=1;
delay(t);
led0;
paint(day/10);//0010
close;
v2=1;
delay(t);
led0;
paint(month%10);//0100
h=0;
close;
v3=1;
delay(t);
led0;
paint(month/10);//1000
close;
v4=1;
delay(t);
}else{
led0;
paint(min%10);//0001
close;
v1=1;
delay(t);
led0;
paint(min/10);//0010
close;
v2=1;
delay(t);
led0;
paint(hour%10);//0100
h=sec%2;
close;
v3=1;
delay(t);
led0;
paint(hour/10);//1000
close;
v4=1;
delay(t);
}
}else if(mo==1){
if(st<50){
led0;
paint(hour/10);//1000
close;
v4=1;
delay(t);
}
if(chan==1){
delay(20);
if(chan==1){
hour+=10;
if(hour>23){
hour=0;
}
while(chan==1);
}
}
if(mode==1){
delay(20);
if(mode==1){
mo++;
}
while(mode==1);
}
}else if(mo==2){
if(st<50){
led0;
paint(hour%10);//1000
close;
v3=1;
delay(t);
}
if(chan==1){
delay(20);
if(chan==1){
hour+=1;
if(hour%10==0){
hour-=10;
}
while(chan==1);
}
}
if(mode==1){
delay(20);
if(mode==1){
mo++;
}
while(mode==1);
}
}else if(mo==3){
if(st<50){
led0;
paint(min/10);//1000
close;
v2=1;
delay(t);
}
if(chan==1){
delay(20);
if(chan==1){
min+=10;
if(min>59){
min=0;
}
while(chan==1);
}
}
if(mode==1){
delay(20);
if(mode==1){
mo++;
}
while(mode==1);
}
}else if(mo==4){
if(st<50){
led0;
paint(min%10);//1000
close;
v1=1;
delay(t);
}
if(chan==1){
delay(20);
if(chan==1){
min+=1;
if(min%10==0){
min-=10;
}
while(chan==1);
}
}
if(mode==1){
delay(20);
if(mode==1){
mo++;
}
while(mode==1);
}
}else if(mo==5){
if(st<50){
led0;
paint(month/10);//1000
close;
v2=1;
delay(t);
led0;
paint(month%10);//1000
close;
v1=1;
delay(t);
}
if(chan==1){
delay(20);
if(chan==1){
month+=1;
if(month==13){
month=1;
}
while(chan==1);
}
}
if(mode==1){
delay(20);
if(mode==1){
mo++;
}
while(mode==1);
}
}else if(mo==6){
if(st<50){
led0;
paint(day/10);//1000
close;
v2=1;
delay(t);
led0;
paint(day%10);//1000
close;
v1=1;
delay(t);
}
if(chan==1){
delay(20);
if(chan==1){
day+=1;
if(day==32){
day=1;
}
while(chan==1);
}
}
if(mode==1){
delay(20);
if(mode==1){
mo++;
}
while(mode==1);
}
}else if(mo==7){
if(st<50){
led0;
paint(yearL%10);//0001
close;
v1=1;
delay(t);
led0;
paint(yearL/10);//0010
close;
v2=1;
delay(t);
led0;
paint(yearH%10);//0100
h=0;
close;
v3=1;
delay(t);
led0;
paint(yearH/10);//1000
close;
v4=1;
delay(t);
}
if(chan==1){
delay(20);
if(chan==1){
yearL+=1;
if(yearL>=30){
yearL=11;
}
while(chan==1);
}
}
if(mode==1){
delay(20);
if(mode==1){
mo++;
}
while(mode==1);
}
}else if(mo==8){
if(st<50){
led0;
paint(alh/10);//1000
close;
v4=1;
delay(t);
led0;
paint(alh%10);//1000
close;
v3=1;
delay(t);
}
if(chan==1){
delay(20);
if(chan==1){
alh+=1;
if(alh>23){
alh=0;
}
while(chan==1);
}
}
if(mode==1){
delay(20);
if(mode==1){
mo++;
}
while(mode==1);
}
}else if(mo==9){
if(st<50){
led0;
paint(alm/10);//1000
close;
v2=1;
delay(t);
led0;
paint(alm%10);//1000
close;
v1=1;
delay(t);
}
if(chan==1){
delay(20);
if(chan==1){
alm+=1;
am=1;
if(alm>=60){
alm=0;
}
while(chan==1);
}
}
if(mode==1){
delay(20);
if(mode==1){
mo=0;
}
while(mode==1);
}
}
}
}
void t0 (void) interrupt 1 {
st++;
if(st>99){
st=0;
sec++;
if(beep==1){
beepc--;
if(beepc<=0){
beep=0;
}
}
}
if(sec>59){
sec=0;
min++;
if(min==alm && hour==alh && am==1){
beep=1;
beepc=50;
}
}
if(min>59){
min=0;
hour++;
beep=1;//整点报时
beepc=1;
}
if(hour>23){
hour=0;
day++;
if(month==2){
if(yearL%4==0){
if(day==30){
day=0;
month++;
}
}else{
if(day==29){
day=0;
month++;
}
}
}else if(bm[month]==0){
if(day==31){
day=0;
month++;
if(month==13){
month=1;
yearL++;
}
}
}else if(bm[month]==1){
if(day==32){
day=0;
month++;
if(month==13){
month=1;
yearL++;
}
}
}
}
TH0=0x6c;/*7a9c*/
TL0=0xc2;
}
复制代码
作者:
stxlpeng
时间:
2016-6-22 09:33
能把原理图发上了么
作者:
双赢电子
时间:
2016-8-5 11:53
谢谢分享
作者:
houniao
时间:
2019-7-25 09:44
能把原理图发上了
作者:
jwjjwj123
时间:
2025-3-31 22:36
这个没几个小时就没电了.
作者:
powerdruy
时间:
2025-4-1 13:27
3ma很费电了,省电就不能用数码管,只能用断码液晶
作者:
fj51hei
时间:
2025-4-1 14:02
powerdruy 发表于 2025-4-1 13:27
3ma很费电了,省电就不能用数码管,只能用断码液晶
数码管3mA人家已经很认真了,但对纽扣电池确是电老虎,呵呵!
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1