Timer
Timer
* File: timer.c
* Author: Sanket
*/
#include "timer.h"
#include "interrupt.h"
#include "display.h"
/*
* Global variables
*/
#ifdef USE_TIMER_0
static uint8_t timer_0_preset;
//static uint8_t timer_0_ovf;
//static uint8_t timer_0_timeout;
//uint8_t timer_0_ovf;
uint8_t timer_0_timeout;
#endif
/*
* Private function prototypes
*/
/*
* Function definitions
*/
#ifdef USE_TIMER_0
// Stop timer.
TIMER_0_STOP();
// Backup preset.
timer_0_preset = preset;
// Reset overflow.
//timer_0_ovf = 0;
}
void timer_0_reload(const timer_0_prescale_t prescale, const uint8_t preset) {
// Stop timer.
TIMER_0_STOP();
// Prescaler settings.
OPTION_REGbits.PS = 0b000;
if (prescale == TIMER_0_PS_1_1) {
OPTION_REGbits.PSA = BIT_SET;
}
else {
OPTION_REGbits.PSA = BIT_CLR;
OPTION_REGbits.PS = (uint8_t) prescale;
}
// Backup preset.
timer_0_preset = preset;
// Preset settings.
TMR0 = timer_0_preset;
}
void timer_0_isr(void) {
// Reload timer with preset count.
TMR0 = timer_0_preset;
#if 0
if (timer_0_ovf) {
timer_0_ovf--;
if (!timer_0_ovf) {
// To Do...
}
}
#endif
if (timer_0_timeout) {
timer_0_timeout--;
}
}
#endif