How to operate a PIC12F724 Timer 1

Thread Starter

lexdean

Joined Jan 22, 2010
2
Hi all

The literature is very misleading in its wording
I get everything else ok

I can handle the pre scaling and timing count of the timer as I want it to run as long as possible (about 3.8 times a second)

I'm wanting a continuous synchronous timer running on the internal 8 MHZ clock
I want it to trigger the interrupt at the end of its count.

What register set were

how
best regards,
Lex Dean
 

Markd77

Joined Sep 7, 2009
2,806
This is for 12F675 - check the banks of all the Special Function Registers as they tend to move around on different chips - hopefully the 724 isn't too different.
I've deleted all but the important stuff for the timer interrupt - on a 675 at 4MHz this gives 2 interrupts per second.

Rich (BB code):
    list    p=12F675
    radix    hex
    title "sound"
        #include <p12f675.inc>
    __config _CP_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT


    cblock 0x20
    W_TEMP
    STATUS_TEMP   
    endc
  
;    
;----------------------------------------------------------------------

    org    0x000
    goto init
    org 0x004    ;interrupt goes here
    MOVWF W_TEMP ; Copy W to TEMP register,
    SWAPF STATUS, W ; Swap status to be saved into W
    MOVWF STATUS_TEMP ; Save status to STATUS_TEMP register
    ;ISR : :
         ; Interrupt Service Routine

    
endint
     ; should configure Bank as required
     ;
    SWAPF STATUS_TEMP,W     ; Swap nibbles in STATUS_TEMP register
    ; and place result into W
    MOVWF STATUS             ; Move W into STATUS register
    ; (sets bank to original state)
    SWAPF W_TEMP, F         ; Swap nibbles in W_TEMP and place result in W_TEMP
    SWAPF W_TEMP, W         ; Swap nibbles in W_TEMP and place result into W
;    CLRF TMR1L                 ; Clear Low byte, Ensures no rollover into TMR1H
;    movlw 0xC0                ;set up timer1
;    movwf TMR1H
;    clrf TMR1L
    clrf INTCON                ;clr interupts
    bsf INTCON,PEIE            ;timer1 interrupt on
;    bsf INTCON, GPIE        ;gpio change interrupt on
    bcf PIR1, 0            ;clr tmr1 interrupt flag
    retfie
    
init    ;initialise stuff here
   
    movlw B'00110001'
    movwf T1CON                ;enable timer1 internal 1:8 prescaler 
    BSF STATUS, RP0 ; Bank 1
   
    bsf PIE1, 0                ;timer1 int enabled
;    BSF STATUS, RP0 ; Bank 1    
    clrf   OPTION_REG      ; 
    bcf     STATUS, RP0    ; bank 0    
    movlw   B'01000000'     ; enable timer 1 interrupt (not GIE yet)
    movwf   INTCON          ;  
    CLRF TMR1L                 ; Clear Low byte, Ensures no rollover into TMR1H
    clrf TMR1H
    
    bsf INTCON, GIE            ;enable interrupts, then sleep
  
main
   


    goto main

    end
 
Top