;***************************************
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