Subversion Repositories Code-Repo

Rev

Rev 222 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include <xc.h>
#include "main.h"
#include "TIMER.h"

void TIMER_1_Init(void) {
    T1CONbits.TMR1CS = 2;   // Clock source is ext oscillator
    T1CONbits.T1CKPS = 0;   // Prescale of 1:1
    T1CONbits.T1OSCEN = 1;  // Dedicated oscillator circuit enabled
    T1CONbits.nT1SYNC = 1;  // Async external clock input
    T1CONbits.TMR1ON = 0;   // Timer stopped
    T1GCONbits.TMR1GE = 0;  // Gate disabled
    TMR1 = 0x8000;

    PIE1bits.TMR1IE = 1;    // Timer 1 overflow interrupt
}

void TIMER_1_Start(void) {
    T1CONbits.TMR1ON = 1;   // Start timer
}

void TIMER_1_Stop(void) {
    T1CONbits.TMR1ON = 0;   // Stop timer
}

void TIMER_1_Interrupt_Handler(void) {
    LED_LAT = ~LED_LAT;
    TMR1 = 0x8000;
}