电子制作天地网站欢迎您的光临,欢迎提出宝贵意见或建议。本站信息产业部备案: 粤ICP备05114582号
采用AT89C2051的智能时钟
AT90C2051 DIGITAL CLOCK

时间:2008-1-17 22:39:21 来源:网络 作者:未知 编辑: 【关闭


采用AT89C2051的智能时钟,AT90C2051 DIGITAL CLOCK

关键字:AT89C2051的智能时钟制作


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
;********************************* 部分程序见下一页面


◆相关文章◆
◆ 编辑推荐 ◆
用户:
更多评论
您要为您所发的言论的后果负责,故请各位遵纪守法并注意语言文明。60个字以内
留言:
验证码:

免责声明:
●本站所有内容均来自网络,以学习为目的,如果侵犯了您的利益,请来信告知,立即删除,站长邮件为"diy+dzdiy.com",请将"+"变更为"@"
●电子制作存在风险,请注意人身安全,如果您在根据本站电路进行制作过程中发生伤害,本站不负任何责任。

版权所有:www.dzdiy.com ? 2001-2019 本站信息产业部备案: 粤ICP备05114582号