采用AT89C2051的智能时钟
扫描二维码
随时随地手机看文章
智能电子钟的功能:
1。 全日历计时。
2。 12/24小时转换。
3。 8路定时输出(可关/开控制)
4。 误差:15S+1uS
5。 大、小月,润年,周,自动追踪
二、 调校:
上电后,电子钟显示“1:00”。
1。 8路定时时间查询
按下K1键依此显示8路定时时间。星期位显示:“H”表示:打开当前定时输出;“L” 表示:关闭当前定时输出。此时按K2键可进行“H”、“L”的切换。所有输出,均由蜂鸣器输出!
2。 显示状态的控制
按下K2键可进入以下工作状态:
1)12小时/ 日月交替显示。
2)12小时固定显示。
3)24小时/ 日月交替显示。
4)24小时固定显示。
3。 校时
按下K2键3S后,进入校时菜单。按下K1键依次进入校时状态:分、时、天、月、年、微调系数。此时按K2键,完成+1。当显示“d”时,表示要调整微调系数(0-99),其值越小,时钟走时越慢。当使用的6MHz的晶振偏差大时,应仔细调整微调系数!当显示“out”时,按K2键,即可退出!退出后,按任意键即可启动时钟。
4。 设置定时时间
按下K1键3S后,进入设置菜单。按下K1键依次进入8路定时调整状态:时、分。此时按K2键,完成+1。当显示“out”时,按K2键,即可退出!
;2001.5.24
;***************
;all_clk1 _program 2000-10-12
;***************
fl_250ms bit 00h
fl_500ms bit fl_250ms+1
set_clk_f bit fl_500ms+1
set_al4_f bit set_clk_f+1
am_f bit set_al4_f+1
fl_3s bit am_f+1
al1_f bit fl_3s+1
al2_f bit fl_3s+2
al3_f bit fl_3s+3
al4_f bit fl_3s+4
set_over bit al4_f+1
ha_f bit set_over+1
ha_over bit ha_f+1
fl_ms_f bit ha_over+1
fl_s_f bit fl_ms_f+1
key_over bit fl_s_f+1
;**************************************************
key_data equ 08h
timers equ key_data+1
t_30ms equ timers+1
t_20ms equ t_30ms+1
t_1s equ t_20ms+1
k1_data equ t_1s+1
k2_data equ k1_data+1
stat_work equ k2_data+1
stat_LEDequ stat_work+1
t_1ms equ stat_led+1
t_20m equ t_1ms+1
beep equ t_20m
al1 equ beep+1
al2 equ beep+2
al3 equ beep+3
al4 equ beep+4
al5 equ beep+5
al6 equ beep+6
al7 equ beep+7
al8 equ beep+8
ret_timer equ al8+1
;**************************************************
sec equ 23h
min equ sec+1h
hour equ min+1h
day equ hour+1h
mon equ day+1h
year equ mon+1h
w_adj equ year+1h
week equ w_adj+1h
;***************************************
al1_h equ week+1h
al1_m equ al1_h+1h
al2_h equ al1_m+1h
al2_m equ al2_h+1h
al3_h equ al2_m+1h
al3_m equ al3_h+1h
al4_h equ al3_m+1h
al4_m equ al4_h+1h
al5_h equ al4_m+1h
al5_m equ al5_h+1h
al6_h equ al5_m+1h
al6_m equ al6_h+1h
al7_h equ al6_m+1h
al7_m equ al7_h+1h
al8_h equ al7_m+1h
al8_m equ al8_h+1h
beep_t equ al8_m+1
frist equ beep_t+1
;**************************************
led1 equ frist+1
led2 equ led1+1
led3 equ led2+1
led4 equ led3+1
led5 equ led4+1
sp_data equ led5+1
;**************************************
led_1 bit p3.5
led_2 bit p3.4
led_3 bit p3.3
led_4 bit p3.2
led_5 bit p3.1
beep_f BIT P3.7
key_f bit p3.0
;********************************************************
t_h_100ms equ 05dh ;100 ms for 6MHz
t_l_100ms equ 07fh ;c6 for 100ms
timer_no equ 8d ;3c90+30d=3cb0h
w_adj_dat equ 50d
key_da equ 00000110b
;*********************************************************
blk_led equ 20d
dot_led equ 21d
f_led equ 22d
n_led equ 23d
u_led equ 24d
t_led equ 25d
b_led equ 26d
d_led equ 27d
oRG 0000H; ;
sJMP start
ORG 0003H; ;
reti;
ORG 000BH ;
;ajmp t0
reti ;
ORG 0013H
reti ;
ORG 001BH ;
aJMP T1 ;
ORG 0023H ;
RETI; AJMP RS_485 ;
;**************************************
start:
call clr_ram
MOV SP,#sp_data ;
call int_t0
call timer_int
call timer_20ms
STAR_BI:
call cLOCk
call week_auto
call al_out
CALL KEY_bord
call key_del
call set_clk_al
call key_jmp
call reback
call led_jmp
sjmp star_bi
;*******************************************
reback:
mov a,stat_work
jz reback_end
jb al1_f ,ka1
mov ret_timer,sec
setb al1_f
sjmp reback_end
ka1:
mov a,ret_timer
add a,#05d
mov b,#60d
div ab
mov a,sec
cjne a,b,reback_end
clr al1_f
mov stat_work,#00d
reback_end:
ret
key_jmp:
mov a,key_data
jz key_jmp_end
mov ret_timer,sec
cjne a,#01d,kk1
mov a,stat_work
inc a ;k1_key
cjne a,#9d,kka1
mov a,#00d
kka1:
mov stat_work ,a
sjmp key_jmp_end
kk1:
mov a,stat_work ;k2_key
jnz kk2
mov a,stat_led
inc a
cjne a,#05d,kka2
mov a,#00d
kka2:
mov stat_led,a
sjmp key_jmp_end
kk2:
acall all1
cpl a
mov @r0,a
key_jmp_end:
ret
all1:
mov r0,#al1
mov a,stat_work
dec a
add a,r0
mov r0,a
mov a,@r0
ret
led_jmp:
;**********************************
;mov stat_work,#01d
;mov stat_tw,#01d
mov a,stat_work
jnz led_al1
mov a,stat_led
acall led_t_d
mov led1,week
sjmp led_jmp_end
led_al1:
acall all1
mov led1,#f_led
jnz le_t2
mov led1,#n_led
le_t2:
jb fl_250ms ,le_t4
mov led1,#blk_led
le_t4:
acall al_led
led_jmp_end:
acall led
ret
;*************************************
time_24:
mov a,hour
acall bcd_8
mov led2,a
jnz tim4
mov led2,#blk_led
tim4:
mov led3,b
jb fl_500ms,tim1
mov a,b
add a,#10d
mov led3,a
tim1:
acall led_min
time_12_end:
ret
;***********************************
led_min:
mov a,min
acall bcd_8
jb fl_500ms ,tim2
add a,#10d
tim2:
mov led4,a
mov led5,b
ret
;*************************************
date_led:
mov a,mon
acall bcd_8
mov led2,a
jnz da1
mov led2,#blk_led
da1:
mov a,b
add a,#10d
mov led3,a
mov a,day
acall bcd_8
mov led4,a
jnz da2
mov led4,#blk_led
da2:
mov led5,b
date_led_end:
ret
;*************
; D_8=>BCD
;*************
BCD_8:
MOV B,#10D
DIV AB
RET
;****************************************
LED:
mov p1,#0
mov dptr,#led_asc
;***************************led1
mov a,led1
movc a,@a+dptr
mov p1,a
clr led_1
acall timer_1ms
acall timer_1ms
;acall timer_1ms
;acall timer_1ms
;acall timer_1ms
setb led_1
;*************************led2
led_led2:
mov a,led2
movc a,@a+dptr
mov p1,a
clr led_2
acall timer_1ms
setb led_2
;*************************led3
led_led3:
mov a,led3
movc a,@a+dptr
mov p1,a
clr led_3
acall timer_1ms
setb led_3
;*************************led4
led_led4:
mov a,led4
movc a,@a+dptr
mov p1,a
clr led_4
acall timer_1ms
setb led_4
;*************************led5
led_led5:
mov a,led5
movc a,@a+dptr
mov p1,a
clr led_5
acall timer_1ms
setb led_5
;*************************
led_end:
mov p1,#0
ret
;************************************
; bafhcdeg
led_asc:
db 11101110B;0
db 10001000B;1
db 11000111B;2
db 11001101B;3
db 10101001B;4
db 01101101B;5
db 01101111B;6
db 11001000B;7
db 11101111B;8
db 11101101B;9
db 11111110B;0. =>10d
db 10011000B;1.
db 11010111B;2.
db 11011101B;3.
db 10111001B;4.
db 01111101B;5.
db 01111111B;6.
db 11011000B;7.
db 11111111B;8.
db 11111101B;9.
DB 00000000B;BLACK=>20d
DB 00010000B;dot=>21d
DB 00100110b;l=>22d
dB 10101011B;h=>23d
DB 10101110B;u=>24d
DB 00100111B;t=>25d
dB 00101111B;b=>26d
dB 10001111B;d=>27d
; bafhcdeg
;**********************************
;delay
;********************************
timer_1ms:
mov t_1ms,#030h
r2_1:
djnz t_1ms , r2_1
ret
timer_20ms:
mov t_20m,#050d
r2_2:
call clock
call led
djnz t_20m , r2_2
call week_auto
call al_out
ret
;#############################################
;if mon<=2 and year=4Z(0,1,2,3...)
;gs1=>week=mod([5/4]*year+mon_asc(mon)+day-1)/7
;else
; gs2=>week=mod([5/4]*year+mon_asc(mon)+day)/7
week_auto:
mov a,YEAR
mov b,#05
mul ab
mov r4,b
mov r5,a
mov r7,#04
call mul_2
MOV DPTR,#MON_ASC
MOV A,MON
dec a
MOVC A,@A+DPTR
ADD A,r3
;*********************
MOV B,DAY
ADD A,B
mov r3,a;r3=gs2
;*******jb mon<=2 ******
MOV A,MON
CJNE A,#02D,WEEK_1
SJMP WEEK_2
WEEK_1:
JC WEEK_2
week_3:
mov a,r3
mov b,#07
div ab
mov a,b
sjmp week_4
WEEK_2:
;*****jb year=4N ******
mov a,year
mov b,#04
div ab
mov a,b
jnz week_3
mov a,r3
dec a
mov b,#07
div ab
mov a,b
week_4:
MOV WEEK,a
jnz week_end
mov week,#07h
week_end:
RET
MON_ASC:
DB 6d, 2d, 2d, 5d, 0d, 3d, 5d, 1d, 4d, 6d, 2d, 4d ;2002.5.5
;r4r5/r7=r3
mul_2:
D457: CLR C
MOV A,R4
SUBB A,R7
JC DV50
SETB OV
RET
DV50: MOV R6,#8 ;;求平均值(R4R5/R7-→R3)
DV51: MOV A,R5
RLC A
MOV R5,A
MOV A,R4
RLC A
MOV R4,A
MOV F0,C
CLR C
SUBB A,R7
ANL C,/F0
JC DV52
MOV R4,A
DV52: CPL C
MOV A,R3
RLC A
MOV R3,A
DJNZ R6,DV51
MOV A,R4 ;;四舍五入
ADD A,#0;R4
JC DV53
SUBB A,R7
JC DV54
DV53: INC R3
DV54: CLR OV
RET
;*************************************************************
clr_ram:
MOV R7,#78h ;
MOV R0,#0bH ;
CLR A ;
CR: INC R0 ;
MOV @R0,A ;
djnz r7,cr ;CLR RAM
ret
;************** INT_CTRL
int_t0:
setb et1
MOV TMOD,#00010001b ;
mov w_adj,#w_adj_dat
setb ea
jmp adj_w
;**********************************************
al_led:
mov r0,#al1_h
mov a,stat_work
dec a
rl a
add a,r0
mov r0,a
mov a,@r0
acall bcd_8
mov led2,a
jnz al_1
mov led2,#blk_led
al_1:
mov a,b
add a,#10d
mov led3,a
inc r0
mov a,@r0
acall bcd_8
add a,#10d
mov led4,a
mov led5,b
al_led_end:
ret
;********************************
set_clk_al:
jnb set_clk_f,see1
call set_clock
clr set_clk_f
sjmp see2
see1:
jnb set_al4_f,see2
call set_al4
clr set_al4_f
see2:
ret
;*********************************
proc led_t_d
led_t_d:
mov dptr,#led_ord_3
mov b,#02h
mul ab
jmp @a+dptr
led_ord_3: ajmp led_k0_2
ajmp led_k1_2
ajmp led_k2_2
ajmp led_k3_2
ajmp led_k4_2
led_k0_2: ; timer_12 and date to led
acall time_12
jnb fl_3s ,lk1
acall date_led
lk1:
ajmp led_jmp_5_end
led_k1_2: ; timer_12 to led
acall time_12
ajmp led_jmp_5_end
led_k2_2: ;timer_24and date to led
acall time_24
jnb fl_3s ,lk2
acall date_led
lk2:
ajmp led_jmp_5_end
led_k3_2: ;timer_24to led
acall time_24
ajmp led_jmp_5_end
led_k4_2: ;sec to led
mov led1,#blk_led
mov led2,#blk_led
mov led3,#dot_led
mov a,sec
acall bcd_8
add a,#10d
mov led4,a
mov led5,b
led_jmp_5_end:
ret
end
;****************************************
proc set_al4
set_al4:
mov k1_data,#01d
mov k2_data,#01d
clr set_over
acall led_al
acall key_bord
call sf_key
mov key_data,#0
mov frist,#0
set_al41:
call clock
call week_auto
acall led_al
acall key_bord
call key_del
acall key_al
jnb set_over,set_al41
clr a
mov k1_data,a
mov k2_data,a
mov key_data,a
mov frist,a
ret
end
;**************************************
proc key_al
key_al:
mov a,key_data
jz key_al_end
cjne a,#01d,k2_al
inc k1_data ;(1-9)
mov a,k1_data
cjne a,#19d,key_al_end
mov k1_data,#01d
sjmp key_al_end
k2_al:
mov a,k1_data
cjne a,#018d,ke2
setb set_over
sjmp key_al_end
ke2:
mov r0,#al1_h
dec a
add a,r0
mov r0,a
inc @r0
acall jj_bit
mov b,#24d
jnz ke3
mov b,#60d
ke3:
mov a,@r0
div ab
mov a,b
mov @r0,a
key_al_end:
ret
end
jj_bit:
mov a,k1_data
mov b,#02d
div ab
mov a,b ;(a=1,0)
ret
;*********************************
led_out1:
mov led2,#00h
mov led3,#u_led
mov led4,#t_led
mov led5,#blk_led
mov led1,#blk_led
ret
;********************************
led_al:
mov a,k1_data
cjne a,#017d,lo1
acall beep_timer
sjmp led_al_end
lo1:
cjne a,#18d,ld1
acall led_out1
sjmp led_al_end
ld1:
inc a
mov b,#02d
div ab
;**********
mov led1,a
;**********
dec a
rl a
mov r0,#al1_h
add a,r0
mov r0,a
mov a,@r0
acall bcd_8
mov led2,a
jnz ld2
mov led2,#blk_led
ld2:
mov a,b
add a,#10d
mov led3,a
;************************************
inc r0
mov a,@r0
acall bcd_8
add a,#10d
mov led4,a
mov led5,b