2,6 → 2,11 |
#include "main.h" |
#include "TIMER.h" |
|
char timer_2_pwm = 0; |
extern char LED_R_ON; |
extern char LED_G_ON; |
extern char LED_B_ON; |
|
void TIMER_1_Init(void) { |
T1CONbits.TMR1CS = 2; // Clock source is ext oscillator |
T1CONbits.T1CKPS = 0; // Prescale of 1:1 |
23,6 → 28,42 |
} |
|
void TIMER_1_Interrupt_Handler(void) { |
LED_LAT = ~LED_LAT; |
TMR1 = 0x8000; |
|
} |
|
void TIMER_2_Init(void) { |
T2CONbits.T2OUTPS = 0; // 1:1 Postscaler |
T2CONbits.TMR2ON = 0; // Timer stopped |
T2CONbits.T2CKPS = 0; // 1:1 Perscaler |
|
PIE1bits.TMR2IE = 1; // Timer 2 overflow interrupt |
} |
|
void TIMER_2_Start(void) { |
T2CONbits.TMR2ON = 1; // Start timer |
} |
|
void TIMER_2_Stop(void) { |
T2CONbits.TMR2ON = 0; // Stop timer |
} |
|
void TIMER_2_Interrupt_Handler(void) { |
// Here we manually 'PWM' the LEDs |
// Note: this is terribly inefficient but we need to do this |
// otherwise we will blow out the blue LED (max 10mA) |
if (timer_2_pwm == 0) { |
LED_R_LAT = (LED_R_ON) ? 0 : 1; |
LED_G_LAT = (LED_G_ON) ? 0 : 1; |
LED_B_LAT = (LED_B_ON) ? 0 : 1; |
} |
if (timer_2_pwm == LED_R_MAX_BRIGHTNESS) { |
LED_R_LAT = 1; |
} |
if (timer_2_pwm == LED_G_MAX_BRIGHTNESS) { |
LED_G_LAT = 1; |
} |
if (timer_2_pwm == LED_B_MAX_BRIGHTNESS) { |
LED_B_LAT = 1; |
} |
timer_2_pwm++; |
} |