Nope... I can't make this darn thing work. I've already gone through the code and see nothing wrong with it, other than the fact that no CCPx pin has been defined as an output (as per the datasheet's specs) for the compare mode interrupt to work.
Here's my code. The LED is flashing every two seconds instead of one, as it should. That means that only one of the two interrupts (Timer1 overflow, and match compare) is working. Most likely only overflow, which is the one that was working fine already.
Here's my code. The LED is flashing every two seconds instead of one, as it should. That means that only one of the two interrupts (Timer1 overflow, and match compare) is working. Most likely only overflow, which is the one that was working fine already.
Code:
RESET_VECTOR: ORG 0x000 ;processor reset vector
goto Init ;go to beginning of program
INT_VECTOR: ORG 0x004 ;interrupt vector location
call Increment_Timekeeping ;update internal seconds counter by adding
;one second to its counter
bsf FLAGS, TIMER1_OV_FLAG ;set the Timer Overflow Flag to signal
;that the Timer_Servicing routine must be
;called. Located in common RAM
call FLASH_LED
;Clear both Timer1 Overflow and Compare match interrupt flags before
;leaving
banksel PIR1 ;Bank 0
bcf PIR1, TMR1IF ;clear the Timer1 interrupt flag
bcf PIR1, CCP1IF ;clear the compare mode interrupt flag
retfie
Init:
call Set_31_KHz_Int_Osc
;INTCON is present in all Banks, so no Bank select is necessary
bsf INTCON, PEIE ;enable all active peripheral interrupts
bsf INTCON, GIE ;enable all active general interrupts
call Start_Timer1
Button_Sense_Loop:
btfss PORTC, PUSHBUTTON_PIN ;check if the push button has been pressed
call Eval_Button_State ;evaluate its state if it has
btfsc FLAGS, TIMER1_OV_FLAG ;check if a Timer1 overflow has happened
call Timer_Servicing
goto Button_Sense_Loop
Start_Timer1:
;set the Compare 16-bit register to half its maximum value.
banksel CCPR1L ;bank 5
clrf CCPR1L ;set compare register low byte to zero
clrf CCPR1H ;set compare register high byte to zero
bsf CCPR1H, 7D ;set compare register high byte to 128,
;this sets the whole compare register to 32,768
;Enable compare mode software interrupt
;banksel CCP1CON ; bank 5
movlw b'00001010' ; software interrupt on match
movwf CCP1CON
;Clearing the interrupt flag and the counter before starting Timer1 is
;recommended by the datasheet
banksel PIR1 ;Bank 0
clrf PIR1 ;clear all peripheral interrupt flags
;banksel TIMR1L ;Bank 0
clrf TMR1L ;clear both bytes of the
clrf TMR1H ;Timer1 counter
;enable Timer1 overflow and compare interrupts
banksel PIE1 ;Bank 1
bsf PIE1, TMR1IE ;enable Timer1 overflow interrupt
bsf PIE1, CCP1IE ;enable Timer1 compare mode interrupt
;Finally, set Timer1 parameters amd start the timer
;the bit structure of T1Con is as follows:
; TMR1CS | T1CKPS |T1OSCEN| /T1SYNC | - | TMR1ON|
; 7 6 5 4 3 2 1 0 |
;Clock source is pin or oscillator (10)
;Prescaler is 1:1 (00)
;Oscillator circuit enabled (1)
;External Clock Input Sync disabled (1)
;bit 1 is not used (0)
;Timer1 start (1)
banksel T1CON ;Bank 0
movlw b'10001101'
movwf T1CON
;Timer1 interrupt period is now given by 2^16/32.768 KHz = 2 seconds exactly
;and compare mode will also yield the same interrupt period, but with a one
;second difference
return
END



