Hi,
I'm building a binary clock and I have been working on this project for a while now, I have completed all programming up until the buttons. I have timer0 interrupt going for state machine/multiplexing and timer2 interrrupt going for the actual time keeping. I'm using assembler to code this and I don't know where the button coding would come.
Here is my interrupt routine:
Does anyone have a code snippet of debouncing a button?
Any help would be greatly appreciated.
I'm building a binary clock and I have been working on this project for a while now, I have completed all programming up until the buttons. I have timer0 interrupt going for state machine/multiplexing and timer2 interrrupt going for the actual time keeping. I'm using assembler to code this and I don't know where the button coding would come.
Here is my interrupt routine:
Rich (BB code):
;**************** INTERRUPT SERVICE *********************
ORG 0x0004
isr:
movwf W_TEMP ; save off current W register contents
movf STATUS,W ; move status register into W register
movwf STATUS_TEMP ; save off contents of STATUS register
movf PCLATH,W ; move pclath register into W register
movwf PCLATH_TEMP ; save off contents of PCLATH register
; Test to see if the interrupt was generated by TMR0 or TMR2
btfsc INTCON,TMR0IF ; TMR0 interrupt?
goto tmr0int ; Yes
btfsc PIR1, TMR2IF
goto tmr2int
goto intout
tmr0int:
bcf INTCON, TMR0IF ; clear interrupt flag (HAVE TO DO THIS)
state_machine:
movlw .0
xorwf current_state, w
btfsc STATUS, Z
goto state_machine_hours
movlw .1
xorwf current_state, w
btfsc STATUS, Z
goto state_machine_min
goto state_machine_sec
state_machine_hours:
bcf SEC_EN
comf hour, w
movwf PORTB
bsf HOUR_EN
incf current_state, f
goto state_machine_end
state_machine_min:
bcf HOUR_EN
comf min, w
movwf PORTB
bsf MIN_EN
incf current_state, f
goto state_machine_end
state_machine_sec:
bcf MIN_EN
comf sec, w
movwf PORTB
bsf SEC_EN
clrf current_state
state_machine_end:
goto intout
tmr2int:
bcf PIR1, TMR2IF ; clear interrupt flag (HAVE TO DO THIS)
sec_s:
banksel sec
incf sec_split, f
movf sec_split, w
sublw d'250'
skpweq
goto intout
every_sec:
clrf sec_split
incf sec, f
movf sec, w
sublw d'60'
skpweq
goto intout
;gets here every minute
every_min:
clrf sec
incf min, f
movf min, w
sublw d'60'
skpweq
goto intout
;gets here every hour
every_hour:
clrf min
incf hour, f
movf hour, w
sublw d'24'
skpweq
goto intout
clear:
clrf sec
clrf min
clrf hour
intout:
movf PCLATH_TEMP,W ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf STATUS_TEMP,W ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf W_TEMP,F
swapf W_TEMP,W ; restore pre-isr W register contents
retfie ; return from interrupt
Any help would be greatly appreciated.
Attachments
-
116.5 KB Views: 16