Subversion Repositories Code-Repo

Rev

Rev 121 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 121 Rev 147
Line 1... Line 1...
1
/* The processor calls these handlers when an interrupt is triggered */
1
/* The processor calls these handlers when an interrupt is triggered */
2
#include "maindefs.h"
2
#include "defines.h"
3
#include <timers.h>
-
 
4
#include "timers.h"
3
#include "timers.h"
5
 
4
 
6
void timers_init() {
5
void Timer1_Init(void) {
7
    /*--------------------Timer Delay Formulas-------------------- */
-
 
8
    /* InitTMR0 = 256 - ( Delay * Frequency ) / ( 4* Prescaler)    */
6
    T1CONbits.TMR1CS = 0x2;     // Clock source using T1OSC and T1CLK pins
9
    /* Delay = (256 - InitTMR0 * Prescaler) / (Frequency / 4)      */
7
    T1CONbits.RD16 = 0x1;       // Configure for 16-bit read/writes
10
    /* ----------------------------------------------------------- */
-
 
11
    
-
 
12
 
-
 
13
    OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_16);
8
    T1CONbits.T1OSCEN = 0x1;    // Enable crystal driver
14
    T0CONbits.TMR0ON = 0;   // Timer 0 initially off
9
    PIE1bits.TMR1IE = 0x1;      // Enable interrupt
15
 
10
 
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)
11
    // Non-applicable settings
23
    OpenTimer2(TIMER_INT_OFF & T2_PS_1_4 & T2_POST_1_1);
12
    T1CONbits.T1CKPS = 0x0;     // 1:1 prescale value
24
 
-
 
25
    // Open timer 3 for PWM IR signaling
13
    T1CONbits.NOT_T1SYNC = 0x1; // No external sync
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
14
    T1GCONbits.TMR1GE = 0x0;    // Disable gate control
29
}
15
}
30
 
16
 
31
// Interrupt handler for timer 0
17
void Timer1_Enable(void) {
32
void timer0_interrupt_handler() {
18
    T1CONbits.TMR1ON = 1;
33
    
-
 
34
}
19
}
35
 
20
 
36
void timer0_enable() {
-
 
37
    T0CONbits.TMR0ON = 1;
-
 
38
}
-
 
39
void timer0_disable() {
21
void Timer1_Disable(void) {
40
    T0CONbits.TMR0ON = 0;
22
    T1CONbits.TMR1ON = 0;
41
}
23
}
42
 
24
 
43
// Interrupt handler for timer 1
25
void Timer1_Interrupt_Handler(void) {
44
void timer1_interrupt_handler() {
26
#ifdef _TEST_TIMER1_RTC
45
    
27
    TMR1H = 0x7F;
46
}
28
    TMR1L = 0xFF;
47
 
-
 
48
void timer3_interrupt_handler() {
29
    LED_BLUE_LAT = 1;
49
 
-
 
50
}
-
 
51
 
-
 
52
void timer3_enable() {
30
    LED_RED_LAT = 1;
53
    T3CONbits.TMR3ON = 1;
31
    Delay10KTCYx(255);
54
}
-
 
55
void timer3_disable() {
32
    LED_BLUE_LAT = 0;
56
    T3CONbits.TMR3ON = 0;
33
    LED_RED_LAT = 0;
-
 
34
#endif
57
}
35
}
58
36