-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccu.c
92 lines (79 loc) · 2.2 KB
/
ccu.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
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
/***********************************************************************
MODULE: CAPTURE COMPARE UNIT
VERSION: 1.02
CONTAINS: Routines for configuring the Capture Compare Unit on the
P89LPC936
COPYRIGHT: Embedded Systems Academy, Inc. - www.esacademy.com
LICENSE: May be freely used in commercial and non-commercial code
without royalties provided this copyright notice remains
in this file and unaltered
WARNING: IF THIS FILE IS REGENERATED BY CODE ARCHITECT ANY CHANGES
MADE WILL BE LOST. WHERE POSSIBLE USE ONLY CODE ARCHITECT
TO CHANGE THE CONTENTS OF THIS FILE
GENERATED: On "Nov 17 2010" at "02:35:06" by Code Architect 2.06
***********************************************************************/
// SFR description needs to be included
#include <reg936.h>
#include "iTrip.h"
#include "ccu.h"
extern volatile word timerCapture;
extern volatile bit DC;
/***********************************************************************
DESC: Initializes the Capture Compare Unit
basic timer, count up
Period: 4 secs
RETURNS: Nothing
CAUTION: Set EA to 1 after calling to enable interrupts
************************************************************************/
void ccu_init
(
void
)
{
//Channel A for comparator time out
CCCRA = 0x01;
OCRAH = CCU_DC >> 8;
OCRAL = CCU_DC;
//channels disabled
CCCRB = 0x00;
CCCRC = 0x00;
CCCRD = 0x00;
// reload value (up counter)
TOR2H = 0x00;
TOR2L = 0x00;
// latch shadow registers on next overflow
TCR21 |= 0x80;
// initial count
TH2 = 0x00;
TL2 = 0x00;
// timer prescaler
// divides CCUCLK by 225, CLK^-1 = 61.035 us, CLK^-1 * 2^16 = 3.99999
TPCR2H = 0x00;
TPCR2L = 0xE1;
// set interrupt priority to 0
IP1 &= ~0x10;
IP1H &= ~0x10;
//Configure and enable overflow and Channel A interrupts
// TICR2 |= 0x88;
// ECCU = 1;
// basic timer, count up
TCR20 = 0x00;
}
void start_CCU () {
// count on
TCR20 = 0x01;
}
void stop_CCU () {
//count off
TCR20 = 0x00;
}
void ccu_isr
(
void
) interrupt 11 using 3
{
//Clear interrupt flag
TIFR2 &= ~0x88;
// ++timerCapture;
// DC = 1;
}