2,12 → 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_callback)(void); |
void (*timer_2_callback)(void); |
|
void TIMER_1_Init(void) { |
void TIMER_1_Init(void (*callback)(void)) { |
timer_1_callback = callback; |
T1CONbits.TMR1CS = 2; // Clock source is ext oscillator |
T1CONbits.T1CKPS = 0; // Prescale of 1:1 |
T1CONbits.T1OSCEN = 1; // Dedicated oscillator circuit enabled |
28,15 → 27,17 |
} |
|
void TIMER_1_Interrupt_Handler(void) { |
|
timer_1_callback(); |
TMR1 = 0x8000; |
} |
|
void TIMER_2_Init(void) { |
T2CONbits.T2OUTPS = 0; // 1:1 Postscaler |
T2CONbits.TMR2ON = 0; // Timer stopped |
T2CONbits.T2CKPS = 0; // 1:1 Perscaler |
void TIMER_2_Init(void (*callback)(void)) { |
timer_2_callback = callback; |
T2CONbits.T2OUTPS = 0; // 1:1 Postscaler |
T2CONbits.TMR2ON = 0; // Timer stopped |
T2CONbits.T2CKPS = 0; // 1:1 Perscaler |
|
PIE1bits.TMR2IE = 1; // Timer 2 overflow interrupt |
PIE1bits.TMR2IE = 1; // Timer 2 overflow interrupt |
} |
|
void TIMER_2_Start(void) { |
48,22 → 49,5 |
} |
|
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++; |
timer_2_callback(); |
} |