标题:
CK3148电子钟源程序 修正BUG
[打印本页]
作者:
51hei丽人
时间:
2016-6-21 01:01
标题:
CK3148电子钟源程序 修正BUG
哈哈,最近又做了一个程序,这已经是我制造的第三个电子钟了,不知道我为什么这么喜欢电子钟?
图片和升级版的程序详见:
http://www.51hei.com/bbs/dpj-52307-1.html
/***********************************************************************
作者:TZR
版本:CK3148 (ver1.2)
功能: 1显示时间
2显示日期
3计算年份
4闹钟功能
5超小体积设计(电池最大……)
6整点报时
日志:V1:实现走时功能,程序整体不稳定,闹钟和整点报时功能不正常。
V1.2:修正闹钟和整点报时BUG,修正出现“0月0日的”BUG,修正年份显示错误的问题。
***************************************************************************/
#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;
}
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1