Subversion Repositories Code-Repo

Rev

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

Rev 202 Rev 222
Line 1... Line 1...
1
#include <xc.h>
1
#include <xc.h>
2
#include "main.h"
2
#include "main.h"
3
#include "TIMER.h"
3
#include "TIMER.h"
4
 
4
 
-
 
5
char timer_2_pwm = 0;
-
 
6
extern char LED_R_ON;
-
 
7
extern char LED_G_ON;
-
 
8
extern char LED_B_ON;
-
 
9
 
5
void TIMER_1_Init(void) {
10
void TIMER_1_Init(void) {
6
    T1CONbits.TMR1CS = 2;   // Clock source is ext oscillator
11
    T1CONbits.TMR1CS = 2;   // Clock source is ext oscillator
7
    T1CONbits.T1CKPS = 0;   // Prescale of 1:1
12
    T1CONbits.T1CKPS = 0;   // Prescale of 1:1
8
    T1CONbits.T1OSCEN = 1;  // Dedicated oscillator circuit enabled
13
    T1CONbits.T1OSCEN = 1;  // Dedicated oscillator circuit enabled
9
    T1CONbits.nT1SYNC = 1;  // Async external clock input
14
    T1CONbits.nT1SYNC = 1;  // Async external clock input
Line 21... Line 26...
21
void TIMER_1_Stop(void) {
26
void TIMER_1_Stop(void) {
22
    T1CONbits.TMR1ON = 0;   // Stop timer
27
    T1CONbits.TMR1ON = 0;   // Stop timer
23
}
28
}
24
 
29
 
25
void TIMER_1_Interrupt_Handler(void) {
30
void TIMER_1_Interrupt_Handler(void) {
-
 
31
    
-
 
32
}
-
 
33
 
26
    LED_LAT = ~LED_LAT;
34
void TIMER_2_Init(void) {
-
 
35
    T2CONbits.T2OUTPS = 0;    // 1:1 Postscaler
27
    TMR1 = 0x8000;
36
    T2CONbits.TMR2ON = 0;       // Timer stopped
-
 
37
    T2CONbits.T2CKPS = 0;    // 1:1 Perscaler
-
 
38
 
-
 
39
    PIE1bits.TMR2IE = 1;   // Timer 2 overflow interrupt
28
}
40
}
-
 
41
 
-
 
42
void TIMER_2_Start(void) {
-
 
43
    T2CONbits.TMR2ON = 1;   // Start timer
-
 
44
}
-
 
45
 
-
 
46
void TIMER_2_Stop(void) {
-
 
47
    T2CONbits.TMR2ON = 0;   // Stop timer
-
 
48
}
-
 
49
 
-
 
50
void TIMER_2_Interrupt_Handler(void) {
-
 
51
    // Here we manually 'PWM' the LEDs
-
 
52
    // Note: this is terribly inefficient but we need to do this
-
 
53
    //  otherwise we will blow out the blue LED (max 10mA)
-
 
54
    if (timer_2_pwm == 0) {
-
 
55
        LED_R_LAT = (LED_R_ON) ? 0 : 1;
-
 
56
        LED_G_LAT = (LED_G_ON) ? 0 : 1;
-
 
57
        LED_B_LAT = (LED_B_ON) ? 0 : 1;
-
 
58
    } 
-
 
59
    if (timer_2_pwm == LED_R_MAX_BRIGHTNESS) {
-
 
60
        LED_R_LAT = 1;
-
 
61
    }
-
 
62
    if (timer_2_pwm == LED_G_MAX_BRIGHTNESS) {
-
 
63
        LED_G_LAT = 1;
-
 
64
    }
-
 
65
    if (timer_2_pwm == LED_B_MAX_BRIGHTNESS) {
-
 
66
        LED_B_LAT = 1;
-
 
67
    }
-
 
68
    timer_2_pwm++;
-
 
69
}
29
70