| 329 |
Kevin |
1 |
#include "defines.h"
|
|
|
2 |
#include "TIMER.h"
|
|
|
3 |
|
|
|
4 |
void TIMER1_Init(void) {
|
|
|
5 |
T1CONbits.TMR1CS = 0x0; // Clock source is instruction clock
|
|
|
6 |
T1CONbits.T1CKPS = 0x3; // Prescale of 1:8
|
|
|
7 |
T1CONbits.T1OSCEN = 0x0; // Dedicated oscillator circuit disabled
|
|
|
8 |
T1CONbits.nT1SYNC = 0x0; // Sync clock input with system clock
|
|
|
9 |
T1CONbits.TMR1ON = 0; // Timer starts off
|
|
|
10 |
T1GCONbits.TMR1GE = 0; // Gate disabled
|
|
|
11 |
TMR1 = 0x0;
|
|
|
12 |
|
|
|
13 |
PIE1bits.TMR1IE = 0; // Interrupt disabled
|
|
|
14 |
|
|
|
15 |
// Instruction clock running at 8MHz
|
|
|
16 |
// 1:1 Prescale overflows at 122Hz (8.2ms period)
|
|
|
17 |
// 1:2 Prescale overflows at 61Hz (16.4ms period)
|
|
|
18 |
// 1:4 Prescale overflows at 30.5Hz (32.7ms period)
|
|
|
19 |
// 1:8 Prescale overflows at 15.3Hz (65.5ms period)
|
|
|
20 |
|
|
|
21 |
// Instruction clock running at 4MHz
|
|
|
22 |
// 1:1 Prescale overflows at 61Hz (16.4ms period)
|
|
|
23 |
// 1:2 Prescale overflows at 30.5Hz (32.7ms period)
|
|
|
24 |
// 1:4 Prescale overflows at 15.3Hz (65.5ms period)
|
|
|
25 |
// 1:8 Prescale overflows at 7.6Hz (131.1ms period)
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
void TIMER1_Start(void) {
|
|
|
29 |
TMR1 = 0x0;
|
|
|
30 |
T1CONbits.TMR1ON = 1;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
void TIMER1_Stop(void) {
|
|
|
34 |
T1CONbits.TMR1ON = 0;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
uint16_t TIMER1_Read(void) {
|
|
|
38 |
return TMR1;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
void TIMER1_Interrupt_Handler(void) {
|
|
|
42 |
|
|
|
43 |
}
|