assemblyinterruptpicmplab

How to use PIC12F675 timer1 interrupt?


What is wrong with this code? The interrupt at 0004 never executes! MPLAB X IDE simulator I tried changing all the bits of T1CON, but no results

; TODO INSERT CONFIG CODE HERE USING CONFIG BITS GENERATOR
#include "p12f675.inc"

; CONFIG
; __config 0x31F1
 __CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _BOREN_ON & _CP_OFF & _CPD_OFF

D1 equ h'20'  ;delay variabile
D2 equ h'21' 
D3 equ h'22' 
 
RES_VECT  CODE    0x0000            ; processor reset vector
    GOTO    START                   ; go to beginning of program

INT_VECT  CODE    0x0004    
 ; TODO ADD INTERRUPTS HERE IF USED
  ;vine de 10 ori/sec
  ;contor 10 ori:
  movlw d'61' ; ar fi (256-61)*256= cca 50 ms > apoi prescaler 2 => 100 ms
  movwf TMR1L  ;numara 61...255
  clrf TMR1H   ;numara 0...255
  bcf PIR1,0  ;clear timer1 interupt flag/ ca sa porneasca
  nop
  retfie

MAIN_PROG CODE                      ; let linker place main program
START
  ; init timer interupt:
  bsf STATUS, RP0  ;banc 1
  bsf PIE1,0  ;enable timer 1 interupt
  bcf STATUS, RP0   ; banc 0
  movlw d'61' ; ar fi (256-61)*256= cca 50 ms > apoi prescaler 2 => 100 ms
  movwf TMR1L  ;numara 61...255
  clrf TMR1H   ;numara 0...255
  movlw b'00010101' ;prescaler 2, timer1 enabled
  movwf T1CON
  movlw b'10000000' ;enable timer-overflow interrupt. trebe?!
  movwf INTCON  
  bcf PIR1,0  ;clear timer1 interupt flag/ ca sa porneasca
  
loop  
    movlw d'10'
    movwf D1
    GOTO loop                          ; loop forever

    END


Solution

  • To make it short: To enable timer 1 interrupt you had to set these bits: