Subversion Repositories Code-Repo

Rev

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

/* The processor calls these handlers when an interrupt is triggered */
#include "maindefs.h"
#include <timers.h>
#include "timers.h"

void timers_init() {
    /*--------------------Timer Delay Formulas-------------------- */
    /* InitTMR0 = 256 - ( Delay * Frequency ) / ( 4* Prescaler)    */
    /* Delay = (256 - InitTMR0 * Prescaler) / (Frequency / 4)      */
    /* ----------------------------------------------------------- */
    

    OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_16);
    T0CONbits.TMR0ON = 0;   // Timer 0 initially off

//    // Set timer 1 to overflow every two seconds
//    OpenTimer1(TIMER_INT_ON & T1_16BIT_RW &
//                T1_SOURCE_PINOSC & T1_PS_1_1 &
//                T1_OSC1EN_ON & T1_SYNC_EXT_OFF,
//                TIMER_GATE_OFF & TIMER_GATE_INT_OFF);
    
    // Open timer 2 for ECCP1 (PWM)
    OpenTimer2(TIMER_INT_OFF & T2_PS_1_4 & T2_POST_1_1);

    // Open timer 3 for PWM IR signaling
    OpenTimer3(TIMER_INT_ON & T3_16BIT_RW & T3_SOURCE_FOSC_4 & 
            T3_OSC1EN_OFF & T3_PS_1_1 & T3_SYNC_EXT_OFF, TIMER_GATE_OFF);
    T3CONbits.TMR3ON = 0;   // Timer 3 initially off
}

// Interrupt handler for timer 0
void timer0_interrupt_handler() {
    
}

void timer0_enable() {
    T0CONbits.TMR0ON = 1;
}
void timer0_disable() {
    T0CONbits.TMR0ON = 0;
}

// Interrupt handler for timer 1
void timer1_interrupt_handler() {
    
}

void timer3_interrupt_handler() {

}

void timer3_enable() {
    T3CONbits.TMR3ON = 1;
}
void timer3_disable() {
    T3CONbits.TMR3ON = 0;
}