newwbies
Newbie level 4
hello i really need an asm program in this.. i have already the clock program but i cant seem to set the time with the keypad to the lcd.. i really hope you could help me.. :'(
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Processor 16F84A
#include "p16F84A.inc"
__CONFIG _CP_OFF & _PWRTE_OFF & _WDT_OFF & _XT_OSC
;Automatic Fish Feeder
#Define glatch PORTA,3
#Define lcd_e PORTA,2
#Define lcd_rw PORTA,1
#Define lcd_rs PORTA,0
org 0x00
mhz EQU D'4'
del1 equ 0ch
del2 equ 0dh
del3 equ 0eh
hour_hi equ 0fh
hour_lo equ 10h
min_hi equ 11h
min_lo equ 12h
sec_hi equ 13h
sec_lo equ 14h
temp equ 15h
count1 equ 16h
count2 equ 17h
count3 equ 18h
count4 equ 19h
ncode1 equ 1ah
ncode2 equ 1bh
ncode3 equ 1ch
ncode4 equ 1dh
ncode5 equ 1eh
ncode6 equ 1fh
key equ 20h
accu equ 21h
dcnt0 EQU 22h ; delay counter 0
dcnt1 EQU 23h ; delay counter 1
dcnt2 EQU 24h
;temp equ 25h
goto Main
org 0x04
goto Main
;kani Setup Output Port
Main
bsf STATUS,5 ;switch to bank 1
movlw 04h ; PORTA output RA0 to RA4
movwf TRISA
movlw 00h
movwf TRISB
bcf STATUS,5 ;switch back to bank 0
clrf PORTA
clrf PORTB
btfss PORTA,2
call KEYPAD
call settime
btfsc PORTA,2
call input
call circle
settime
movlw 0x00
movwf hour_hi
movlw 0x00
movwf hour_lo
movlw 0x00
movwf min_hi
movlw 0x00
movwf min_lo
movlw 0x00
movwf sec_hi
movlw 0x00
movwf sec_lo
;call line3
call lcd_init
call line3
;out1 movlw d'150'
; call udelay
; decfsz dcnt2, F
; goto out1
call displaytext
;out1 movlw d'150'
;call udelay
;decfsz dcnt2, F
;goto out1
call curhom
out2 movlw d'150'
call udelay
decfsz dcnt2, F
goto out2
;call line2
movlw 0xc6
call lcd_cmd
call displaytime
out3 movlw d'150'
call udelay
decfsz dcnt2, F
goto out3
;;input from the keypad
circle
btfsc PORTA,2
call input
call delay
;call line2
movlw 0xc6
call lcd_cmd
call displaytime
incf sec_lo,1
movlw 0x0a
subwf sec_lo,0
btfss STATUS,0
goto circle
goto c_sechi
c_sechi
clrf sec_lo
incf sec_hi,1
movlw 0x06
subwf sec_hi,0
btfss STATUS,0
goto circle
goto c_minlo
c_minlo
clrf sec_hi
incf min_lo,1
movlw 0x0a
subwf min_lo,0
btfss STATUS,0
goto circle
goto c_minhi
c_minhi
clrf min_lo
incf min_hi,1
movlw 0x06
subwf min_hi,0
btfss STATUS,0
goto circle
goto testhi
testhi
clrf min_hi
movlw 0x02
subwf hour_hi,0
btfss STATUS,0
goto hi1
goto testlow
testlow
incf hour_lo,1
movlw 0x04
subwf hour_lo,0
btfss STATUS,0
goto low1
goto hi2
hi1
incf hour_lo,1
movlw 0x0a
subwf hour_lo,0
btfss STATUS,0
goto circle
goto low2
low1
goto circle
hi2
clrf hour_lo
clrf hour_hi
goto circle
low2
incf hour_hi,1
clrf hour_lo
goto circle
;delay
;movlw 0x10
;movwf del3
;loop1 decfsz del1,1
;goto loop1
; decfsz del2,1
; goto loop1
; decfsz del3,1
; goto loop1
;return
delay:
loop1 decfsz 08h, 1
goto loop1
decfsz 09h, 1
goto loop1
decfsz 0Ah, 1
goto loop1
return
;**************************************************
delay5
movlw 0x12 ; delay 50us (18*3+2us)
movwf count1
d11
decfsz count1,F
goto d11
return
;***************************************************
delay30
movlw 0x20 ; delay 32ms
movwf count2
r2 movlw 0xFA ; cca. 1ms (250*4us)
movwf count1
r1 nop
decfsz count1,F
goto r1
decfsz count2,F
goto r2
return
;***************************************************
delay200
movlw 0xC8 ; delay 200ms
movwf count2
t2 movlw 0xFA ; cca. 1ms (250*4us)
movwf count1
t1 nop
decfsz count1,F
goto t1
decfsz count2,F
goto t2
return
;************************************************************************
lcd_init
call delay200
bsf STATUS,RP0
movlw 0x00
movwf TRISB
bcf STATUS,RP0
bsf glatch
movlw 0x3F
call lcd_cmd
call delay30
movlw 0x0E
call lcd_cmd
call delay30
movlw 0x06
call lcd_cmd
call delay30
movlw 0x01
call lcd_cmd
bcf glatch
return
lcd_cmd
nop
bcf PORTA,0
nop
movwf PORTB
nop
; bsf PORTA,3
bcf PORTA,1
nop
nop
bsf PORTA,1
nop
nop
bcf PORTA,1
nop
nop
; bcf PORTA,3
call delay5
;bcf lcd_rw
;nop
;bcf lcd_rs
;nop
;movwf PORTB
;nop
;bsf glatch
;bcf lcd_e
;nop
;nop
;bsf lcd_e
;nop
;nop
;bcf lcd_e
;nop
;nop
;bcf glatch
;call delay5
return
lcd_data
nop
bsf PORTA,0
nop
movwf PORTB
nop
;bsf PORTA,3
bcf PORTA,1
nop
nop
bsf PORTA,1
nop
nop
bcf PORTA,1
nop
nop
; bcf PORTA,3
call delay5
;bcf lcd_rw
;nop
;bsf lcd_rs
;nop
;movwf PORTB
;nop
;bsf glatch
;bcf lcd_e
;nop
;nop
;bsf lcd_e
;nop
;nop
;bcf lcd_e
;nop
;nop
;bcf glatch
;call delay5
return
line1
movlw 0x80
call lcd_cmd
return
line2
movlw 0xC0
call lcd_cmd
return
line3
movlw 0x94
call lcd_cmd
return
shiftr
movlw 0x0a
call lcd_cmd
return
curhom
movlw 0x02
call lcd_cmd
return
displaytime
movf hour_hi,0
movwf count3
call text
call lcd_data
movf hour_lo,0
movwf count3
call text
call lcd_data
movlw 0x0a
movwf count3
call text
call lcd_data
movf min_hi,0
movwf count3
call text
call lcd_data
movf min_lo,0
movwf count3
call text
call lcd_data
movlw 0x0a
movwf count3
call text
call lcd_data
movf sec_hi,0
movwf count3
call text
call lcd_data
movf sec_lo,0
movwf count3
call text
call lcd_data
return
displaytext
;bsf glatch
call line3
movlw 0x12
movwf count4
movlw 0x0b
movwf count3
scr2
call text
call lcd_data
incf count3,F
decfsz count4,F
goto scr2
;bcf glatch
return
ORG 0x0300
text
movlw 0x03
movwf PCLATH
movf count3,W
addwf PCL,F
retlw 0x30 ;0
retlw 0x31 ;1
retlw 0x32 ;2
retlw 0x33 ;3
retlw 0x34 ;4
retlw 0x35 ;5
retlw 0x36 ;6
retlw 0x37 ;7
retlw 0x38 ;8
retlw 0x39 ;9
retlw 0x3a ;:
retlw 0x20
retlw 0x20
retlw 0x20
retlw 0x20
retlw 0x46 ;F
retlw 0x49 ;I
retlw 0x53 ;S
retlw 0x48 ;H
retlw 0x20 ;Space
retlw 0x46 ;F
retlw 0x45 ;E
retlw 0x45 ;E
retlw 0x44 ;D
retlw 0x45 ;E
retlw 0x52 ;R
retlw 0x21 ;!
retlw 0x21 ;!
retlw 0x20 ;Space
udelay ; delay W * 100 usec
movwf dcnt0
udelay0 movlw 8 * mhz
movwf dcnt1
udelay1 decfsz dcnt1, F
goto udelay1
decfsz dcnt0, F
goto udelay0
return
bnkcol
bsf STATUS,RP0
movlw b'11110000'
movwf TRISB
bcf STATUS,RP0
RETURN
bnkrow
bsf STATUS,RP0
movlw b'00001111'
movwf TRISB
bcf STATUS,RP0
RETURN
lcd_bank
bsf STATUS,RP0 ;switch to bank 1
movlw 0x04 ; PORTA output RA0 to RA4
movwf TRISA
movlw 0x00
movwf TRISB
bcf STATUS,RP0 ;switch back to bank 0
return
KEYPAD
movlw 0xc6
call lcd_cmd
;clrf PORTB
;call bnk
call input
movlw '#'
subwf temp,0
btfsc STATUS,2
return
movf temp,w
movwf hour_hi
call input
movlw '#'
subwf temp,0
btfsc STATUS,2
return
movf temp,w
movwf hour_lo
call input
movlw '#'
subwf temp,0
btfsc STATUS,2
return
movf temp,w
movwf min_hi
call input
movlw '#'
subwf temp,0
btfsc STATUS,2
return
movf temp,w
movwf min_lo
call input
movlw '#'
subwf temp,0
btfsc STATUS,2
return
movf temp,w
movwf sec_hi
call input
movlw '#'
subwf temp,0
btfsc STATUS,2
return
movf temp,w
movwf sec_lo
return
input:
call curhom
clrf PORTB
nop
call bnkcol
btfss PORTB,4
goto rw1
btfss PORTB,5
goto rw2
btfss PORTB,6
goto rw3
btfss PORTB,7
goto rw4
goto input
rw1
nop
call bnkrow
btfss PORTB,1
goto d1
btfss PORTB,2
goto d2
btfss PORTB,3
goto d3
rw2
nop
call bnkrow
btfss PORTB,1
goto d4
btfss PORTB,2
goto d5
btfss PORTB,3
goto d6
rw3
nop
call bnkrow
btfss PORTB,1
goto d7
btfss PORTB,2
goto d8
btfss PORTB,3
goto d9
rw4
nop
call bnkrow
btfss PORTB,1
goto dx
btfss PORTB,2
goto d0
btfss PORTB,3
goto d#
d1
call lcd_bank
;call lcd_init
movlw 0x01
movwf temp
movlw '1'
call lcd_data
return
d2
call lcd_bank
;call lcd_init
movlw 0x02
movwf temp
movlw '2'
call lcd_data
return
d3
call lcd_bank
;call lcd_init
movlw 0x03
movwf temp
movlw '3'
call lcd_data
return
d4
call lcd_bank
;call lcd_init
movlw 0x04
movwf temp
movlw '4'
call lcd_data
return
d5
call lcd_bank
;call lcd_init
movlw 0x05
movwf temp
movlw '5'
call lcd_data
return
d6
call lcd_bank
;call lcd_init
movlw 0x06
movwf temp
movlw '6'
call lcd_data
return
d7
call lcd_bank
;call lcd_init
movlw 0x07
movwf temp
movlw '7'
call lcd_data
return
d8
call lcd_bank
;call lcd_init
movlw 0x08
movwf temp
movlw '8'
call lcd_data
return
d9
call lcd_bank
;call lcd_init
movlw 0x09
movwf temp
movlw '9'
call lcd_data
return
dx
goto input
d0
call lcd_bank
;call lcd_init
movlw 0x00
movwf temp
movlw '0'
call lcd_data
return
d#
;call lcd_bank
;call lcd_init
movlw '#'
movwf temp
;movlw '1'
;call lcd_data
return
end