-
Notifications
You must be signed in to change notification settings - Fork 1
/
Timer1.cpp
117 lines (101 loc) · 3.11 KB
/
Timer1.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "Timer1.hpp"
#include "Osc.hpp"
enum {
T1CON = 0xBF800600,
ON = 15,
SIDL = 13,
TWDIS = 12,
TWIP = 11,
TGATE = 7,
TCKPS_SHIFT = 4, TCKPS_MASK = 3,
TSYNC = 2,
TCS = 1,
TMR1 = 0xBF800610,
PR1 = 0xBF800620
};
//=============================================================================
auto Timer1::
timer (uint16_t n) -> void
{
val(TMR1, n);
}
//=============================================================================
auto Timer1::
timer () -> uint16_t
{
return val16(TMR1);
}
//=============================================================================
auto Timer1::
period (uint16_t n) -> void
{
val(PR1, n);
}
//=============================================================================
auto Timer1::
period () -> uint16_t
{
return val16(PR1);
}
//=============================================================================
auto Timer1::
on (bool tf) -> void
{
setbit(T1CON, 1<<ON, tf);
}
//=============================================================================
auto Timer1::
stop_idle (bool tf) -> void
{
setbit(T1CON, 1<<SIDL, tf);
}
//=============================================================================
auto Timer1::
wr_async (bool tf) -> void
{
setbit(T1CON, 1<<TWDIS, not tf);
}
//=============================================================================
auto Timer1::
wr_busy () -> bool
{
return anybit(T1CON, 1<<TWIP);
}
//=============================================================================
auto Timer1::
clk_src (CLK e) -> void
{
clrbit(T1CON, 1 << TCS);
setbit(T1CON, 1 << TCS, e);
}
//=============================================================================
auto Timer1::
tgate (bool tf) -> void
{
setbit(T1CON, 1<<TGATE, tf);
}
//=============================================================================
auto Timer1::
prescale (TCKPS e) -> void
{
clrbit(T1CON, TCKPS_MASK<<TCKPS_SHIFT);
setbit(T1CON, e<<TCKPS_SHIFT);
}
//=============================================================================
auto Timer1::
tsync (bool tf) -> void
{
setbit(T1CON, 1<<TSYNC, tf);
}
//=============================================================================
auto Timer1::
t1con () -> uint16_t
{
return val16(T1CON);
}
//=============================================================================
auto Timer1::
t1con (uint16_t v) -> void
{
val(T1CON, v);
}