多功能AT89C2051倒计时器,AT89C2051 timer
关键字:多功能AT89C2051倒计时器
;************************************** proc key_3 key_3:
mov dptr,#led_ord_3 mov a,key_power ;data mov b,#02h mul ab jmp @a+dptr
led_ord_3: ajmp led_k0_2 ajmp led_k2_2 ajmp led_k1_2 ajmp led_k4_2 ajmp led_k3_2 ajmp led_k6_2 ajmp led_k5_2 ajmp led_k7_2
led_k0_2: ; nop
ajmp led_jmp_5_end
led_k1_2: ; al1 way off/on
cpl al1_f jb flash_f ,tw_11
sjmp tw_21 tw_11: mov c,al1_f mov a,flash mov acc.1 ,c mov flash,a
tw_21: ajmp led_jmp_5_end
led_k2_2: ;al1 timer
jb flash_f ,set_11 inc al1_min_t mov a,al1_min_t cjne a,#60 ,set_12 mov al1_min_t,#00h set_12: sjmp set_14
set_11: inc al1_min mov a,al1_min cjne a,#60 ,set_14 mov al1_min,#00h set_14:
ajmp led_jmp_5_end
led_k3_2: ;al2 way off/on
cpl al2_f jb flash_f ,tw_12 sjmp tw_22 tw_12: mov c,al2_f mov a,flash mov acc.2 ,c mov flash,a
tw_22: ajmp led_jmp_5_end
led_k4_2: ;al2 timer
jb flash_f ,set_21 inc al2_min_t mov a,al2_min_t cjne a,#60 ,set_22 mov al2_min_t,#00h set_22: sjmp set_24
set_21: inc al2_min mov a,al2_min cjne a,#60 ,set_24 mov al2_min,#00h set_24:
ajmp led_jmp_5_end
led_k5_2: ; al3 way off/on
cpl al3_f jb flash_f ,tw_13 sjmp tw_23 tw_13: mov c,al3_f mov a,flash mov acc.3 ,c mov flash,a
tw_23: ajmp led_jmp_5_end
led_k6_2: ;al3 timer jb flash_f ,set_31 inc al3_min_t mov a,al3_min_t cjne a,#60 ,set_32 mov al3_min_t,#00h set_32: sjmp set_34
set_31: inc al3_min mov a,al3_min cjne a,#60 ,set_34 mov al3_min,#00h set_34: ajmp led_jmp_5_end
led_k7_2: ; turn off/on setb turn_f
led_jmp_5_end: ret end ;**************************************** proc key_2 key_2:
mov dptr,#led_ord_3 mov a,key_power ;data mov b,#02h mul ab jmp @a+dptr
led_ord_3: ajmp led_k0_2 ajmp led_k2_2 ajmp led_k1_2 ajmp led_k4_2 ajmp led_k3_2 ajmp led_k6_2 ajmp led_k5_2 ajmp led_k7_2
led_k0_2: ; nop
ajmp led_jmp_5_end
led_k1_2: ; al1 way off/on
ajmp led_jmp_5_end
led_k2_2: ;al1 timer jb flash_f ,set_311 inc al1_hour_t mov a,al1_hour_t cjne a,#20d ,set_321 mov al1_hour_t,#00h set_321: sjmp set_341
set_311: inc al1_hour mov a,al1_hour cjne a,#20d ,set_341 mov al1_hour,#00h set_341:
ajmp led_jmp_5_end
led_k3_2: ;al2 way off/on ajmp led_jmp_5_end
led_k4_2: ;al2 timer jb flash_f ,set_312 inc al2_hour_t mov a,al2_hour_t cjne a,#20d ,set_322 mov al2_hour_t,#00h set_322: sjmp set_342
set_312: inc al2_hour mov a,al2_hour cjne a,#20d ,set_342 mov al2_hour,#00h set_342:
ajmp led_jmp_5_end
led_k5_2: ; al3 way off/on ajmp led_jmp_5_end
led_k6_2: ;al3 timer jb flash_f ,set_313 inc al3_hour_t mov a,al3_hour_t cjne a,#20d ,set_323 mov al3_hour_t,#00h set_323: sjmp set_343
set_313: inc al3_hour mov a,al3_hour cjne a,#20d ,set_343 mov al3_hour,#00h set_343:
ajmp led_jmp_5_end
led_k7_2: ; turn off/on
led_jmp_5_end: ret end
;******************************************** led proc led_jmp_1 led_jmp_1:
mov dptr,#led_ord_3 mov a,key_power ;data mov b,#02h mul ab jmp @a+dptr
led_ord_3: ajmp led_k0_2 ajmp led_k2_2 ajmp led_k1_2 ajmp led_k4_2 ajmp led_k3_2 ajmp led_k6_2 ajmp led_k5_2 ajmp led_k7_2
led_k0_2: ; nop
setb flash_f mov a,#89d mov r7,#18d acall timer_led1 clr flash_f ajmp led_jmp_5_end
led_k1_2: ; al1 way off/on
mov led1 ,#0bh
jnb al1_f,aal_1
mov a,#0ch mov led1,a aal_1: mov led3,#1d mov led2,#led_blk
ajmp led_jmp_5_end
led_k2_2: ;al1 timer
jb flash_f ,led_m11 mov a,al1_min_t mov r7,al1_hour_t sjmp led_m21 led_m11: mov a,al1_min mov r7,al1_hour led_m21: acall timer_led1 ajmp led_jmp_5_end
led_k3_2: ;al2 way off/on mov led1 ,#0bh
jnb al2_f,aal_2
mov a,#0ch mov led1 ,a
aal_2: mov led3,#2d mov led2,#led_blk
ajmp led_jmp_5_end
led_k4_2: ;al2 timer
jb flash_f ,led_m12 mov a,al2_min_t mov r7,al2_hour_t sjmp led_m22 led_m12: mov a,al2_min mov r7,al2_hour led_m22: acall timer_led1
ajmp led_jmp_5_end
led_k5_2: ; al3 way off/on
mov led1 ,#0bh
jnb al3_f,aal_3
mov a,#0ch mov led1 ,a
aal_3: mov led3,#3d mov led2,#led_blk ajmp led_jmp_5_end
led_k6_2: ;al3 timer
jb flash_f ,led_m13 mov a,al3_min_t mov r7,al3_hour_t sjmp led_m23 led_m13: mov a,al3_min mov r7,al3_hour led_m23: acall timer_led1 ajmp led_jmp_5_end
led_k7_2: ; turn off/on mov led3,#00h mov led2,#0bh;led_b mov led1,#0bh;led_b
led_jmp_5_end: acall led ret end
timer_led1:
;*******************************min to led MOV B,#10D DIV AB mov led2,a mov a,b mov led1,a ;*******************************hour to led mov a,r7 MOV B,#10D DIV AB mov r1,a mov a,b mov b,r1 mov r1,a
jnz tt_2
tt_1: mov a,#led_blk tt_2: mov led3,a clr all_s
mov a,b jz tt_3 setb all_s mov led3 ,r1 tt_3: ret
;******************** ; LED_PROGRAM ;*******************
LED:
mov c,flash_f jnc ffl_1 mov c,timer_50ms jc ffl_1
;mov led1,#led_blk ;mov led2,#led_blk ;mov led3,#led_blk ajmp led_end
ffl_1:
mov dptr,#led_asc ;***************************led1 mov a,led1 movc a,@a+dptr mov c, timer_50ms mov acc.0,c
mov p1,a
clr led_1
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 c,all_s mov acc.0 ,c
mov p1,a
clr led_3 acall timer_1ms setb led_3 ;************************* led_end: mov p1,#0ffh mov a,p3 orl a,#11111000b mov p3,a
ret
led_asc: db 11101110B;0 "bafgecdh" db 10000100B;1 db 11011010B;2 db 11010110B;3 db 10110100B;4 db 01110110B;5 db 01111110B;6 db 11000100B;7 db 11111110B;8 db 11110110B;9 DB 00000000B;BLACK=>0aH DB 01111000B;f=>b dB 11101100B;e=>C DB 00110000B;1,=>D
;********************************** ;delay ;********************************
timer_1ms: push b mov r2,#01h a_1: mov b,#020h b_1: djnz b,b_1 djnz r2,a_1 pop b ret
;****************** ; TO-T1_INT T1定时器完成100毫秒定时(6M晶振) ;******************
T1: setb tr0 PUSH ACC ;程序参数保护 PUSH b ; push psw
inc time_led1 mov a,time_led1 cjne a,#5d,t1_n1;判断time_led1中是否满5? mov time_led1,#00h cpl timer_50ms;满50毫秒后对50毫秒标志位取反
; mov a,timers ; cjne a,#10d ,t1_n11;判断timers中是否满10? ;t1_n12: ; clr timer_1s;满1秒后对1秒标志位取反
sjmp t1_n1 ;********************************* t1_end_2: ajmp t1_end_1 ;********************************
;t1_n11: jc t1_n12 ; setb timer_1s
t1_n1: djnz timers ,t1_end_2 mov timers,#tis
inc time_led3 mov a,time_led3 cjne a,#03d,t1_sec mov time_led3,#00h cpl timer_3s t1_sec: inc sec mov a,sec cjne a,#60d ,t1_end mov sec,#00d
jnb al1_f ,t1_al1
mov a,al1_min_t mov b,al1_hour_t mov c ,aal1_f acall al_all mov al1_min_t,a mov al1_hour_t,b mov aal1_f,c
t1_al1: jnb al2_f ,t1_al2 mov a,al2_min_t mov b,al2_hour_t mov c ,aal2_f acall al_all mov al2_min_t,a mov al2_hour_t,b mov aal2_f,c
t1_al2: jnb al3_f ,t1_al3 mov a,al3_min_t mov b,al3_hour_t mov c ,aal3_f acall al_all mov al3_min_t,a mov al3_hour_t,b mov aal3_f,c
t1_al3: T1_END: t1_end_1: ;************************************ sub t0 timer clr c clr tr0 mov b,timer_no mov a,#til add a,tl0
addc a,b ;*******have 5 order mov tl1 ,a
mov a,#tih addc a, th0 mov th1,a mov th0,#00h mov tl0,#00h setb tr1 pop psw pop b ; pop acc ; RETI ;
;************************************ beep: clr ha
mov r6,#060h bee_2: mov r4,#0ffh bee_1: djnz r4 ,bee_1 djnz r6,bee_2 setb ha ret ;*************************************** stop: mov a,#0ffh mov p1,a mov p3,a
mov a,pcon orl a,#00000010b mov pcon,a ret
al_out_way:
jnb aal1_f ,al_out1
mov r3,#0ffh pnp_3: mov b,#060h
pnp_4: push b
acall led_jmp_1;led_times
mov c,timer_50ms mov ha ,c pop b djnz b ,pnp_4 djnz r3 ,pnp_3
mov c,al2_f orl c,al3_f jc al_out54 acall stop
al_out54: clr aal1_f clr al1_f sjmp al_out4
al_out1: jnb aal2_f ,al_out2
clr pnp1 mov r3,#0ffh pnp_1: mov b,#020h
pnp_2: push b
acall led_jmp_1;led_times pop b djnz b ,pnp_2 djnz r3 ,pnp_1
setb pnp1
mov c,al1_f orl c,al3_f jc al_out64 acall stop
al_out64: clr aal2_f clr al2_f sjmp al_out4
al_out2: jnb aal3_f ,al_out3 clr pnp2
al_out3: jnb turn_f ,al_out4 acall stop al_out4: ret ;******************************************* al_all: jc al_all_1 dec a jnz al_all_1 mov a,b jz al_all_3 dec b sjmp al_all_2
al_all_3: setb c sjmp al_all_1
al_all_2: mov a,#60d al_all_1:
ret
;看懂别人写的汇编程序是很困难的事情,我希望有兴趣的网友能帮我完成这段程序的中文注释,这样可以使初学者能够更加容易学会编程.
这是上面程序汇编以后获得的编程器烧写文件:倒计时.rar
|