pwm
This commit is contained in:
@ -65,8 +65,8 @@ void ADC_Initialize(void)
|
||||
// VCFG1 VSS; VCFG0 VDD;
|
||||
ADCON1 = 0x00;
|
||||
|
||||
// ADFM left; ACQT 0; ADCS FOSC/2;
|
||||
ADCON2 = 0x00;
|
||||
// ADFM right; ACQT 0; ADCS FOSC/2;
|
||||
ADCON2 = 0x80;
|
||||
|
||||
// ADRESL 0;
|
||||
ADRESL = 0x00;
|
||||
|
96
solar_panel.X/mcc_generated_files/epwm1.c
Normal file
96
solar_panel.X/mcc_generated_files/epwm1.c
Normal file
@ -0,0 +1,96 @@
|
||||
/**
|
||||
EPWM1 Generated Driver File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
epwm1.c
|
||||
|
||||
@Summary
|
||||
This is the generated driver implementation file for the EPWM1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This source file provides implementations for driver APIs for EPWM1.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F97J60
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <xc.h>
|
||||
#include "epwm1.h"
|
||||
|
||||
/**
|
||||
Section: Macro Declarations
|
||||
*/
|
||||
|
||||
#define PWM1_INITIALIZE_DUTY_VALUE 511
|
||||
|
||||
/**
|
||||
Section: EPWM Module APIs
|
||||
*/
|
||||
|
||||
void EPWM1_Initialize(void)
|
||||
{
|
||||
// Set the EPWM1 to the options selected in the User Interface
|
||||
|
||||
// CCP1M P1A,P1C: active high; P1B,P1D: active high; DC1B 3; P1M single;
|
||||
CCP1CON = 0x3C;
|
||||
|
||||
// ECCPASE operating; PSSBD P1BP1D_0; PSSAC P1AP1C_0; ECCPAS disabled;
|
||||
ECCP1AS = 0x00;
|
||||
|
||||
// P1RSEN automatic_restart; P1DC0 0;
|
||||
ECCP1DEL = 0x80;
|
||||
|
||||
// CCPR1H 0;
|
||||
CCPR1H = 0x00;
|
||||
|
||||
// CCPR1L 127;
|
||||
CCPR1L = 0x7F;
|
||||
|
||||
}
|
||||
|
||||
void EPWM1_LoadDutyValue(uint16_t dutyValue)
|
||||
{
|
||||
// Writing to 8 MSBs of pwm duty cycle in CCPRL register
|
||||
CCPR1L = ((dutyValue & 0x03FC)>>2);
|
||||
|
||||
// Writing to 2 LSBs of pwm duty cycle in CCPCON register
|
||||
CCP1CON = ((uint8_t)(CCP1CON & 0xCF) | ((dutyValue & 0x0003)<<4));
|
||||
}
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
|
133
solar_panel.X/mcc_generated_files/epwm1.h
Normal file
133
solar_panel.X/mcc_generated_files/epwm1.h
Normal file
@ -0,0 +1,133 @@
|
||||
/**
|
||||
EPWM1 Generated Driver File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
epwm1.h
|
||||
|
||||
@Summary
|
||||
This is the generated driver implementation file for the EPWM1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This header file provides implementations for driver APIs for EPWM1.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F97J60
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EPWM1_H
|
||||
#define EPWM1_H
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <xc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
Section: EPWM Module APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Initializes the EPWM1
|
||||
|
||||
@Description
|
||||
This routine initializes the EPWM1 module.
|
||||
This routine must be called before any other EPWM1 routine is called.
|
||||
This routine should only be called once during system initialization.
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Comment
|
||||
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint16_t dutycycle;
|
||||
|
||||
ECCP1_Initialize();
|
||||
EPWM1_LoadDutyValue(dutycycle);
|
||||
</code>
|
||||
*/
|
||||
void EPWM1_Initialize(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Loads 16-bit duty cycle.
|
||||
|
||||
@Description
|
||||
This routine loads the 16 bit duty cycle value.
|
||||
|
||||
@Preconditions
|
||||
EPWM1_Initialize() function should have been called before calling this function.
|
||||
|
||||
@Param
|
||||
Pass 16bit duty cycle value.
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint16_t dutycycle;
|
||||
|
||||
EPWM1_Initialize();
|
||||
EPWM1_LoadDutyValue(dutycycle);
|
||||
</code>
|
||||
*/
|
||||
void EPWM1_LoadDutyValue(uint16_t dutyValue);
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif //EPWM1_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
@ -52,6 +52,8 @@ void SYSTEM_Initialize(void)
|
||||
|
||||
PIN_MANAGER_Initialize();
|
||||
OSCILLATOR_Initialize();
|
||||
EPWM1_Initialize();
|
||||
TMR2_Initialize();
|
||||
ADC_Initialize();
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,8 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <conio.h>
|
||||
#include "epwm1.h"
|
||||
#include "tmr2.h"
|
||||
#include "adc.h"
|
||||
|
||||
|
||||
|
@ -71,7 +71,7 @@ void PIN_MANAGER_Initialize(void)
|
||||
TRISG = 0xFF;
|
||||
TRISB = 0xFF;
|
||||
TRISH = 0xFF;
|
||||
TRISC = 0xFF;
|
||||
TRISC = 0xFB;
|
||||
TRISD = 0xFF;
|
||||
TRISJ = 0xFF;
|
||||
|
||||
|
@ -67,6 +67,14 @@
|
||||
#define PULL_UP_ENABLED 1
|
||||
#define PULL_UP_DISABLED 0
|
||||
|
||||
// get/set RC2 procedures
|
||||
#define RC2_SetHigh() do { LATCbits.LATC2 = 1; } while(0)
|
||||
#define RC2_SetLow() do { LATCbits.LATC2 = 0; } while(0)
|
||||
#define RC2_Toggle() do { LATCbits.LATC2 = ~LATCbits.LATC2; } while(0)
|
||||
#define RC2_GetValue() PORTCbits.RC2
|
||||
#define RC2_SetDigitalInput() do { TRISCbits.TRISC2 = 1; } while(0)
|
||||
#define RC2_SetDigitalOutput() do { TRISCbits.TRISC2 = 0; } while(0)
|
||||
|
||||
// get/set voltage aliases
|
||||
#define voltage_TRIS TRISFbits.TRISF0
|
||||
#define voltage_LAT LATFbits.LATF0
|
||||
|
124
solar_panel.X/mcc_generated_files/tmr2.c
Normal file
124
solar_panel.X/mcc_generated_files/tmr2.c
Normal file
@ -0,0 +1,124 @@
|
||||
/**
|
||||
TMR2 Generated Driver File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
tmr2.c
|
||||
|
||||
@Summary
|
||||
This is the generated driver implementation file for the TMR2 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This source file provides APIs for TMR2.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F97J60
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <xc.h>
|
||||
#include "tmr2.h"
|
||||
|
||||
/**
|
||||
Section: Global Variables Definitions
|
||||
*/
|
||||
|
||||
/**
|
||||
Section: TMR2 APIs
|
||||
*/
|
||||
|
||||
void TMR2_Initialize(void)
|
||||
{
|
||||
// Set TMR2 to the options selected in the User Interface
|
||||
|
||||
// PR2 255;
|
||||
PR2 = 0xFF;
|
||||
|
||||
// TMR2 0;
|
||||
TMR2 = 0x00;
|
||||
|
||||
// Clearing IF flag.
|
||||
PIR1bits.TMR2IF = 0;
|
||||
|
||||
// T2CKPS 1:1; TOUTPS 1:1; TMR2ON on;
|
||||
T2CON = 0x04;
|
||||
}
|
||||
|
||||
void TMR2_StartTimer(void)
|
||||
{
|
||||
// Start the Timer by writing to TMRxON bit
|
||||
T2CONbits.TMR2ON = 1;
|
||||
}
|
||||
|
||||
void TMR2_StopTimer(void)
|
||||
{
|
||||
// Stop the Timer by writing to TMRxON bit
|
||||
T2CONbits.TMR2ON = 0;
|
||||
}
|
||||
|
||||
uint8_t TMR2_ReadTimer(void)
|
||||
{
|
||||
uint8_t readVal;
|
||||
|
||||
readVal = TMR2;
|
||||
|
||||
return readVal;
|
||||
}
|
||||
|
||||
void TMR2_WriteTimer(uint8_t timerVal)
|
||||
{
|
||||
// Write to the Timer2 register
|
||||
TMR2 = timerVal;
|
||||
}
|
||||
|
||||
void TMR2_LoadPeriodRegister(uint8_t periodVal)
|
||||
{
|
||||
PR2 = periodVal;
|
||||
}
|
||||
|
||||
bool TMR2_HasOverflowOccured(void)
|
||||
{
|
||||
// check if overflow has occurred by checking the TMRIF bit
|
||||
bool status = PIR1bits.TMR2IF;
|
||||
if(status)
|
||||
{
|
||||
// Clearing IF flag.
|
||||
PIR1bits.TMR2IF = 0;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
/**
|
||||
End of File
|
||||
*/
|
337
solar_panel.X/mcc_generated_files/tmr2.h
Normal file
337
solar_panel.X/mcc_generated_files/tmr2.h
Normal file
@ -0,0 +1,337 @@
|
||||
/**
|
||||
TMR2 Generated Driver API Header File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
tmr2.h
|
||||
|
||||
@Summary
|
||||
This is the generated header file for the TMR2 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This header file provides APIs for TMR2.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F97J60
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef TMR2_H
|
||||
#define TMR2_H
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
Section: Macro Declarations
|
||||
*/
|
||||
|
||||
/**
|
||||
Section: TMR2 APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Initializes the TMR2 module.
|
||||
|
||||
@Description
|
||||
This function initializes the TMR2 Registers.
|
||||
This function must be called before any other TMR2 function is called.
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Comment
|
||||
|
||||
|
||||
@Example
|
||||
<code>
|
||||
main()
|
||||
{
|
||||
// Initialize TMR2 module
|
||||
TMR2_Initialize();
|
||||
|
||||
// Do something else...
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void TMR2_Initialize(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
This function starts the TMR2.
|
||||
|
||||
@Description
|
||||
This function starts the TMR2 operation.
|
||||
This function must be called after the initialization of TMR2.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR2 before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
// Initialize TMR2 module
|
||||
|
||||
// Start TMR2
|
||||
TMR2_StartTimer();
|
||||
|
||||
// Do something else...
|
||||
</code>
|
||||
*/
|
||||
void TMR2_StartTimer(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
This function stops the TMR2.
|
||||
|
||||
@Description
|
||||
This function stops the TMR2 operation.
|
||||
This function must be called after the start of TMR2.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR2 before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
// Initialize TMR2 module
|
||||
|
||||
// Start TMR2
|
||||
TMR2_StartTimer();
|
||||
|
||||
// Do something else...
|
||||
|
||||
// Stop TMR2;
|
||||
TMR2_StopTimer();
|
||||
</code>
|
||||
*/
|
||||
void TMR2_StopTimer(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Reads the TMR2 register.
|
||||
|
||||
@Description
|
||||
This function reads the TMR2 register value and return it.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR2 before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
This function returns the current value of TMR2 register.
|
||||
|
||||
@Example
|
||||
<code>
|
||||
// Initialize TMR2 module
|
||||
|
||||
// Start TMR2
|
||||
TMR2_StartTimer();
|
||||
|
||||
// Read the current value of TMR2
|
||||
if(0 == TMR2_ReadTimer())
|
||||
{
|
||||
// Do something else...
|
||||
|
||||
// Reload the TMR value
|
||||
TMR2_Reload();
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
uint8_t TMR2_ReadTimer(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Writes the TMR2 register.
|
||||
|
||||
@Description
|
||||
This function writes the TMR2 register.
|
||||
This function must be called after the initialization of TMR2.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR2 before calling this function.
|
||||
|
||||
@Param
|
||||
timerVal - Value to write into TMR2 register.
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
#define PERIOD 0x80
|
||||
#define ZERO 0x00
|
||||
|
||||
while(1)
|
||||
{
|
||||
// Read the TMR2 register
|
||||
if(ZERO == TMR2_ReadTimer())
|
||||
{
|
||||
// Do something else...
|
||||
|
||||
// Write the TMR2 register
|
||||
TMR2_WriteTimer(PERIOD);
|
||||
}
|
||||
|
||||
// Do something else...
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void TMR2_WriteTimer(uint8_t timerVal);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Load value to Period Register.
|
||||
|
||||
@Description
|
||||
This function writes the value to PR2 register.
|
||||
This function must be called after the initialization of TMR2.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR2 before calling this function.
|
||||
|
||||
@Param
|
||||
periodVal - Value to load into TMR2 register.
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
#define PERIOD1 0x80
|
||||
#define PERIOD2 0x40
|
||||
#define ZERO 0x00
|
||||
|
||||
while(1)
|
||||
{
|
||||
// Read the TMR2 register
|
||||
if(ZERO == TMR2_ReadTimer())
|
||||
{
|
||||
// Do something else...
|
||||
|
||||
if(flag)
|
||||
{
|
||||
flag = 0;
|
||||
|
||||
// Load Period 1 value
|
||||
TMR2_LoadPeriodRegister(PERIOD1);
|
||||
}
|
||||
else
|
||||
{
|
||||
flag = 1;
|
||||
|
||||
// Load Period 2 value
|
||||
TMR2_LoadPeriodRegister(PERIOD2);
|
||||
}
|
||||
}
|
||||
|
||||
// Do something else...
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void TMR2_LoadPeriodRegister(uint8_t periodVal);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Boolean routine to poll or to check for the match flag on the fly.
|
||||
|
||||
@Description
|
||||
This function is called to check for the timer match flag.
|
||||
This function is used in timer polling method.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR2 module before calling this routine.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
true - timer match has occurred.
|
||||
false - timer match has not occurred.
|
||||
|
||||
@Example
|
||||
<code>
|
||||
while(1)
|
||||
{
|
||||
// check the match flag
|
||||
if(TMR2_HasOverflowOccured())
|
||||
{
|
||||
// Do something else...
|
||||
|
||||
// Reload the TMR2 value
|
||||
TMR2_Reload();
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
bool TMR2_HasOverflowOccured(void);
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // TMR2_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
|
Reference in New Issue
Block a user