Rev 223 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#include <xc.h>#include "main.h"#include "TIMER.h"void (*timer_1_callback)(void);void (*timer_2_callback)(void);void TIMER_1_Init(void (*callback)(void)) {timer_1_callback = callback;T1CONbits.TMR1CS = 2; // Clock source is ext oscillatorT1CONbits.T1CKPS = 0; // Prescale of 1:1T1CONbits.T1OSCEN = 1; // Dedicated oscillator circuit enabledT1CONbits.nT1SYNC = 1; // Async external clock inputT1CONbits.TMR1ON = 0; // Timer stoppedT1GCONbits.TMR1GE = 0; // Gate disabledTMR1 = 0x8000;PIE1bits.TMR1IE = 1; // Timer 1 overflow interrupt}void TIMER_1_Start(void) {T1CONbits.TMR1ON = 1; // Start timer}void TIMER_1_Stop(void) {T1CONbits.TMR1ON = 0; // Stop timer}void TIMER_1_Interrupt_Handler(void) {timer_1_callback();TMR1 = 0x8000;}void TIMER_2_Init(void (*callback)(void)) {timer_2_callback = callback;T2CONbits.T2OUTPS = 0; // 1:1 PostscalerT2CONbits.TMR2ON = 0; // Timer stoppedT2CONbits.T2CKPS = 0; // 1:1 PerscalerPIE1bits.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) {timer_2_callback();}