Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 Kevin 1
/* The processor calls these handlers when an interrupt is triggered */
2
#include "maindefs.h"
3
#include <timers.h>
4
#include "timers.h"
5
 
6
void timers_init() {
7
    /*--------------------Timer Delay Formulas-------------------- */
8
    /* InitTMR0 = 256 - ( Delay * Frequency ) / ( 4* Prescaler)    */
9
    /* Delay = (256 - InitTMR0 * Prescaler) / (Frequency / 4)      */
10
    /* ----------------------------------------------------------- */
11
 
121 Kevin 12
 
119 Kevin 13
    OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_16);
14
    T0CONbits.TMR0ON = 0;   // Timer 0 initially off
15
 
16
//    // Set timer 1 to overflow every two seconds
17
//    OpenTimer1(TIMER_INT_ON & T1_16BIT_RW &
18
//                T1_SOURCE_PINOSC & T1_PS_1_1 &
19
//                T1_OSC1EN_ON & T1_SYNC_EXT_OFF,
20
//                TIMER_GATE_OFF & TIMER_GATE_INT_OFF);
21
 
22
    // Open timer 2 for ECCP1 (PWM)
23
    OpenTimer2(TIMER_INT_OFF & T2_PS_1_4 & T2_POST_1_1);
24
 
25
    // Open timer 3 for PWM IR signaling
26
    OpenTimer3(TIMER_INT_ON & T3_16BIT_RW & T3_SOURCE_FOSC_4 & 
27
            T3_OSC1EN_OFF & T3_PS_1_1 & T3_SYNC_EXT_OFF, TIMER_GATE_OFF);
28
    T3CONbits.TMR3ON = 0;   // Timer 3 initially off
29
}
30
 
31
// Interrupt handler for timer 0
32
void timer0_interrupt_handler() {
121 Kevin 33
 
119 Kevin 34
}
35
 
36
void timer0_enable() {
37
    T0CONbits.TMR0ON = 1;
38
}
39
void timer0_disable() {
40
    T0CONbits.TMR0ON = 0;
41
}
42
 
43
// Interrupt handler for timer 1
44
void timer1_interrupt_handler() {
121 Kevin 45
 
119 Kevin 46
}
47
 
48
void timer3_interrupt_handler() {
121 Kevin 49
 
119 Kevin 50
}
51
 
52
void timer3_enable() {
53
    T3CONbits.TMR3ON = 1;
54
}
55
void timer3_disable() {
56
    T3CONbits.TMR3ON = 0;
57
}