1 |
/** |
---|
2 |
TMR0 Generated Driver File |
---|
3 |
|
---|
4 |
@Company |
---|
5 |
Microchip Technology Inc. |
---|
6 |
|
---|
7 |
@File Name |
---|
8 |
tmr0.c |
---|
9 |
|
---|
10 |
@Summary |
---|
11 |
This is the generated driver implementation file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs |
---|
12 |
|
---|
13 |
@Description |
---|
14 |
This source file provides APIs for TMR0. |
---|
15 |
Generation Information : |
---|
16 |
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.65.2 |
---|
17 |
Device : PIC16F1579 |
---|
18 |
Driver Version : 2.01 |
---|
19 |
The generated drivers are tested against the following: |
---|
20 |
Compiler : XC8 1.45 |
---|
21 |
MPLAB : MPLAB X 4.15 |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
/* |
---|
25 |
(c) 2018 Microchip Technology Inc. and its subsidiaries. |
---|
26 |
|
---|
27 |
Subject to your compliance with these terms, you may use Microchip software and any |
---|
28 |
derivatives exclusively with Microchip products. It is your responsibility to comply with third party |
---|
29 |
license terms applicable to your use of third party software (including open source software) that |
---|
30 |
may accompany Microchip software. |
---|
31 |
|
---|
32 |
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER |
---|
33 |
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY |
---|
34 |
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS |
---|
35 |
FOR A PARTICULAR PURPOSE. |
---|
36 |
|
---|
37 |
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, |
---|
38 |
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND |
---|
39 |
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP |
---|
40 |
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO |
---|
41 |
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL |
---|
42 |
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT |
---|
43 |
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS |
---|
44 |
SOFTWARE. |
---|
45 |
*/ |
---|
46 |
|
---|
47 |
/** |
---|
48 |
Section: Included Files |
---|
49 |
*/ |
---|
50 |
|
---|
51 |
#include <xc.h> |
---|
52 |
#include "tmr0.h" |
---|
53 |
|
---|
54 |
/** |
---|
55 |
Section: Global Variables Definitions |
---|
56 |
*/ |
---|
57 |
|
---|
58 |
volatile uint8_t timer0ReloadVal; |
---|
59 |
void (*TMR0_InterruptHandler)(void); |
---|
60 |
/** |
---|
61 |
Section: TMR0 APIs |
---|
62 |
*/ |
---|
63 |
|
---|
64 |
void TMR0_Initialize(void) |
---|
65 |
{ |
---|
66 |
// Set TMR0 to the options selected in the User Interface |
---|
67 |
|
---|
68 |
// PSA assigned; PS 1:8; TMRSE Increment_hi_lo; mask the nWPUEN and INTEDG bits |
---|
69 |
OPTION_REG = (uint8_t)((OPTION_REG & 0xC0) | (0xD2 & 0x3F)); |
---|
70 |
|
---|
71 |
// TMR0 6; |
---|
72 |
TMR0 = 0x06; |
---|
73 |
|
---|
74 |
// Load the TMR value to reload variable |
---|
75 |
timer0ReloadVal= 6; |
---|
76 |
|
---|
77 |
// Clear Interrupt flag before enabling the interrupt |
---|
78 |
INTCONbits.TMR0IF = 0; |
---|
79 |
|
---|
80 |
// Enabling TMR0 interrupt |
---|
81 |
INTCONbits.TMR0IE = 1; |
---|
82 |
|
---|
83 |
// Set Default Interrupt Handler |
---|
84 |
TMR0_SetInterruptHandler(TMR0_DefaultInterruptHandler); |
---|
85 |
} |
---|
86 |
|
---|
87 |
uint8_t TMR0_ReadTimer(void) |
---|
88 |
{ |
---|
89 |
uint8_t readVal; |
---|
90 |
|
---|
91 |
readVal = TMR0; |
---|
92 |
|
---|
93 |
return readVal; |
---|
94 |
} |
---|
95 |
|
---|
96 |
void TMR0_WriteTimer(uint8_t timerVal) |
---|
97 |
{ |
---|
98 |
// Write to the Timer0 register |
---|
99 |
TMR0 = timerVal; |
---|
100 |
} |
---|
101 |
|
---|
102 |
void TMR0_Reload(void) |
---|
103 |
{ |
---|
104 |
// Write to the Timer0 register |
---|
105 |
TMR0 = timer0ReloadVal; |
---|
106 |
} |
---|
107 |
|
---|
108 |
void TMR0_ISR(void) |
---|
109 |
{ |
---|
110 |
|
---|
111 |
// Clear the TMR0 interrupt flag |
---|
112 |
INTCONbits.TMR0IF = 0; |
---|
113 |
|
---|
114 |
TMR0 = timer0ReloadVal; |
---|
115 |
|
---|
116 |
if(TMR0_InterruptHandler) |
---|
117 |
{ |
---|
118 |
TMR0_InterruptHandler(); |
---|
119 |
} |
---|
120 |
|
---|
121 |
// add your TMR0 interrupt custom code |
---|
122 |
} |
---|
123 |
|
---|
124 |
|
---|
125 |
void TMR0_SetInterruptHandler(void (* InterruptHandler)(void)){ |
---|
126 |
TMR0_InterruptHandler = InterruptHandler; |
---|
127 |
} |
---|
128 |
|
---|
129 |
void TMR0_DefaultInterruptHandler(void){ |
---|
130 |
// add your TMR0 interrupt custom code |
---|
131 |
// or set custom function using TMR0_SetInterruptHandler() |
---|
132 |
} |
---|
133 |
|
---|
134 |
/** |
---|
135 |
End of File |
---|
136 |
*/ |
---|