LCD_DATA EQU PORTB
LCD_DATA_TRIS EQU TRISB
LCD_CTRL EQU PORTA
LCD_RS EQU 0x00
LCD_RW EQU 0x01
LCD_E EQU 0x02
wait_loop EQU 0x20
loop EQU 0x22
temp EQU 0x21
w_temp EQU 0x22
s_temp EQU 0x23
p_temp EQU 0x24
clock_timer EQU 0x25
update EQU 0x26
wait_w EQU 0x27
tc EQU 0x5f
wtemp EQU 0x30
h1 EQU 0x28
h10 EQU 0x29
m1 EQU 0x2a
m10 EQU 0x2b
s1 EQU 0x2c
s10 EQU 0x2d
fastinc EQU 0x2e
toggle EQU 0x2f
org 0x00
goto INIT
org 0x04
ISR
movwf w_temp
swapf STATUS,W
bcf STATUS,RP0
movwf s_temp
swapf PCLATH,W
movwf p_temp
bcf STATUS,Z
decfsz clock_timer,F
goto exit_int
movlw tc
movwf clock_timer
movf PORTA,W
andlw 0xf8
bcf STATUS,Z
xorlw 0x00
btfss STATUS,Z
goto chk_btn
movlw 0x00
movwf s1
movwf s10
goto ret_from_int
chk_btn
btfsc PORTA,3
goto check_hour
movlw tc
movwf clock_timer
bcf STATUS,C
rrf clock_timer,F
bcf STATUS,c
goto inc_min
check_hour
btfss PORTA,4
goto inc_hour
inc_sec
incf s1,F
movf s1,W
bcf STATUS,Z
xorlw 0x0A
btfss STATUS,Z
goto ret_from_int
movlw 0x00
movwf s1
incf s10,F
movf s10,W
bcf STATUS,Z
xorlw 0x06
btfss STATUS,Z
goto ret_from_int
movlw 0x00
movwf s10
inc_min
incf m1,F
movf m1,W
bcf STATUS,Z
xorlw 0x0A
btfss STATUS,Z
goto ret_from_int
movlw 0x00
movwf m1
incf m10,F
movf m10,W
bcf STATUS,Z
xorlw 0x06
btfss STATUS,Z
goto ret_from_int
movlw 0x00
movwf m10
inc_hour
incf h1,F
movf h1,W
bcf STATUS,Z
xorlw 0x0a
btfss STATUS,Z
goto ret_from_int
movlw 0x00
movwf h1
incf h10,F
movf h10,W
bcf STATUS,Z
xorlw 0x02
btfss STATUS,Z
goto ret_from_int
movf h1,W
bcf STATUS,Z
xorlw 0x04
btfss STATUS,Z
goto ret_from_int
movlw 0x00
movwf h1
movwf h10
ret_from_int
movf toggle,W
bcf STATUS,Z
xorlw 0x3a
movlw 0x3a
btfsc STATUS,Z
movlw 0xa0
movwf toggle
movlw 0x02
call LCDPUTCMD
movf h10,W
addlw 0x30
call LCDPUTDATA
movf h1,W
addlw 0x30
call LCDPUTDATA
movf toggle,W
call LCDPUTDATA
movf m10,W
addlw 0x30
call LCDPUTDATA
movf m1,W
addlw 0x30
call LCDPUTDATA
movf toggle,W
call LCDPUTDATA
movf s10,W
addlw 0x30
call LCDPUTDATA
movf s1,W
addlw 0x30
call LCDPUTDATA
exit_int
swapf p_temp,W
movwf PCLATH
swapf s_temp,W
movwf STATUS
swapf w_temp,F
swapf w_temp,W
bcf INTCON, T0IF
retfie
INIT
bsf STATUS,RP0
movlw 0x18
movwf TRISA
clrf TRISB
bcf OPTION_REG,T0CS
bcf OPTION_REG,PSA
bsf OPTION_REG,PS0
bcf OPTION_REG,PS1
bsf OPTION_REG,PS2
bcf STATUS,RP0
clrf PORTA
clrf PORTB
clrf h1
clrf h10
clrf m1
clrf m10
clrf s1
clrf s10
movlw tc
movwf clock_timer
goto main
WAIT
movwf wait_w
movlw 0xFF
movwf wait_loop
wloop
decfsz wait_loop,F
goto wloop
movf wait_w,W
return
LCDPUTCMD
movwf temp
call LCDWAIT
bcf LCD_CTRL,LCD_RS
bcf LCD_CTRL,LCD_RW
bsf LCD_CTRL,LCD_E
call WAIT
swapf temp,W
movwf LCD_DATA
bcf LCD_CTRL,LCD_E
call WAIT
bsf LCD_CTRL,LCD_E
call WAIT
movf temp,W
movwf LCD_DATA
bcf LCD_CTRL,LCD_E
return
LCDPUTDATA
movwf temp
call LCDWAIT
bsf LCD_CTRL,LCD_RS
bcf LCD_CTRL,LCD_RW
bsf LCD_CTRL,LCD_E
call WAIT
swapf temp,W
movwf LCD_DATA
bcf LCD_CTRL,LCD_E
call WAIT
bsf LCD_CTRL,LCD_E
call WAIT
movf temp,W
movwf LCD_DATA
bcf LCD_CTRL,LCD_E
return
LCDINIT
movlw 0xa0
movwf temp
lcdinitloop
call WAIT
decfsz temp,F
goto lcdinitloop
bcf LCD_CTRL,LCD_RS
bcf LCD_CTRL,LCD_RW
bsf LCD_CTRL,LCD_E
call WAIT
movlw 0x03
movwf LCD_DATA
bcf LCD_CTRL,LCD_E
call WAIT
call WAIT
bsf LCD_CTRL,LCD_E
call WAIT
call WAIT
bcf LCD_CTRL,LCD_E
call WAIT
call WAIT
bsf LCD_CTRL,LCD_E
call WAIT
call WAIT
bcf LCD_CTRL,LCD_E
call LCDWAIT
call WAIT
bsf LCD_CTRL,LCD_E
movlw 0x02
movwf LCD_DATA
call WAIT
call WAIT
bcf LCD_CTRL,LCD_E
movlw 0x20
call LCDPUTCMD
movlw 0x0C
call LCDPUTCMD
movlw 0x01
call LCDPUTCMD
return
LCDWAIT
BSF STATUS,RP0
MOVLW 0xFF
MOVWF LCD_DATA_TRIS
BCF STATUS, RP0
BCF LCD_CTRL, LCD_RS
BSF LCD_CTRL, LCD_RW
do_check
BSF LCD_CTRL, LCD_E
MOVF LCD_DATA, W
movwf wtemp
BCF LCD_CTRL, LCD_E
call WAIT
BSF LCD_CTRL, LCD_E
call WAIT
bcf LCD_CTRL, LCD_E
movf wtemp,W
ANDLW 0x08
BTFSS STATUS, Z
GOTO do_check
lcdnotbusy
BCF LCD_CTRL, LCD_RW
BSF STATUS, RP0
MOVLW 0x000
MOVWF LCD_DATA_TRIS
BCF STATUS, RP0
return
main
call LCDINIT
bsf INTCON,T0IE
bcf INTCON,T0IF
bsf INTCON,GIE
mainloop
goto mainloop
end
|