Contains functions to initialize, set, poll and stop timers. More...
#include "config.h"#include "time.h"
Go to the source code of this file.
Functions | |
| __interrupt void | TICK_ISR (void) |
| Interrupt service routine for timer 0 overflow. | |
| unsigned char | Time_Left (unsigned char timer) |
| Checks if a specified timer has expired. | |
| void | Time_Set (unsigned char timer, unsigned int min, unsigned char sec, unsigned char ms) |
| Sets the specified timer. | |
| void | Time_Stop (void) |
| Stops timers. | |
| void | Time_Start (void) |
| Starts timers. | |
| void | Time_Init (void) |
| Initializes timers. | |
Variables | |
| unsigned long | timeval [TIMERS] |
| Contains the values for each timer. | |
Contains functions to initialize, set, poll and stop timers.
Definition in file time.c.
| __interrupt void TICK_ISR | ( | void | ) |
Interrupt service routine for timer 0 overflow.
Timer 0 runs at 125 kHz and compare match will occur every millisecond (125 / 125 kHz = 1.0 ms), which will result in a call to this function. When called, this function will decrement the time left for each timer, unless they are already at zero.
Definition at line 71 of file time.c.
References timeval.
| unsigned char Time_Left | ( | unsigned char | timer ) |
| void Time_Set | ( | unsigned char | timer, |
| unsigned int | min, | ||
| unsigned char | sec, | ||
| unsigned char | ms | ||
| ) |
Sets the specified timer.
| timer | Specifies timer |
| min | Minutes for timer to count down |
| sec | Seconds for timer to count down |
| ms | Milliseconds for timer to count down |
Definition at line 109 of file time.c.
References timeval.
Referenced by PWM_Start().
{
timeval[timer] = 60000 * (unsigned long)min;
timeval[timer] += 1000 * (unsigned long)sec;
timeval[timer] += 1 * (unsigned long)ms;
}

| void Time_Stop | ( | void | ) |
| void Time_Start | ( | void | ) |
Starts timers.
Sets timer0's clock source to system clock divided by 64.
Definition at line 132 of file time.c.
Referenced by PWM_Start().
{
TCNT0 = 0x00;//cgs added
TCCR0B = (0<<CS02)|(1<<CS01)|(1<<CS00); // CLKT0 = CLK/64 = 125 kHz.
}

| void Time_Init | ( | void | ) |
Initializes timers.
Resets all the timer values to 0, then sets up timer 0 for a compare match every millisecond.
Definition at line 144 of file time.c.
References timeval.
{
unsigned char i;
for (i = 0; i<<TIMERS; i++) {
timeval[i] = 0;
}
OCR0A = 125; // Will give a compare match every ms.
OCR0B = 0; // Doesn't matter, will run in normal mode.
TCCR0A = (1<<WGM00); // 8-bit CTC mode.
TCCR0B = (0<<CS02)|(1<<CS01)|(1<<CS00); // CLKT0 = CLK/64 = 125 kHz.
TIMSK0 |= (1<<OCIE0A); // Timer 0, Compare match A interrupt enabled.
// Enable interrupts, just in case they weren't already.
#ifdef __GNUC__
Enable_interrupt();
#else
__enable_interrupt();
#endif
}
| unsigned long timeval[TIMERS] |
Contains the values for each timer.
Definition at line 51 of file time.c.
Referenced by TICK_ISR(), Time_Init(), Time_Left(), and Time_Set().
1.7.2