-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.c
More file actions
78 lines (61 loc) · 1.43 KB
/
timer.c
File metadata and controls
78 lines (61 loc) · 1.43 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <msp430.h>
#include "ini.h"
#include "timer.h"
#include "in_out.h"
void init_timer(void)
{
TACTL = TACLR; // Timer_A clear
TACCTL0 = CM_0; // No capture
TACCTL1 = CM_0;
TACCR2 = 10000; // 10 ms
TACCTL2 = OUTMOD_4 + CCIE; // Output is toggled when the timer counts to the TACCRx value
TACTL = TASSEL_2 + MC_2 + ID_1 + TAIE; // ACLK, cont. mode, divide by 8 => 1 MHz, timer owerflow interrupt enabled,
}
void TimerA0_start( void )
{
TACCTL0 &= ~CCIE; // disable TA0
TACCTL0 &= ~( CCIFG | COV ); // clear flags
TACCR0 = TAR + 1000; // 1 ms
TACCTL0 |= CCIE;
time_1ms = 0;
}
#pragma vector = TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
TACCR0 += 1000;
time_1ms++; // increase miliseconds
}
// Timer_A3 Interrupt Vector (TAIV) handler
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A1(void)
{
switch( TAIV )
{
case 2: // TACCR1
{
break;
}
case 4:
{
TACCR2 = 9900; // 10ms Add Offset to CCR2
//------------------------------------------------
// Time ( 10 ms, 200ms, 1 second )
//------------------------------------------------
time_10ms++;
if( ( time_10ms % 20 ) == 0 )
{
time_200ms_flag = 1;
}
if( time_10ms >= 100 )
{
time_10ms = 0;
time_seconds++;
}
break;
}
case 10:
{
break;
}
}
}