ReflexBall Rally
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Macros
time.c
Go to the documentation of this file.
1
#include <eZ8.h>
// special encore constants, macros and flash routines
2
#include <sio.h>
// special encore serial i/o routines
3
#include "
time.h
"
4
#include "
ansi.h
"
5
6
volatile
unsigned
long
delayTimer
,
mscounter
;
7
8
void
initTimers
() {
// Initialize Timer1 to interrupt every 1ms
9
DI();
// Disable interrupt
10
11
T1CTL = 0;
// TEN - disable timer
12
T1CTL |=
PRE1
;
// PRES - Prescaler
13
T1CTL |= (1 << 0);
// TMODE - continuous mode
14
15
T1H = 0;
16
T1L = 1;
17
18
T1RH = 18432 >> 8;
// Interrupt every 1ms
19
T1RL = 18432 & 0xFF;
20
21
SET_VECTOR(TIMER1,
timer1int
);
// Enter the timer1int function at each interrupt
22
23
// Set timer1 priority to high
24
IRQ0ENH |=
PRIORITY_TIMER1
;
25
IRQ0ENL |=
PRIORITY_TIMER1
;
26
27
delayTimer
= 0;
28
mscounter
= 0;
29
30
T1CTL |= (1 << 7);
// TEN - enable timer
31
32
EI();
// Enable interrupt
33
}
34
35
unsigned
long
millis
() {
// Get the time since program start in ms
36
return
mscounter
;
37
}
38
39
void
delay_ms
(
unsigned
long
time) {
// Delay in ms - this is not that acurate, but good enough for our needs
40
delayTimer
= time;
41
while
(
delayTimer
);
42
}
43
44
#pragma interrupt
45
void
timer1int
() {
// Interrupt function
46
delayTimer
--;
47
mscounter
++;
48
}
Generated by
1.8.4