Blame | Last modification | View Log | Download | RSS feed
#include <xc.h>#include <plib.h>#include "defines.h"#include "TIMER5.h"static void (*callback_function)(void);void TIMER5_Init(void (*callback)(void), unsigned int time_us) {callback_function = callback;int time = 5 * time_us;INTDisableInterrupts();T5CON = 0x0040; // Prescaler at 1:16, clock from peripheral clockNop();TMR5 = 0x0; // Clear timer registerPR5 = time; // Load period registerIPC5SET = 0x00000011; // Set priority level = 4, sub-priority level = 1IFS0CLR = 0x00100000; // Clear timer interrupt flagIEC0SET = 0x00100000; // Enable timer interruptINTEnableInterrupts();}void TIMER5_Start(void) {T5CONSET = 0x8000; // Start timer}void TIMER5_Stop(void) {T5CONCLR = 0x8000; // Stop timer}void __ISR(_TIMER_5_VECTOR, ipl4) __TIMER_5_Interrupt_Handler(void) {// Call the saved callback function(*callback_function)();IFS0CLR = 0x00100000; // Clear the timer interrupt flag}