What I want to do is have a button connected to Port A, 0
I want to push the button N amount of times and then display it on a
BCD
encoder that I have hooked to RA1-4.
The amount of time I want it to wait before it ouputs to the BCD is
about
5-10 seconds then after it outputs the BCD then it will just stop.
---------------------
LIST P=16F84A
INCLUDE "p16f84A.inc"
CBLOCK 0CH
count ; count storage
ENDC
;**********************
; CPU EQUATES
;**********************
#DEFINE BTN PORTA, 0
org 0x00
goto main ; jump over to main routine
;****************
;Port Init
;****************
Init:
clrf PORTA
clrf PORTB
movlw B'00000111' ; RA0-2 input, others outputs
; tris PORTA
movlw B'00000000' ; RB all outputs
; tris PORTB
; option
return
;**************************
;Lookup table for BCD
;**************************
LEDLOOKUP:
addwf PCL, f
retlw 0x00 ;led drive za 0
retlw 0x01 ;1
retlw 0x02 ;2
retlw 0x03 ;3
retlw 0x04 ;4
retlw 0x05 ;5
retlw 0x06 ;6
retlw 0x07 ;7
retlw 0x08 ;8
retlw 0x09 ;9
return
;**************************
;Delay Subroutines
;**************************
onesecond: ; a subroutine that delays for 1 seconds
call msec250
call msec250
call msec250
call msec250
return
msec40 movlw D'40' ; 40 msec delay entry point
goto nmsec
msec250: ; a subroutine to delay 250 msec
movlw D'250' ; W is changed but no separate register needed
nmsec: ; could call it here with # msec in W
nop ; each nop is 0.122 milliseconds
nop
nop ; each total loop is 8 X 0.122 = 0.976 msec
nop
addlw 0xFF ; same as subtracting 1 from W
btfss STATUS, Z ; skip if result is zero
goto nmsec ; this is 2 X 0.122 msec
return ; back to calling point
;*******************
;Main Program
;*******************
main:
call Init ; initialize ports, set up timer
call press
movf count, w ; Display number in binary
movlw PORTB
press:
btfss BTN ; wait until pushbutton
incf count ; increment
call onesecond ; wait 5 seconds
call onesecond
call onesecond
call onesecond
call onesecond
return
; doThis call BUTNPRESS
; movf LEDLOOKUP, w ; Get lookup received
; movwf portB ; Display on 7 segment display
; circle goto doThis ; Done
; movwf portB ; Display on 7 segment display
end
I want to push the button N amount of times and then display it on a
BCD
encoder that I have hooked to RA1-4.
The amount of time I want it to wait before it ouputs to the BCD is
about
5-10 seconds then after it outputs the BCD then it will just stop.
---------------------
LIST P=16F84A
INCLUDE "p16f84A.inc"
CBLOCK 0CH
count ; count storage
ENDC
;**********************
; CPU EQUATES
;**********************
#DEFINE BTN PORTA, 0
org 0x00
goto main ; jump over to main routine
;****************
;Port Init
;****************
Init:
clrf PORTA
clrf PORTB
movlw B'00000111' ; RA0-2 input, others outputs
; tris PORTA
movlw B'00000000' ; RB all outputs
; tris PORTB
; option
return
;**************************
;Lookup table for BCD
;**************************
LEDLOOKUP:
addwf PCL, f
retlw 0x00 ;led drive za 0
retlw 0x01 ;1
retlw 0x02 ;2
retlw 0x03 ;3
retlw 0x04 ;4
retlw 0x05 ;5
retlw 0x06 ;6
retlw 0x07 ;7
retlw 0x08 ;8
retlw 0x09 ;9
return
;**************************
;Delay Subroutines
;**************************
onesecond: ; a subroutine that delays for 1 seconds
call msec250
call msec250
call msec250
call msec250
return
msec40 movlw D'40' ; 40 msec delay entry point
goto nmsec
msec250: ; a subroutine to delay 250 msec
movlw D'250' ; W is changed but no separate register needed
nmsec: ; could call it here with # msec in W
nop ; each nop is 0.122 milliseconds
nop
nop ; each total loop is 8 X 0.122 = 0.976 msec
nop
addlw 0xFF ; same as subtracting 1 from W
btfss STATUS, Z ; skip if result is zero
goto nmsec ; this is 2 X 0.122 msec
return ; back to calling point
;*******************
;Main Program
;*******************
main:
call Init ; initialize ports, set up timer
call press
movf count, w ; Display number in binary
movlw PORTB
press:
btfss BTN ; wait until pushbutton
incf count ; increment
call onesecond ; wait 5 seconds
call onesecond
call onesecond
call onesecond
call onesecond
return
; doThis call BUTNPRESS
; movf LEDLOOKUP, w ; Get lookup received
; movwf portB ; Display on 7 segment display
; circle goto doThis ; Done
; movwf portB ; Display on 7 segment display
end