Solar panel
Loading...
Searching...
No Matches
tmr2.c
Go to the documentation of this file.
1
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
51#include <xc.h>
52#include "tmr2.h"
53
63{
64 // Set TMR2 to the options selected in the User Interface
65
66 // PR2 255;
67 PR2 = 0xFF;
68
69 // TMR2 0;
70 TMR2 = 0x00;
71
72 // Clearing IF flag.
73 PIR1bits.TMR2IF = 0;
74
75 // T2CKPS 1:1; TOUTPS 1:1; TMR2ON on;
76 T2CON = 0x04;
77}
78
80{
81 // Start the Timer by writing to TMRxON bit
82 T2CONbits.TMR2ON = 1;
83}
84
86{
87 // Stop the Timer by writing to TMRxON bit
88 T2CONbits.TMR2ON = 0;
89}
90
91uint8_t TMR2_ReadTimer(void)
92{
93 uint8_t readVal;
94
95 readVal = TMR2;
96
97 return readVal;
98}
99
100void TMR2_WriteTimer(uint8_t timerVal)
101{
102 // Write to the Timer2 register
103 TMR2 = timerVal;
104}
105
106void TMR2_LoadPeriodRegister(uint8_t periodVal)
107{
108 PR2 = periodVal;
109}
110
112{
113 // check if overflow has occurred by checking the TMRIF bit
114 bool status = PIR1bits.TMR2IF;
115 if(status)
116 {
117 // Clearing IF flag.
118 PIR1bits.TMR2IF = 0;
119 }
120 return status;
121}
void TMR2_StopTimer(void)
Definition: tmr2.c:85
void TMR2_Initialize(void)
Definition: tmr2.c:62
uint8_t TMR2_ReadTimer(void)
Definition: tmr2.c:91
void TMR2_LoadPeriodRegister(uint8_t periodVal)
Definition: tmr2.c:106
bool TMR2_HasOverflowOccured(void)
Definition: tmr2.c:111
void TMR2_WriteTimer(uint8_t timerVal)
Definition: tmr2.c:100
void TMR2_StartTimer(void)
Definition: tmr2.c:79