智能时钟 - 图文

更新时间:2023-10-24 09:21:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

关键字: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_led equ 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.

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

;***************************flash bit jb fl_250ms,led_al_end acall jj_bit jnz led_al_e mov led4,#blk_led mov led5,#blk_led sjmp led_al_end led_al_e:

mov led2,#blk_led mov led3,#blk_led led_al_end: acall led

ret

;*************************************** proc set_clock set_clock: mov k1_data,#01d mov k2_data,#01d clr set_over call led_cl call key_bord call sf_key mov key_data,#0 mov frist,#0 set_al41: call clock acall week_auto call al_out acall led_cl acall key_bord call key_del acall key_cl

jnb set_over,set_al41 ;acall key_bord clr a mov k1_data,a mov k2_data,a mov key_data,a mov frist,a ret end

;************************************** proc key_cl key_cl: mov a,key_data jz key_al_end cjne a,#01d,k2_al inc k1_data ;(1-8) mov a,k1_data

cjne a,#9d,key_al_end mov k1_data,#01d sjmp key_al_end k2_al: mov a,k1_data cjne a,#08d,ke2

setb set_over sjmp key_al_end ke2: dec a

mov dptr,#asc_h movc a,@a+dptr mov b,a

;******************************** mov r0,#sec mov a,k1_data dec a add a,r0 mov r0,a inc @r0 mov a,@r0 div ab mov a,b mov @r0,a key_al_end: ret end asc_h:

db 60d,60d,24d,32d,13d,100d,100d proc led_cl led_cl:

mov dptr,#led_ord_3 mov a,k1_data dec a 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 ajmp led_k5_2 ajmp led_k6_2 ajmp led_k7_2

led_k0_2: ; led sec mov led2,#blk_led mov led3,#dot_led

mov a,sec acall bcd_8 add a,#10d mov led4,a mov led5,b jb fl_250ms ,lk1 mov led4,#blk_led mov led5,#blk_led lk1:

ajmp led_jmp_5_end led_k1_2: ; led min,hour acall led_hour jb fl_250ms ,lk2 mov led4,#blk_led mov led5,#blk_led lk2:

ajmp led_jmp_5_end led_k2_2: ;led min,hour acall led_hour jb fl_250ms ,lk3 mov led2,#blk_led mov led3,#blk_led lk3:

ajmp led_jmp_5_end led_k3_2: ;led day,mon acall led_mon jb fl_250ms ,lk4 mov led4,#blk_led mov led5,#blk_led lk4:

ajmp led_jmp_5_end led_k4_2: ; led day,mon acall led_mon jb fl_250ms ,lk5 mov led2,#blk_led mov led3,#blk_led lk5:

ajmp led_jmp_5_end led_k5_2: ; led year mov led2,#2d mov led3,#0d mov a,year acall bcd_8 mov led4,a

mov led5,b jb fl_250ms ,lk6 mov led4,#blk_led mov led5,#blk_led lk6:

ajmp led_jmp_5_end led_k6_2: ;led w_adj mov led2,#d_led mov led3,#blk_led mov a,w_adj acall bcd_8 mov led4,a mov led5,b jb fl_250ms ,lk7 mov led4,#blk_led mov led5,#blk_led lk7:

ajmp led_jmp_5_end led_k7_2: ;led out acall led_out1 led_jmp_5_end: mov led1,week acall led ret end led_hour: mov a,hour acall bcd_8 mov led2,a jnz lj1

mov led2,#blk_led lj1: mov a,b add a,#10d mov led3,a

;********************* mov a,min acall bcd_8 add a,#10d mov led4,a mov led5,b ret led_mon:

mov a,mon jnz lj5 inc mon mov a,mon lj5: acall bcd_8 mov led2,a jnz lj2

mov led2,#blk_led lj2: mov led3,b

;********************* mov a,day jnz lj4 inc day mov a,day lj4: acall bcd_8 mov led4,a jnz lj3

mov led4,#blk_led lj3: mov led5,b ret

;******************************************** al_out:

jb ha_over,al_out_end mov r7,#8d mov r1,#al8_m al_ch_1: mov r0,#min

mov r6,#02d ;min hour al_l: mov a,@r0 mov b,@r1 cjne a,b ,al_ch inc r0 dec r1

djnz r6 ,al_l

;************************************************** mov a,r7 dec a mov r0,#al1 add a,r0

mov r0,a mov a,@r0 mov c,acc.0 cpl c

anl c,fl_250ms cpl c mov beep_f,c acall beep_out al_ch: clr c mov a,r1 subb a,r6 mov r1,a djnz r7,al_ch_1 al_out_end: ret beep_out: jb ha_f,ba1 mov beep,sec setb ha_f ba1: mov a,beep add a,beep_t mov b,#60d div ab mov a,sec

cjne a,b,beep_out_end setb beep_f setb ha_over clr ha_f beep_out_end: ret timer_int:

MOV T_1S,#TIMER_no mov beep_t,#15d mov year ,#01d mov mon , #011d mov day , #06d mov hour ,#13d mov min , #00d mov sec , #00d mov r7,#16 mov dptr ,#al_asc

mov r0,#al1_h al_read: clr a

movc a,@a+dptr mov @r0,a inc r0 inc dptr djnz r7,al_read ret

;************************************ beep_timer: mov led1,#blk_led mov led2,#b_led mov led3,#blk_led mov a,beep_t acall bcd_8 mov led4,a mov led5,b jb fl_250ms,ft1 mov led4,#blk_led mov led5,#blk_led ft1: ret time_12:

mov dptr,#asc_12 mov a,hour rl a

movc a,@a+dptr mov led2,a jnz iu2

mov led2,#blk_led iu2: inc dptr mov a,hour rl a

movc a,@a+dptr jb fl_500ms ,iu1 add a,#10d iu1: mov led3,a

;*************************************** min to led acall led_min

本文来源:https://www.bwwdw.com/article/i1c2.html

Top