;*******ZLG7289 PARAMETERS*******
ZLG_BIT_CNT EQU 30H ;The number of data sended
ZLG_REC_BUF EQU 31H ;The buffer of data received
ZLG_SEND_BUF EQU 32H ;The buffer of data sended
SECOND EQU 33H
MINUTE EQU 34H
HOUR EQU 35H
CURR_SECOND EQU 36H
CURR_MINUTE EQU 37H
CURR_HOUR EQU 38H
VAR_TIMER EQU 39H
SELECTION EQU 3AH
SETTING_FLAG EQU 00H
ZLG_CS EQU P0.0 ;/CS of ZLG7289
ZLG_CLK EQU P0.1 ;CLK of ZLG7289
ZLG_DATA EQU P0.2 ;DIO of ZLG7289
ZLG_KEY EQU P0.3 ;/KEY of ZLG7289
;*******DELAY PARAMETERS*******
VAR_DELAY EQU 71H ;The variable for delay function
org 0000H
ljmp MAIN
org 000BH
ljmp int_TIMER ;Interrupt for Timer
org 0030H
MAIN:
mov SECOND,#00 ;Initialize the value
mov MINUTE,#30
mov HOUR,#23
mov VAR_TIMER,#00H
clr SETTING_FLAG ;Not setting
mov TMOD,#01H
mov TH0,#0B1H ;20ms,load number
mov TL0,#0E0H
setb TR0 ;Start T0
setb ET0 ;Enable T0 inerrupt
setb EA ;Enable interrupt
setb ZLG_CS
setb ZLG_KEY
setb ZLG_DATA
lcall delay_50
mov ZLG_SEND_BUF,#10100100B ;Initialize ZLG7289
lcall zlg_send
setb ZLG_CS ;Set standby mode
MAIN_LOOP:
jb ZLG_KEY,$ ;Wait for keyboard
mov ZLG_SEND_BUF,#00010101B ;Send the command of reading keyboard
lcall zlg_send
lcall zlg_receive ;Read the data of keyboard
setb ZLG_CS ;Set standby mode
jnb ZLG_KEY,$ ;Wait the key to pop
mov a,ZLG_REC_BUF
cjne a,#15,MAIN_LOOP
lcall SET_TIME
ajmp MAIN_LOOP
ret ;main return
;*****************************************************************
int_TIMER:
push acc ;Pay attention to here
push psw
;Reset T0,must be done
mov TH0,#0B1H ;20ms,reload number
mov TL0,#0E0H
inc VAR_TIMER ;Add 20ms
mov a,VAR_TIMER
cjne a,#50,INT_TIMER_EXIT
mov VAR_TIMER,#00H
lcall TIME_ADD
jb SETTING_FLAG,INT_TIMER_EXIT
lcall DISPLAY_TIME
INT_TIMER_EXIT:
pop psw
pop acc
reti
;*****************************************************************
TIME_ADD:
inc SECOND
mov a,SECOND
cjne a,#60,TIME_ADD_EXIT
mov SECOND,#00H
inc MINUTE
mov a,MINUTE
cjne a,#60,TIME_ADD_EXIT
mov MINUTE,#00H
inc HOUR
mov a,HOUR
cjne a,#24,TIME_ADD_EXIT
mov HOUR,#00H
TIME_ADD_EXIT:
ret
;*****************************************************************
DISPLAY_TIME:
mov a,SECOND ;Display second
mov ZLG_SEND_BUF,#10000000B
lcall DISPLAY_NUM
mov ZLG_SEND_BUF,#10000010B ;Display separation
lcall DISPLAY_SEP
mov a,MINUTE ;Display minute
mov ZLG_SEND_BUF,#10000011B
lcall DISPLAY_NUM
mov ZLG_SEND_BUF,#10000101B ;Display separation
lcall DISPLAY_SEP
mov a,HOUR
mov ZLG_SEND_BUF,#10000110B ;Display hour
lcall DISPLAY_NUM
ret
;*****************************************************************
DISPLAY_NUM:
mov b,#0AH
div ab
push ZLG_SEND_BUF ;Save position value
lcall zlg_send ;Specify position
mov ZLG_SEND_BUF,b ;Display low value
lcall zlg_send
setb ZLG_CS
pop ZLG_SEND_BUF
inc ZLG_SEND_BUF
lcall zlg_send
mov ZLG_SEND_BUF,a ;Display high value
lcall zlg_send
setb ZLG_CS
ret
;*****************************************************************
DISPLAY_SEP:
lcall zlg_send ;Specify position
mov ZLG_SEND_BUF,#0AH ;Separation
lcall zlg_send
setb ZLG_CS
ret
;*****************************************************************
SET_TIME:
setb SETTING_FLAG
mov CURR_SECOND,SECOND
mov CURR_MINUTE,MINUTE
mov CURR_HOUR,HOUR
mov SELECTION,#1
WAIT_OPERATION_KEY:
lcall SET_SELECTION ;Change target to modify
jb ZLG_KEY,$ ;Wait for keyboard
mov ZLG_SEND_BUF,#00010101B ;Send the command of reading keyboard
lcall zlg_send
lcall zlg_receive ;Read the data of keyboard
setb ZLG_CS ;Set standby mode
jnb ZLG_KEY,$ ;Wait the key to pop
mov r0,ZLG_REC_BUF
cjne r0,#15,NOT_OK
mov SECOND,CURR_SECOND
mov MINUTE,CURR_MINUTE
mov HOUR,CURR_HOUR
dec SECOND ;Reduce error
jmp SET_TIME_EXIT
NOT_OK:
cjne r0,#14,NOT_FORWARD ;Not forward key
inc SELECTION
mov a,SELECTION
cjne a,#4,WAIT_OPERATION_KEY
mov SELECTION,#1
jmp WAIT_OPERATION_KEY
NOT_FORWARD:
cjne r0,#13,NOT_BACK ;Not back key
dec SELECTION
mov a,SELECTION
cjne a,#0,WAIT_OPERATION_KEY
mov SELECTION,#3
jmp WAIT_OPERATION_KEY
NOT_BACK:
cjne r0,#7,NOT_CANCEL ;Not cancel key
jmp SET_TIME_EXIT ;Quit without modify
NOT_CANCEL:
cjne r0,#6,NOT_DEC ;Not decrease key
lcall SET_DEC_TIME
lcall SET_DISPLAY_TIME
jmp WAIT_OPERATION_KEY
NOT_DEC:
cjne r0,#5,WAIT_OPERATION_KEY;Not add key
lcall SET_ADD_TIME
lcall SET_DISPLAY_TIME
jmp WAIT_OPERATION_KEY
SET_TIME_EXIT:
mov ZLG_SEND_BUF,#10001000B ;Disable selection
lcall zlg_send
mov ZLG_SEND_BUF,#11111111B
lcall zlg_send
clr SETTING_FLAG ;Set finished
ret
;*****************************************************************
SET_SELECTION:
mov ZLG_SEND_BUF,#10001000B
lcall zlg_send
;setb ZLG_CS
mov a,SELECTION
cjne a,#1,SEL_NOT_HOUR
mov ZLG_SEND_BUF,#00111111B
jmp HIGHLIGHT
SEL_NOT_HOUR:
cjne a,#2,SEL_NOT_MINUTE
mov ZLG_SEND_BUF,#11100111B
jmp HIGHLIGHT
SEL_NOT_MINUTE:
mov ZLG_SEND_BUF,#11111100B
jmp HIGHLIGHT
HIGHLIGHT:
lcall zlg_send
setb ZLG_CS
ret
;*****************************************************************
SET_DEC_TIME:
mov a,SELECTION
cjne a,#1,DEC_NOT_HOUR
dec CURR_HOUR
mov a,CURR_HOUR
cjne a,#0FFH,DEC_EXIT
mov CURR_HOUR,#23
jmp DEC_EXIT
DEC_NOT_HOUR:
cjne a,#2,DEC_NOT_MINUTE
dec CURR_MINUTE
mov a,CURR_MINUTE
cjne a,#0FFH,DEC_EXIT
mov CURR_MINUTE,#59
jmp DEC_EXIT
DEC_NOT_MINUTE:
dec CURR_SECOND
mov a,CURR_SECOND
cjne a,#0FFH,DEC_EXIT
mov CURR_SECOND,#59
jmp DEC_EXIT
DEC_EXIT:
ret
;*****************************************************************
SET_ADD_TIME:
mov a,SELECTION
cjne a,#1,ADD_NOT_HOUR
inc CURR_HOUR
mov a,CURR_HOUR
cjne a,#24,ADD_EXIT
mov CURR_HOUR,#0
jmp ADD_EXIT
ADD_NOT_HOUR:
cjne a,#2,ADD_NOT_MINUTE
inc CURR_MINUTE
mov a,CURR_MINUTE
cjne a,#60,ADD_EXIT
mov CURR_MINUTE,#0
jmp ADD_EXIT
ADD_NOT_MINUTE:
inc CURR_SECOND
mov a,CURR_SECOND
cjne a,#60,ADD_EXIT
mov CURR_SECOND,#0
jmp ADD_EXIT
ADD_EXIT:
ret
;*****************************************************************
SET_DISPLAY_TIME:
mov a,CURR_SECOND ;Display second
mov ZLG_SEND_BUF,#10000000B
lcall DISPLAY_NUM
mov a,CURR_MINUTE ;Display minute
mov ZLG_SEND_BUF,#10000011B
lcall DISPLAY_NUM
mov a,CURR_HOUR
mov ZLG_SEND_BUF,#10000110B ;Display hour
lcall DISPLAY_NUM
ret
;*****************************************************************
;Send a byte to MCU with higer bit first
zlg_send:
push acc
mov ZLG_BIT_CNT,#8 ;Set the number of data sended
clr ZLG_CS ;Set set ZLG7289 ready,T1
call delay_50;T1
ZLG_SEND_LP:
;Send a bit
mov a,ZLG_SEND_BUF
rlc a
mov ZLG_SEND_BUF,a
mov ZLG_DATA,c
nop ;Wait for data to ready
nop
setb ZLG_CLK ;T2
lcall delay_8
clr ZLG_CLK ;T3
lcall delay_8
djnz ZLG_BIT_CNT,ZLG_SEND_LP ;Loop to next bit
pop acc
;clr ZLG_DATA
ret
;*****************************************************************
;Receive a byte to ZLG7289 with higer bit first
zlg_receive:
mov ZLG_BIT_CNT,#8 ;Set the number of data received
clr ZLG_CS ;Set set ZLG7289 ready,T1
lcall delay_50
ZLG_REC_LP:
;Receive a bit
setb ZLG_CLK ;T2
lcall delay_8
mov c,ZLG_DATA
mov a,ZLG_REC_BUF
rlc a
mov ZLG_REC_BUF,acc
clr ZLG_CLK ;T3
lcall delay_8
djnz ZLG_BIT_CNT,ZLG_REC_LP ;Loop to next bit
clr ZLG_DATA
ret
;*****************************************************************
;Delay for (50+2) us
delay_50:
mov VAR_DELAY,#25
djnz VAR_DELAY,$
ret
;*****************************************************************
;Delay for (8+2) us
delay_8:
mov VAR_DELAY,#4
djnz VAR_DELAY,$
ret
;*****************************************************************
END
我写了,但是用编程器烧到s52上时,zlg显示不出来是怎么回事 |