-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.c
62 lines (54 loc) · 1.46 KB
/
time.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "eggs.h"
volatile unsigned int timerSleep = 0;
void sleep(unsigned int centaseconds)
{
timerSleep = centaseconds;
#ifndef VLOCLK12Khz
#ifndef VLOCLK32Khz
__bis_SR_register((CPUOFF + SCG0 + GIE)); // LPM1 with interrupts enabled
#endif
#endif
#ifdef VLOCLK32Khz
__bis_SR_register((CPUOFF + SCG0 + SCG1 + GIE)); // LPM3 with interrupts enabled
#endif
#ifdef VLOCLK12Khz
__bis_SR_register((CPUOFF + SCG0 + SCG1 + GIE)); // LPM3 with interrupts enabled
#endif
}
void setup_time()
{
//8 MHz = 8,000,000 cycles per second
//8,000,000 / 100 = 80,000
#ifndef VLOCLK12Khz
#ifndef VLOCLK32Khz
TA0CCR0 = 80000;// 100 interrupts per second
TA0CTL = TASSEL_2 + MC_1; // Set the timer A to SMCLCK, Continuous
// Clear the timer and enable timer interrupt
#endif
#endif
#ifdef VLOCLK32Khz
// Clock is 32768
TA0CCR0 = 328; // 100 Interrupts per second
TA0CTL = TASSEL_1 + MC_1;
#endif
#ifdef VLOCLK12Khz
// Clock is roughly 12 Khz per second
TA0CCR0 = 120; // 100 interrupts per second
TA0CTL = TASSEL_1 + MC_1; // Set the timer A to ALCK, Continuous
#endif
}
// Timer A0 interrupt service routine
// Occurs every 1/100th of a second
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
time_event();
if (timerSleep != 0)
{
timerSleep --;
if (timerSleep == 0)
{
LPM4_EXIT;
}
}
}