-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht1open.c
97 lines (77 loc) · 2.56 KB
/
t1open.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
93
94
95
96
#include <p18cxxx.h>
#include "timers.h"
/********************************************************************
* Function Name: OpenTimer1 *
* Return Value: void *
* Parameters: config: bit definitions to configure Timer1 *
* Description: This routine first resets the Timer1 regs *
* to the POR state and then configures the *
* interrupt, clock source and 8/16-bit mode. *
* Notes: The bit definitions for config can be found *
* in the timers.h file. *
********************************************************************/
#if defined (TMR_V1) || defined (TMR_V2) || defined (TMR_V3) ||\
defined (TMR_V4) || defined (TMR_V5)
void OpenTimer1(unsigned char config)
{
T1CON = (0x7e & config); // Set everything except 8/16 mode, and
// don't start timer yet
if( config & 0x40 ) // The 8/16 selection bit isn't in the
T1CONbits.RD16 = 1; // right place -- we have to move it
else
T1CONbits.RD16 = 0;
TMR1H=0; // Clear out timer registers
TMR1L=0;
PIR1bits.TMR1IF=0;
if(config&0x80) // Enable interrupts if selected
PIE1bits.TMR1IE=1;
else
PIE1bits.TMR1IE=0;
T1CONbits.TMR1ON = 1; // Start Timer1
}
#endif
#if defined (TMR_V6) || defined (TMR_V7) || defined (TMR_V7_1)\
|| defined (TMR_V7_2) || defined (TMR_V7_3) || defined (TMR_V7_4) || defined (TMR_V7_5)
void OpenTimer1(unsigned char config, unsigned char config1)
{
T1GCON = (0XF3 & config1);
T1CON = (0x7F & config) << 1 ;
TMR1H=0; // Clear out timer registers
TMR1L=0;
PIR1bits.TMR1IF=0;
if(config&0x80) // Enable interrupts if selected
PIE1bits.TMR1IE=1;
else
PIE1bits.TMR1IE=0;
#ifndef TMR_V6
#if defined(TMR_INT_V2) || defined (TMR_INT_V7_3) || defined (TMR_INT_V7_5)
PIR3bits.TMR1GIF =0;
#elif defined(TMR_V7_1_INT_V1)
PIR5bits.TMR1GIF =0;
#else
PIR1bits.TMR1GIF =0;
#endif
#endif
#ifndef TMR_V6
#if defined(TMR_INT_V2) || defined (TMR_INT_V7_3) || defined (TMR_INT_V7_5)
if(config1 & 0x04)
PIE3bits.TMR1GIE=1;
else
PIE3bits.TMR1GIE=0;
#elif defined(TMR_V7_1_INT_V1)
if(config1 & 0x04)
PIE5bits.TMR1GIE=1;
else
PIE5bits.TMR1GIE=0;
#else
if(config1 & 0x04)
PIE1bits.TMR1GIE=1;
else
PIE1bits.TMR1GIE=0;
#endif
#endif
if(T1GCONbits.TMR1GE)
T1GCONbits.T1GGO = 1;
T1CONbits.TMR1ON = 1; // Start Timer1
}
#endif