Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Binary Clock using pic16f88 help with push buttons

Status
Not open for further replies.

Carl03

New Member
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:

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

My buttons are to set the hours and minutes. My hours set button is connected to RA3 and minutes set button is connected to RA4 and this also resets the seconds. I've written a bit of code but when I start the program, it scrolls through the hours fast (very fast) until I press the hours set button does the same with minutes. I would post the code but at the moment I'm replying via my mobile. Any ideas what my problem might be?

This is what I've tried so far

Code:
check_delay:
	incf	debounce, f
	movf	debounce, w
	sublw	.255
	skpweq
	goto	check_delay
	clrf	debounce
	goto	check_buttons

check_buttons:
	movf	PORTA, w
	movwf	buttons	
	btfss	buttons,4
	goto	check_end
	btfss	buttons, 3
	btfss	buttons, 4
	goto	set_hours
	goto	set_min

set_hours:
	btfss	buttons, 3
	goto	check_end
	incf	hour, f
	movf	hour, w
	sublw	d'24'
	skpweq
	goto	show_hour
	clrf	hour
show_hour:
	movf	hour, w
	movwf	hour
	bsf		T2CON, TMR2ON		
	return

set_min:
	incf	min, f
	movf	min, w
	sublw	d'60'
	skpweq
	goto	show_min
	clrf	min	
show_min:
	movf 	min, w
	movwf	min

check_end:
	bsf		T2CON, TMR2ON
	return
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top