-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathinterrupts.c
More file actions
111 lines (90 loc) · 2.67 KB
/
interrupts.c
File metadata and controls
111 lines (90 loc) · 2.67 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
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
/*
* -----------------------------------------------------------------------------
* ----- INTERRUPTS.C -----
* ----- EASYPAY -----
* -----------------------------------------------------------------------------
*
* File Description:
* This file contains setup for interrupts
*
* Table of Contents:
* Tmr0Init - Initialize Timer0
* Tmr2Init - Initialize Timer2
*
* Assumptions:
* None
*
* Compiler:
* HI-TECH C Compiler for PIC18 MCUs (http://www.htsoft.com/)
*
* Revision History:
* Dec. 19, 2012 Nnoduka Eruchalu Initial Revision
* Apr. 26, 2013 Nnoduka Eruchalu Added Tmr2Init
*/
#include <htc.h>
#include "interrupts.h"
/*
* Tmr0Init
* Description: Initialize Tmr0 to generate 0.889ms periods
*
* Arguments: None
* Return: None
*
* Operation: Setup T0CON.
* Setup INTCON: T0IE, T0IF
*
* Revision History:
* Dec. 19, 2012 Nnoduka Eruchalu Initial Revision
*/
void Tmr0Init(void)
{
/* configure Timer0 as follows:
Period = 1 / [(Processor Frequency)/4] = 1 / (18.432MHz/4) = 217nS
PreScalar = 16
n = 8 bit timer
Time between Interrupts = Period * PreScaler * 2^n = 0.889 ms
*/
T0PS0 = 1; /* prescale is divide by 16 */
T0PS1 = 1;
T0PS2 = 0;
PSA = 0; /* Timer0 clock source is from prescaler */
T0CS = 0; /* use internal clock (Fosc/4) */
T08BIT = 1; /* 8 bit timer/counter */
TMR0 = 0; /* Clear the TMR0 register */
TMR0IF = 0;
TMR0IE = 1; /* enable TIMER0 overflow interrupts */
TMR0ON = 1; /* now start the timer */
}
/*
* Tmr2Init
* Description: Initialize Tmr2 to generate 0.5ms periods
*
* Arguments: None
* Return: None
*
* Operation: Setup T2CON.
* Setup INTCON: T2IE, T2IF
*
* Revision History:
* Apr. 26, 2013 Nnoduka Eruchalu Initial Revision
*/
void Tmr2Init(void)
{
/* configure Timer2 as follows:
Period = 1 / [(Processor Frequency)/4] = 1 / (18.432MHz/4) = 217nS
PreScalar = 16
PR2 = 144
Time between Interrupts = Period * PreScaler * PR2 = 0.5ms
*/
T2CKPS0 = 1; /* prescale is divide by 16 */
T2CKPS1 = 1;
T2OUTPS0 = 0; /* postscale is 1:1 */
T2OUTPS1 = 0;
T2OUTPS2 = 0;
T2OUTPS3 = 0;
PR2 = 144;
TMR2 = 0; /* Clear the TMR2 register */
TMR2IF = 0;
TMR2IE = 1; /* enable TIMER2 overflow interrupts */
TMR2ON = 1; /* now start the timer */
}