Inital working code

This commit is contained in:
2025-01-30 20:02:06 -05:00
commit ea24f650d1
49 changed files with 6617 additions and 0 deletions

View File

@@ -0,0 +1,139 @@
/**
* ADC Generated Driver API Header File
*
* @file adc.h
*
* @defgroup adc ADC
*
* @brief This file contains the API prototypes and data types for the ADC driver.
*
* @version ADC Driver Version 2.1.3
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef ADC_H
#define ADC_H
#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
/**
@ingroup adc
@typedef adc_result_t
@brief Used for the result of the Analog-to-Digital (A/D) conversion.
*/
typedef uint16_t adc_result_t;
/**
* @ingroup adc
* @typedef adc_sync_double_result_t
* @struct Used for the result for a Double ADC conversion value.
*/
typedef struct
{
adc_result_t adcResult1;
adc_result_t adcResult2;
} adc_sync_double_result_t;
/**
* @ingroup adc
* @enum adc_channel_t
* @brief Contains the available ADC channels.
*/
typedef enum
{
channel_AVSS = 0x3b,
channel_Temp = 0x3c,
channel_DAC1 = 0x3d,
channel_FVR_BUF1 = 0x3e,
channel_FVR_BUF2 = 0x3f,
channel_ANC0 = 0x10
} adc_channel_t;
/**
Section: ADC Module APIs
*/
/**
* @ingroup adc
* @brief Initializes the ADC module. This routine is called before any other ADC routine.
* @param None.
* @return None.
*/
void ADC_Initialize(void);
/**
* @ingroup adc
* @brief Selects the channel for the A/D conversion.
* @param channel - Analog channel number on which the A/D conversion will be applied.
* Refer to adc_channel_t for the available channels.
* @return None.
*/
void ADC_SelectChannel(adc_channel_t channel);
/**
* @ingroup adc
* @brief Starts A/D conversion.
* @param None.
* @return None.
*/
void ADC_StartConversion(void);
/**
* @ingroup adc
* @brief Checks if ongoing A/D conversion is complete.
* @param None.
* @retval True - A/D conversion is complete.
* @retval False - A/D conversion is ongoing.
*/
bool ADC_IsConversionDone(void);
/**
* @ingroup adc
* @brief Retrieves the result of the latest A/D conversion.
* @param None.
* @return The result of A/D conversion. Refer to the adc_result_t.
*/
adc_result_t ADC_GetConversionResult(void);
/**
* @ingroup adc
* @brief Retrieves the result of a single A/D conversion on any given channel.
* @param channel - Analog channel number on which the A/D conversion will be applied.
* Refer to adc_channel_t for the available channels.
* @return The result of A/D conversion. Refer to the adc_result_t.
*/
adc_result_t ADC_GetConversion(adc_channel_t channel);
/**
* @ingroup adc
* @brief Adds the acquisition delay for the temperature sensor.
* @pre This function is called when temperature sensor is used.
* @param None.
* @return None.
*/
void ADC_TemperatureAcquisitionDelay(void);
#endif //ADC_H

View File

@@ -0,0 +1,125 @@
/**
* ADC Generated Driver File
*
* @file adc.c
*
* @ingroup adc
*
* @brief This file contains the API implementations for the ADC module.
*
* @version ADC Driver Version 2.1.3
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
Section: Included Files
*/
#include <xc.h>
#include "../adc.h"
#include "../../system/clock.h"
/**
Section: Macro Declarations
*/
#define ACQ_US_DELAY 5
/**
Section: ADC Module APIs
*/
void ADC_Initialize(void)
{
//ADPREF VDD; ADCS FOSC/64; ADFM right;
ADCON1 = 0xE0;
//ADRESL 0x0;
ADRESL = 0x0;
//ADRESH 0x0;
ADRESH = 0x0;
//ADACT disabled;
ADACT = 0x0;
//ADON enabled; GO_nDONE stop; CHS ANC0;
ADCON0 = 0x41;
//Clear the ADC interrupt flag
PIR1bits.ADIF = 0;
}
void ADC_SelectChannel(adc_channel_t channel)
{
//Selects the A/D channel
ADCON0bits.CHS = channel;
}
void ADC_StartConversion(void)
{
//Starts the conversion
ADCON0bits.GOnDONE = 1;
}
bool ADC_IsConversionDone(void)
{
//Returns the conversion status
return ((bool)(!ADCON0bits.GOnDONE));
}
adc_result_t ADC_GetConversionResult(void)
{
//Conversion finished, returns the result
return ((adc_result_t)((ADRESH << 8) + ADRESL));
}
adc_result_t ADC_GetConversion(adc_channel_t channel)
{
//Selects the A/D channel
ADCON0bits.CHS = channel;
//Turns on the ADC module
ADCON0bits.ADON = 1;
//Acquisition time delay
__delay_us(ACQ_US_DELAY);
//Starts the conversion
ADCON0bits.GOnDONE = 1;
//Waits for the conversion to finish
while (ADCON0bits.GOnDONE)
{
}
//Conversion finished, returns the result
return ((adc_result_t)((ADRESH << 8) + ADRESL));
}
void ADC_TemperatureAcquisitionDelay(void)
{
__delay_us(200);
}

View File

@@ -0,0 +1,67 @@
/**
* PWM3 Generated Driver API Header File
*
* @file pwm3.h
*
* @defgroup pwm3 PWM3
*
* @brief This file contains the API prototypes for the PWM3 driver.
*
* @version PWM3 Driver Version 2.0.4
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef PWM3_H
#define PWM3_H
/**
* Section: Included Files
*/
#include <xc.h>
#include <stdint.h>
/**
* Section: Macro Declarations
*/
#define PWM3_INITIALIZE_DUTY_VALUE 499
/**
* @ingroup pwm3
* @brief Initializes the PWM3 interface.
* @param None.
* @return None.
*/
void PWM3_Initialize(void);
/**
* @ingroup pwm3
* @brief Loads the 16-bit duty cycle value.
* @param uint16_t dutyValue - PWM3 duty cycle value to be loaded.
* @return None.
*/
void PWM3_LoadDutyValue(uint16_t dutyValue);
#endif //PWM3_H

View File

@@ -0,0 +1,67 @@
/**
* PWM4 Generated Driver API Header File
*
* @file pwm4.h
*
* @defgroup pwm4 PWM4
*
* @brief This file contains the API prototypes for the PWM4 driver.
*
* @version PWM4 Driver Version 2.0.4
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef PWM4_H
#define PWM4_H
/**
* Section: Included Files
*/
#include <xc.h>
#include <stdint.h>
/**
* Section: Macro Declarations
*/
#define PWM4_INITIALIZE_DUTY_VALUE 499
/**
* @ingroup pwm4
* @brief Initializes the PWM4 interface.
* @param None.
* @return None.
*/
void PWM4_Initialize(void);
/**
* @ingroup pwm4
* @brief Loads the 16-bit duty cycle value.
* @param uint16_t dutyValue - PWM4 duty cycle value to be loaded.
* @return None.
*/
void PWM4_LoadDutyValue(uint16_t dutyValue);
#endif //PWM4_H

View File

@@ -0,0 +1,69 @@
/**
* PWM3 Generated Driver File
*
* @file pwm3.c
*
* @ingroup pwm3
*
* @brief This file contains the API implementations for the PWM3 module.
*
* @version PWM3 Driver Version 2.0.4
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
* Section: Included Files
*/
#include <xc.h>
#include "../pwm3.h"
/**
* Section: PWM Module APIs
*/
void PWM3_Initialize(void)
{
// Set the PWM3 to the options selected in the User Interface
// PWMPOL active_hi; PWMEN enabled;
PWM3CON = 0x80;
// PWMDCH 124;
PWM3DCH = 0x7C;
// PWMDCL 3;
PWM3DCL = 0xC0;
}
void PWM3_LoadDutyValue(uint16_t dutyValue)
{
// Writing to 8 MSBs of PWM duty cycle in PWMDCH register
PWM3DCH = (uint8_t) ((dutyValue & 0x03FCu) >> 2);
// Writing to 2 LSBs of PWM duty cycle in PWMDCL register
PWM3DCL = (uint8_t) ((dutyValue & 0x0003u) << 6);
}

View File

@@ -0,0 +1,69 @@
/**
* PWM4 Generated Driver File
*
* @file pwm4.c
*
* @ingroup pwm4
*
* @brief This file contains the API implementations for the PWM4 module.
*
* @version PWM4 Driver Version 2.0.4
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
* Section: Included Files
*/
#include <xc.h>
#include "../pwm4.h"
/**
* Section: PWM Module APIs
*/
void PWM4_Initialize(void)
{
// Set the PWM4 to the options selected in the User Interface
// PWMPOL active_hi; PWMEN enabled;
PWM4CON = 0x80;
// PWMDCH 124;
PWM4DCH = 0x7C;
// PWMDCL 3;
PWM4DCL = 0xC0;
}
void PWM4_LoadDutyValue(uint16_t dutyValue)
{
// Writing to 8 MSBs of PWM duty cycle in PWMDCH register
PWM4DCH = (uint8_t) ((dutyValue & 0x03FCu) >> 2);
// Writing to 2 LSBs of PWM duty cycle in PWMDCL register
PWM4DCL = (uint8_t) ((dutyValue & 0x0003u) << 6);
}

View File

@@ -0,0 +1,61 @@
/**
* CLOCK Generated Driver Header File
*
* @file clock.h
*
* @defgroup clockdriver Clock Driver
*
* @brief This file contains the API prototypes and other data types for the Clock driver.
*
* @version Driver Version 2.0.4
*
* @version Package Version 4.3.7
*
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef CLOCK_H
#define CLOCK_H
#ifndef _XTAL_FREQ
/**
@ingroup clock control
@def system frequency
@misradeviation{@required, 21.1} Defining the system frequency using the _XTAL_FREQ macro is required by the XC8 compiler for the built-in delay functions.
*/
/* cppcheck-suppress misra-c2012-21.1 */
#define _XTAL_FREQ 32000000U
#endif
/**
* @ingroup clockdriver
* @brief Initializes all the Internal Oscillator sources and the clock switch configurations.
* @param None.
* @return None.
*/
void CLOCK_Initialize(void);
#endif /* CLOCK_H */
/**
End of File
*/

View File

@@ -0,0 +1,44 @@
/**
* Configuration Bits Generated Driver Header File
*
* @file config_bits.h
*
* @defgroup config_bitsdriver CONFIGBITS Driver
*
* @brief This file contains the API prototype for the Configuration Bits driver.
*
* @version Driver Version 2.0.2
*
* @version Package Version 1.0.5
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef CONFIG_BITS_H
#define CONFIG_BITS_H
#include "../system/clock.h"
#endif /* CONFIG_BITS_H */
/**
End of File
*/

View File

@@ -0,0 +1,166 @@
/**
* Interrupt Manager Generated Driver API Header File
*
* @file interrupt.h
*
* @defgroup interrupt INTERRUPT
*
* @brief This file contains API prototypes and other data types for the Interrupt Manager driver.
*
* @version Interrupt Manager Driver Version 2.0.6
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef INTERRUPT_H
#define INTERRUPT_H
/**
* @ingroup interrupt
* @brief Enables global interrupts.
* @param None.
* @return None.
*/
#define INTERRUPT_GlobalInterruptEnable() (INTCONbits.GIE = 1)
/**
* @ingroup interrupt
* @brief Disables global interrupts.
* @param None.
* @return None.
*/
#define INTERRUPT_GlobalInterruptDisable() (INTCONbits.GIE = 0)
/**
* @ingroup interrupt
* @brief Returns the Global Interrupt Enable bit status.
* @param None.
* @retval 0 - Global interrupt disabled.
* @retval 1 - Global interrupt enabled.
*/
#define INTERRUPT_GlobalInterruptStatus() (INTCONbits.GIE)
/**
* @ingroup interrupt
* @brief Enables peripheral interrupts.
* @param None.
* @return None.
*/
#define INTERRUPT_PeripheralInterruptEnable() (INTCONbits.PEIE = 1)
/**
* @ingroup interrupt
* @brief Disables peripheral interrupts.
* @param None.
* @return None.
*/
#define INTERRUPT_PeripheralInterruptDisable() (INTCONbits.PEIE = 0)
/**
* @ingroup interrupt
* @brief Initializes peripheral interrupt priorities, enables or disables priority vectors and initializes the external interrupt.
* @param None.
* @return None.
*/
void INTERRUPT_Initialize (void);
/**
* @ingroup interrupt
* @brief Clears the Interrupt flag for the external interrupt, INT.
* @param None.
* @return None.
*/
#define EXT_INT_InterruptFlagClear() (PIR0bits.INTF = 0)
/**
* @ingroup interrupt
* @brief Clears the interrupt enable for the external interrupt, INT. This way, the external interrupts on this pin will not be serviced by the interrupt handler.
* @param None.
* @return None.
*/
#define EXT_INT_InterruptDisable() (PIE0bits.INTE = 0)
/**
* @ingroup interrupt
* @brief Sets the interrupt enable for the external interrupt, INT. This way, the external interrupts on this pin will be serviced by the interrupt handler.
* @param None.
* @return None.
*/
#define EXT_INT_InterruptEnable() (PIE0bits.INTE = 1)
/**
Section: External Interrupt Handlers
*/
/**
* @ingroup interrupt
* @brief Executes the ISR whenever the signal on the INT pin transitions to the preconfigured state.
* @pre Interrupt Manager is initialized.
* @param None.
* @return None.
*/
void INT_ISR(void);
/**
* @ingroup interrupt
* @brief Allows for a specific callback function to be called in the INT ISR and for a nonspecific interrupt handler to be called at run time.
* @pre Interrupt Manager is initialized.
* @param None.
* @return None.
*/
void INT_CallBack(void);
/**
* @ingroup interrupt
* @brief Allows selecting an interrupt handler for EXT_INT - INT at application run time.
* @pre Interrupt Manager is initialized.
* @param (*InterruptHandler)(void) - InterruptHandler function pointer.
* @return None.
*/
void INT_SetInterruptHandler(void (* InterruptHandler)(void));
/**
* @ingroup interrupt
* @brief Dynamic interrupt handler to be called every time the INT ISR is executed. It allows any function to be registered at run time.
* @pre Interrupt Manager is initialized.
* @param None.
* @return None.
*/
extern void (*INT_InterruptHandler)(void);
/**
* @ingroup interrupt
* @brief Default interrupt handler to be called every time the INT ISR is executed. It allows any function to be registered at run time.
* @pre Interrupt Manager is initialized.
* @param None.
* @return None.
*/
void INT_DefaultInterruptHandler(void);
#endif // INTERRUPT_H
/**
End of File
*/

View File

@@ -0,0 +1,205 @@
/**
* Generated Pins header File
*
* @file pins.h
*
* @defgroup pinsdriver Pins Driver
*
* @brief This is generated driver header for pins.
* This header file provides APIs for all pins selected in the GUI.
*
* @version Driver Version 3.0.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef PINS_H
#define PINS_H
#include <xc.h>
#define INPUT 1
#define OUTPUT 0
#define HIGH 1
#define LOW 0
#define ANALOG 1
#define DIGITAL 0
#define PULL_UP_ENABLED 1
#define PULL_UP_DISABLED 0
// get/set IO_RA2 aliases
#define DEBUG_TRIS TRISAbits.TRISA2
#define DEBUG_LAT LATAbits.LATA2
#define DEBUG_PORT PORTAbits.RA2
#define DEBUG_WPU WPUAbits.WPUA2
#define DEBUG_OD ODCONAbits.ODCA2
#define DEBUG_ANS ANSELAbits.ANSA2
#define DEBUG_SetHigh() do { LATAbits.LATA2 = 1; } while(0)
#define DEBUG_SetLow() do { LATAbits.LATA2 = 0; } while(0)
#define DEBUG_Toggle() do { LATAbits.LATA2 = ~LATAbits.LATA2; } while(0)
#define DEBUG_GetValue() PORTAbits.RA2
#define DEBUG_SetDigitalInput() do { TRISAbits.TRISA2 = 1; } while(0)
#define DEBUG_SetDigitalOutput() do { TRISAbits.TRISA2 = 0; } while(0)
#define DEBUG_SetPullup() do { WPUAbits.WPUA2 = 1; } while(0)
#define DEBUG_ResetPullup() do { WPUAbits.WPUA2 = 0; } while(0)
#define DEBUG_SetPushPull() do { ODCONAbits.ODCA2 = 0; } while(0)
#define DEBUG_SetOpenDrain() do { ODCONAbits.ODCA2 = 1; } while(0)
#define DEBUG_SetAnalogMode() do { ANSELAbits.ANSA2 = 1; } while(0)
#define DEBUG_SetDigitalMode() do { ANSELAbits.ANSA2 = 0; } while(0)
// get/set IO_RA4 aliases
#define LED1_TRIS TRISAbits.TRISA4
#define LED1_LAT LATAbits.LATA4
#define LED1_PORT PORTAbits.RA4
#define LED1_WPU WPUAbits.WPUA4
#define LED1_OD ODCONAbits.ODCA4
#define LED1_ANS ANSELAbits.ANSA4
#define LED1_SetHigh() do { LATAbits.LATA4 = 1; } while(0)
#define LED1_SetLow() do { LATAbits.LATA4 = 0; } while(0)
#define LED1_Toggle() do { LATAbits.LATA4 = ~LATAbits.LATA4; } while(0)
#define LED1_GetValue() PORTAbits.RA4
#define LED1_SetDigitalInput() do { TRISAbits.TRISA4 = 1; } while(0)
#define LED1_SetDigitalOutput() do { TRISAbits.TRISA4 = 0; } while(0)
#define LED1_SetPullup() do { WPUAbits.WPUA4 = 1; } while(0)
#define LED1_ResetPullup() do { WPUAbits.WPUA4 = 0; } while(0)
#define LED1_SetPushPull() do { ODCONAbits.ODCA4 = 0; } while(0)
#define LED1_SetOpenDrain() do { ODCONAbits.ODCA4 = 1; } while(0)
#define LED1_SetAnalogMode() do { ANSELAbits.ANSA4 = 1; } while(0)
#define LED1_SetDigitalMode() do { ANSELAbits.ANSA4 = 0; } while(0)
// get/set IO_RA5 aliases
#define LED2_TRIS TRISAbits.TRISA5
#define LED2_LAT LATAbits.LATA5
#define LED2_PORT PORTAbits.RA5
#define LED2_WPU WPUAbits.WPUA5
#define LED2_OD ODCONAbits.ODCA5
#define LED2_ANS ANSELAbits.ANSA5
#define LED2_SetHigh() do { LATAbits.LATA5 = 1; } while(0)
#define LED2_SetLow() do { LATAbits.LATA5 = 0; } while(0)
#define LED2_Toggle() do { LATAbits.LATA5 = ~LATAbits.LATA5; } while(0)
#define LED2_GetValue() PORTAbits.RA5
#define LED2_SetDigitalInput() do { TRISAbits.TRISA5 = 1; } while(0)
#define LED2_SetDigitalOutput() do { TRISAbits.TRISA5 = 0; } while(0)
#define LED2_SetPullup() do { WPUAbits.WPUA5 = 1; } while(0)
#define LED2_ResetPullup() do { WPUAbits.WPUA5 = 0; } while(0)
#define LED2_SetPushPull() do { ODCONAbits.ODCA5 = 0; } while(0)
#define LED2_SetOpenDrain() do { ODCONAbits.ODCA5 = 1; } while(0)
#define LED2_SetAnalogMode() do { ANSELAbits.ANSA5 = 1; } while(0)
#define LED2_SetDigitalMode() do { ANSELAbits.ANSA5 = 0; } while(0)
// get/set IO_RC0 aliases
#define IO_RC0_TRIS TRISCbits.TRISC0
#define IO_RC0_LAT LATCbits.LATC0
#define IO_RC0_PORT PORTCbits.RC0
#define IO_RC0_WPU WPUCbits.WPUC0
#define IO_RC0_OD ODCONCbits.ODCC0
#define IO_RC0_ANS ANSELCbits.ANSC0
#define IO_RC0_SetHigh() do { LATCbits.LATC0 = 1; } while(0)
#define IO_RC0_SetLow() do { LATCbits.LATC0 = 0; } while(0)
#define IO_RC0_Toggle() do { LATCbits.LATC0 = ~LATCbits.LATC0; } while(0)
#define IO_RC0_GetValue() PORTCbits.RC0
#define IO_RC0_SetDigitalInput() do { TRISCbits.TRISC0 = 1; } while(0)
#define IO_RC0_SetDigitalOutput() do { TRISCbits.TRISC0 = 0; } while(0)
#define IO_RC0_SetPullup() do { WPUCbits.WPUC0 = 1; } while(0)
#define IO_RC0_ResetPullup() do { WPUCbits.WPUC0 = 0; } while(0)
#define IO_RC0_SetPushPull() do { ODCONCbits.ODCC0 = 0; } while(0)
#define IO_RC0_SetOpenDrain() do { ODCONCbits.ODCC0 = 1; } while(0)
#define IO_RC0_SetAnalogMode() do { ANSELCbits.ANSC0 = 1; } while(0)
#define IO_RC0_SetDigitalMode() do { ANSELCbits.ANSC0 = 0; } while(0)
// get/set IO_RC3 aliases
#define RS_MODE_TRIS TRISCbits.TRISC3
#define RS_MODE_LAT LATCbits.LATC3
#define RS_MODE_PORT PORTCbits.RC3
#define RS_MODE_WPU WPUCbits.WPUC3
#define RS_MODE_OD ODCONCbits.ODCC3
#define RS_MODE_ANS ANSELCbits.ANSC3
#define RS_MODE_SetHigh() do { LATCbits.LATC3 = 1; } while(0)
#define RS_MODE_SetLow() do { LATCbits.LATC3 = 0; } while(0)
#define RS_MODE_Toggle() do { LATCbits.LATC3 = ~LATCbits.LATC3; } while(0)
#define RS_MODE_GetValue() PORTCbits.RC3
#define RS_MODE_SetDigitalInput() do { TRISCbits.TRISC3 = 1; } while(0)
#define RS_MODE_SetDigitalOutput() do { TRISCbits.TRISC3 = 0; } while(0)
#define RS_MODE_SetPullup() do { WPUCbits.WPUC3 = 1; } while(0)
#define RS_MODE_ResetPullup() do { WPUCbits.WPUC3 = 0; } while(0)
#define RS_MODE_SetPushPull() do { ODCONCbits.ODCC3 = 0; } while(0)
#define RS_MODE_SetOpenDrain() do { ODCONCbits.ODCC3 = 1; } while(0)
#define RS_MODE_SetAnalogMode() do { ANSELCbits.ANSC3 = 1; } while(0)
#define RS_MODE_SetDigitalMode() do { ANSELCbits.ANSC3 = 0; } while(0)
// get/set IO_RC4 aliases
#define IO_RC4_TRIS TRISCbits.TRISC4
#define IO_RC4_LAT LATCbits.LATC4
#define IO_RC4_PORT PORTCbits.RC4
#define IO_RC4_WPU WPUCbits.WPUC4
#define IO_RC4_OD ODCONCbits.ODCC4
#define IO_RC4_ANS ANSELCbits.ANSC4
#define IO_RC4_SetHigh() do { LATCbits.LATC4 = 1; } while(0)
#define IO_RC4_SetLow() do { LATCbits.LATC4 = 0; } while(0)
#define IO_RC4_Toggle() do { LATCbits.LATC4 = ~LATCbits.LATC4; } while(0)
#define IO_RC4_GetValue() PORTCbits.RC4
#define IO_RC4_SetDigitalInput() do { TRISCbits.TRISC4 = 1; } while(0)
#define IO_RC4_SetDigitalOutput() do { TRISCbits.TRISC4 = 0; } while(0)
#define IO_RC4_SetPullup() do { WPUCbits.WPUC4 = 1; } while(0)
#define IO_RC4_ResetPullup() do { WPUCbits.WPUC4 = 0; } while(0)
#define IO_RC4_SetPushPull() do { ODCONCbits.ODCC4 = 0; } while(0)
#define IO_RC4_SetOpenDrain() do { ODCONCbits.ODCC4 = 1; } while(0)
#define IO_RC4_SetAnalogMode() do { ANSELCbits.ANSC4 = 1; } while(0)
#define IO_RC4_SetDigitalMode() do { ANSELCbits.ANSC4 = 0; } while(0)
// get/set IO_RC5 aliases
#define IO_RC5_TRIS TRISCbits.TRISC5
#define IO_RC5_LAT LATCbits.LATC5
#define IO_RC5_PORT PORTCbits.RC5
#define IO_RC5_WPU WPUCbits.WPUC5
#define IO_RC5_OD ODCONCbits.ODCC5
#define IO_RC5_ANS ANSELCbits.ANSC5
#define IO_RC5_SetHigh() do { LATCbits.LATC5 = 1; } while(0)
#define IO_RC5_SetLow() do { LATCbits.LATC5 = 0; } while(0)
#define IO_RC5_Toggle() do { LATCbits.LATC5 = ~LATCbits.LATC5; } while(0)
#define IO_RC5_GetValue() PORTCbits.RC5
#define IO_RC5_SetDigitalInput() do { TRISCbits.TRISC5 = 1; } while(0)
#define IO_RC5_SetDigitalOutput() do { TRISCbits.TRISC5 = 0; } while(0)
#define IO_RC5_SetPullup() do { WPUCbits.WPUC5 = 1; } while(0)
#define IO_RC5_ResetPullup() do { WPUCbits.WPUC5 = 0; } while(0)
#define IO_RC5_SetPushPull() do { ODCONCbits.ODCC5 = 0; } while(0)
#define IO_RC5_SetOpenDrain() do { ODCONCbits.ODCC5 = 1; } while(0)
#define IO_RC5_SetAnalogMode() do { ANSELCbits.ANSC5 = 1; } while(0)
#define IO_RC5_SetDigitalMode() do { ANSELCbits.ANSC5 = 0; } while(0)
/**
* @ingroup pinsdriver
* @brief GPIO and peripheral I/O initialization
* @param none
* @return none
*/
void PIN_MANAGER_Initialize (void);
/**
* @ingroup pinsdriver
* @brief Interrupt on Change Handling routine
* @param none
* @return none
*/
void PIN_MANAGER_IOC(void);
#endif // PINS_H
/**
End of File
*/

View File

@@ -0,0 +1,56 @@
/**
* CLOCK Generated Driver Source File
*
* @file clock.c
*
* @ingroup clockdriver
*
* @brief This file contains the API prototypes for the Clock driver.
*
* @version Driver Version 2.0.4
*
* @version Package Version 4.3.7
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include <xc.h>
#include "../clock.h"
void CLOCK_Initialize(void)
{
// Set the CLOCK CONTROL module to the options selected in the user interface.
OSCCON1 = (0 << _OSCCON1_NDIV_POSN) // NDIV 1
| (6 << _OSCCON1_NOSC_POSN); // NOSC HFINTOSC
OSCCON3 = (0 << _OSCCON3_CSWHOLD_POSN); // CSWHOLD may proceed
OSCEN = (0 << _OSCEN_EXTOEN_POSN) // EXTOEN disabled
| (0 << _OSCEN_HFOEN_POSN) // HFOEN disabled
| (0 << _OSCEN_MFOEN_POSN) // MFOEN disabled
| (0 << _OSCEN_LFOEN_POSN) // LFOEN disabled
| (0 << _OSCEN_ADOEN_POSN); // ADOEN disabled
OSCFRQ = (6 << _OSCFRQ_HFFRQ_POSN); // HFFRQ 32_MHz
OSCTUNE = (0 << _OSCTUNE_HFTUN_POSN); // HFTUN 0x20
}
/**
End of File
*/

View File

@@ -0,0 +1,75 @@
/**
* Configuration Bits Generated Driver Source File
*
* @file config_bits.c
*
* @ingroup config_bitsdriver
*
* @brief This file contains the API Implementation for the Device Configuration Bits driver.
*
* @version Driver Version 2.0.2
*
* @version Package Version 1.0.5
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
// Configuration bits: selected in the GUI
//CONFIG1
#pragma config FEXTOSC = OFF // External Oscillator Selection bits->Oscillator not enabled
#pragma config RSTOSC = LFINT // Reset Oscillator Selection bits->LFINTOSC
#pragma config CLKOUTEN = OFF // Clock Out Enable bit->CLKOUT function is disabled; i/o or oscillator function on OSC2
#pragma config CSWEN = ON // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit->FSCM timer enabled
//CONFIG2
#pragma config MCLRE = ON // Master Clear Enable bit->MCLR pin is Master Clear function
#pragma config LPBOREN = OFF // Low-Power BOR Enable bit->ULPBOR disabled
#pragma config BOREN = ON // Brown-out Reset Enable bits->Brown-out Reset Enabled, SBOREN bit is ignored
#pragma config BORV = LO // Brown-out Reset Voltage Selection bit->Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices
#pragma config ZCD = OFF // ZCD Disable bit->Zero-cross detect circuit is disabled at POR.
#pragma config PPS1WAY = ON // PPSLOCKED One-Way Set Enable bit->The PPSLOCK bit can be cleared and set only once in software
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit->Stack Overflow or Underflow will cause a reset
//CONFIG3
#pragma config WDTCPS = WDTCPS_31 // WDT Period Select bits->Divider ratio 1:65536; software control of WDTPS
#pragma config WDTE = OFF // WDT Operating Mode bits->WDT Disabled, SWDTEN is ignored
#pragma config WDTCWS = WDTCWS_7 // WDT Window Select bits->window always open (100%); software control; keyed access not required
#pragma config WDTCCS = SC // WDT Input Clock Select bits->Software Control
//CONFIG4
#pragma config BBSIZE = BB512 // Boot Block Size Selection bits->512 words boot block size
#pragma config BBEN = OFF // Boot Block Enable bit->Boot Block disabled
#pragma config SAFEN = OFF // Storage Area Flash (SAF) Enable bit->SAF disabled
#pragma config WRTAPP = OFF // Application Block Write Protection bit->Application Block not write protected
#pragma config WRTB = OFF // Boot Block Write Protection bit->Boot Block not write protected
#pragma config WRTC = OFF // Configuration Register Write Protection bit->Configuration Register not write protected
#pragma config WRTSAF = OFF // Storage Area Flash (SAF) Write Protection bit->SAF not write protected
#pragma config LVP = ON // Low Voltage Programming Enable bit->Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.
//CONFIG5
#pragma config CP = OFF // Program Flash Memory Code Protection bit->UserNVM code protection disabled
/**
End of File
*/

View File

@@ -0,0 +1,113 @@
/**
* Interrupt Manager Generated Driver File
*
* @file interrupt.c
*
* @ingroup interrupt
*
* @brief This file contains the API implementation for the Interrupt Manager driver.
*
* @version Interrupt Manager Driver Version 2.0.6
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include "../../system/interrupt.h"
#include "../../system/system.h"
#include "../pins.h"
void (*INT_InterruptHandler)(void);
void INTERRUPT_Initialize (void)
{
// Clear the interrupt flag
EXT_INT_InterruptFlagClear();
// Set Default Interrupt Handler
INT_SetInterruptHandler(INT_DefaultInterruptHandler);
// EXT_INT_InterruptEnable();
}
/**
* @ingroup interrupt
* @brief Services the Interrupt Service Routines (ISR) of enabled interrupts and is called every time an interrupt is triggered.
* @pre Interrupt Manager is initialized.
* @param None.
* @return None.
*/
void __interrupt() INTERRUPT_InterruptManager (void)
{
// interrupt handler
if(INTCONbits.PEIE == 1)
{
if(PIE0bits.TMR0IE == 1 && PIR0bits.TMR0IF == 1)
{
TMR0_ISR();
}
else if(PIE4bits.TMR2IE == 1 && PIR4bits.TMR2IF == 1)
{
TMR2_ISR();
}
else if(PIE4bits.TMR1IE == 1 && PIR4bits.TMR1IF == 1)
{
TMR1_OverflowISR();
}
else
{
//Unhandled Interrupt
}
}
else
{
//Unhandled Interrupt
}
}
void INT_ISR(void)
{
EXT_INT_InterruptFlagClear();
// Callback function gets called everytime this ISR executes
INT_CallBack();
}
void INT_CallBack(void)
{
// Add your custom callback code here
if(INT_InterruptHandler)
{
INT_InterruptHandler();
}
}
void INT_SetInterruptHandler(void (* InterruptHandler)(void)){
INT_InterruptHandler = InterruptHandler;
}
void INT_DefaultInterruptHandler(void){
// add your INT interrupt custom code
// or set custom function using INT_SetInterruptHandler()
}
/**
End of File
*/

View File

@@ -0,0 +1,111 @@
/**
* Generated Driver File
*
* @file pins.c
*
* @ingroup pinsdriver
*
* @brief This is generated driver implementation for pins.
* This file provides implementations for pin APIs for all pins selected in the GUI.
*
* @version Driver Version 3.0.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include "../pins.h"
void PIN_MANAGER_Initialize(void)
{
/**
LATx registers
*/
LATA = 0x0;
LATC = 0x0;
/**
TRISx registers
*/
TRISA = 0x3;
TRISC = 0x17;
/**
ANSELx registers
*/
ANSELA = 0x33;
ANSELC = 0x7;
/**
WPUx registers
*/
WPUA = 0x0;
WPUC = 0x0;
/**
ODx registers
*/
ODCONA = 0x0;
ODCONC = 0x0;
/**
SLRCONx registers
*/
SLRCONA = 0x37;
SLRCONC = 0x3F;
/**
INLVLx registers
*/
INLVLA = 0x3F;
INLVLC = 0x3F;
/**
PPS registers
*/
RX1DTPPS = 0x14; //RC4->EUSART1:RX1;
RA5PPS = 0x0C; //RA5->PWM4:PWM4OUT;
RC5PPS = 0x0F; //RC5->EUSART1:TX1;
RA4PPS = 0x0B; //RA4->PWM3:PWM3OUT;
/**
APFCON registers
*/
/**
IOCx registers
*/
IOCAP = 0x0;
IOCAN = 0x0;
IOCAF = 0x0;
IOCCP = 0x0;
IOCCN = 0x0;
IOCCF = 0x0;
}
void PIN_MANAGER_IOC(void)
{
}
/**
End of File
*/

View File

@@ -0,0 +1,52 @@
/**
* System Driver Source File
*
* @file system.c
*
* @ingroup systemdriver
*
* @brief This file contains the API implementation for the System driver.
*
* @version Driver Version 2.0.3
*
* @version Package Version 1.0.5
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include "../system.h"
void SYSTEM_Initialize(void)
{
CLOCK_Initialize();
PIN_MANAGER_Initialize();
TMR0_Initialize();
TMR1_Initialize();
TMR2_Initialize();
ADC_Initialize();
EUSART1_Initialize();
PWM3_Initialize();
PWM4_Initialize();
INTERRUPT_Initialize();
}

View File

@@ -0,0 +1,66 @@
/**
* System Driver Header File
*
* @file system.h
*
* @defgroup systemdriver System Driver
*
* @brief This file contains the API prototype for the System Driver.
*
* @version Driver Version 2.0.3
*
* @version Package Version 1.0.5
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef SYSTEM_H
#define SYSTEM_H
#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#include "config_bits.h"
#include "../system/pins.h"
#include "../adc/adc.h"
#include "../uart/eusart1.h"
#include "../pwm/pwm3.h"
#include "../pwm/pwm4.h"
#include "../system/interrupt.h"
#include "../system/clock.h"
#include "../timer/tmr0.h"
#include "../timer/tmr1.h"
#include "../timer/tmr2.h"
/**
* @ingroup systemdriver
* @brief Initializes the system module.
* This routine is called only once during system initialization, before calling other APIs.
* @param None.
* @return None.
*/
void SYSTEM_Initialize(void);
#endif /* SYSTEM_H */
/**
End of File
*/

View File

@@ -0,0 +1,143 @@
/**
* TMR0 Generated Driver File
*
* @file tmr0.c
*
* @ingroup tmr08bit
*
* @brief Driver implementation for the TMR0 driver
*
* @version TMR0 Driver Version 3.0.0
*
* @version Package Version 5.0.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include <xc.h>
#include "../tmr0.h"
static void (*TMR0_PeriodMatchCallback)(void);
static void TMR0_DefaultCallback(void);
/**
Section: TMR0 APIs
*/
void TMR0_Initialize(void)
{
TMR0H = 0x63; // Period 10ms; Frequency 10000 Hz; Count 99
TMR0L = 0x0;
T0CON1 = (0 << _T0CON1_T0CS_POSN) // T0CS T0CKI_PIN
| (0 << _T0CON1_T0CKPS_POSN) // T0CKPS 1:1
| (1 << _T0CON1_T0ASYNC_POSN); // T0ASYNC not_synchronised
TMR0_PeriodMatchCallback = TMR0_DefaultCallback;
PIR0bits.TMR0IF = 0;
PIE0bits.TMR0IE = 1;
T0CON0 = (0 << _T0CON0_T0OUTPS_POSN) // T0OUTPS 1:1
| (1 << _T0CON0_T0EN_POSN) // T0EN enabled
| (0 << _T0CON0_T016BIT_POSN); // T016BIT 8-bit
}
void TMR0_Deinitialize(void)
{
T0CON0bits.T0EN = 0;
PIR0bits.TMR0IF = 0;
PIE0bits.TMR0IE = 0;
T0CON0 = 0x0;
T0CON1 = 0x0;
TMR0H = 0xFF;
TMR0L =0x0;
}
void TMR0_Start(void)
{
T0CON0bits.T0EN = 1;
}
void TMR0_Stop(void)
{
T0CON0bits.T0EN = 0;
}
uint8_t TMR0_CounterGet(void)
{
uint8_t counterValue;
counterValue = TMR0L;
return counterValue;
}
void TMR0_CounterSet(uint8_t counterValue)
{
TMR0L = counterValue;
}
void TMR0_PeriodSet(uint8_t periodValue)
{
TMR0H = periodValue;
}
uint8_t TMR0_PeriodGet(void)
{
return TMR0H;
}
uint8_t TMR0_MaxCountGet(void)
{
return TMR0_MAX_COUNT;
}
void TMR0_TMRInterruptEnable(void)
{
PIE0bits.TMR0IE = 1;
}
void TMR0_TMRInterruptDisable(void)
{
PIE0bits.TMR0IE = 0;
}
void TMR0_ISR(void)
{
if(NULL != TMR0_PeriodMatchCallback)
{
TMR0_PeriodMatchCallback();
}
PIR0bits.TMR0IF = 0;
}
void TMR0_PeriodMatchCallbackRegister(void (* callbackHandler)(void))
{
TMR0_PeriodMatchCallback = callbackHandler;
}
static void TMR0_DefaultCallback(void)
{
// Default callback
}

View File

@@ -0,0 +1,218 @@
/**
* TMR1 Generated Driver File
*
* @file tmr1.c
*
* @ingroup tmr1
*
* @brief Driver implementation for the TMR1 driver
*
* @version TMR1 Driver Version 4.0.0
*
* @version Package Version 5.0.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
* Section: Included Files
*/
#include <xc.h>
#include "../tmr1.h"
static volatile uint16_t timer1ReloadVal;
static void (*TMR1_OverflowCallback)(void);
static void (*TMR1_GateCallback)(void);
static void TMR1_DefaultOverflowCallback(void);
static void TMR1_DefaultGateCallback(void);
void TMR1_Initialize(void)
{
T1CONbits.TMR1ON = 0; // TMRON disabled
T1GCON = (0 << _T1GCON_T1GGO_POSN) // T1GGO done
| (0 << _T1GCON_T1GSPM_POSN) // T1GSPM disabled
| (0 << _T1GCON_T1GTM_POSN) // T1GTM disabled
| (0 << _T1GCON_T1GPOL_POSN) // T1GPOL low
| (0 << _T1GCON_T1GE_POSN); // T1GE disabled
T1GATE = (0 << _T1GATE_GSS_POSN); // GSS T1G_pin
T1CLK = (4 << _T1CLK_CS_POSN); // CS LFINTOSC
TMR1H = 0xF3; // Period 100.03226ms; Timer clock 31000 Hz;
TMR1L = 0xE3;
timer1ReloadVal=((uint16_t)TMR1H << 8) | TMR1L;
TMR1_OverflowCallback = TMR1_DefaultOverflowCallback;
TMR1_GateCallback = TMR1_DefaultGateCallback;
PIR4bits.TMR1IF = 0;
PIE4bits.TMR1IE = 1;
T1CON = (1 << _T1CON_TMR1ON_POSN) // TMR1ON enabled
| (0 << _T1CON_T1RD16_POSN) // T1RD16 disabled
| (1 << _T1CON_nT1SYNC_POSN) // nT1SYNC do_not_synchronize
| (0 << _T1CON_CKPS_POSN); // CKPS 1:1
}
void TMR1_Deinitialize(void)
{
T1CONbits.TMR1ON = 0; // TMRON disabled
T1CON = 0x0;
T1GCON = 0x0;
T1GATE = 0x0;
T1CLK = 0x0;
TMR1H = 0x0;
TMR1L = 0x0;
PIR4bits.TMR1IF = 0;
PIE4bits.TMR1IE = 0;
PIR5bits.TMR1GIF = 0;
PIE5bits.TMR1GIE = 0;
}
void TMR1_Start(void)
{
T1CONbits.TMR1ON = 1;
}
void TMR1_Stop(void)
{
T1CONbits.TMR1ON = 0;
}
uint16_t TMR1_CounterGet(void)
{
uint16_t readVal;
uint8_t readValHigh;
uint8_t readValLow;
readValLow = TMR1L;
readValHigh = TMR1H;
readVal = ((uint16_t)readValHigh << 8) | readValLow;
return readVal;
}
void TMR1_CounterSet(uint16_t timerVal)
{
if (1U == T1CONbits.nT1SYNC)
{
bool onState = T1CONbits.TMR1ON;
TMR1H = (uint8_t)(timerVal >> 8);
TMR1L = (uint8_t)timerVal;
T1CONbits.TMR1ON = onState;
}
else
{
TMR1H = (uint8_t)(timerVal >> 8);
TMR1L = (uint8_t)timerVal;
}
}
void TMR1_PeriodSet(uint16_t periodVal)
{
timer1ReloadVal = periodVal;
}
uint16_t TMR1_PeriodGet(void)
{
return timer1ReloadVal;
}
void TMR1_Reload(void)
{
/* cppcheck-suppress misra-c2012-8.7 */
TMR1_CounterSet(timer1ReloadVal);
}
uint16_t TMR1_MaxCountGet(void)
{
return TMR1_MAX_COUNT;
}
void TMR1_SinglePulseAcquisitionStart(void)
{
T1GCONbits.T1GGO = 1;
}
uint8_t TMR1_GateStateGet(void)
{
return (T1GCONbits.T1GVAL);
}
void TMR1_TMRInterruptEnable(void)
{
PIE4bits.TMR1IE = 1;
}
void TMR1_TMRInterruptDisable(void)
{
PIE4bits.TMR1IE = 0;
}
void TMR1_OverflowISR(void)
{
static volatile uint16_t CountCallBack = 0;
/* cppcheck-suppress misra-c2012-8.7 */
TMR1_CounterSet(timer1ReloadVal);
// Callback function: This is called on every 5 pass.
if(++CountCallBack >= TMR1_INTERRUPT_TICKER_FACTOR)
{
if(NULL != TMR1_OverflowCallback)
{
TMR1_OverflowCallback();
}
CountCallBack = 0;
}
PIR4bits.TMR1IF = 0;
}
void TMR1_OverflowCallbackRegister(void (*CallbackHandler)(void))
{
TMR1_OverflowCallback = CallbackHandler;
}
void TMR1_GateCallbackRegister(void (*CallbackHandler)(void))
{
TMR1_GateCallback = CallbackHandler;
}
static void TMR1_DefaultOverflowCallback(void)
{
// Default overflow callback
}
static void TMR1_DefaultGateCallback(void)
{
// Default Gate callback
}
/**
End of File
*/

View File

@@ -0,0 +1,157 @@
/**
* TMR2 Generated Timer Driver File
*
* @file tmr2.c
*
* @ingroup timerdriver
*
* @brief Driver implementation for the TMR2 Timer driver.
*
* @version Driver Version 4.0.0
*
* @version Package Version 5.0.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
Section: Included Files
*/
#include <xc.h>
#include "../tmr2.h"
const struct TIMER_INTERFACE Timer2 = {
.Initialize = TMR2_Initialize,
.Deinitialize = TMR2_Deinitialize,
.Start = TMR2_Start,
.Stop = TMR2_Stop,
.PeriodSet = TMR2_PeriodSet,
.PeriodGet = TMR2_PeriodGet,
.CounterGet = TMR2_CounterGet,
.CounterSet = TMR2_CounterSet,
.MaxCountGet = TMR2_MaxCountGet,
.TimeoutCallbackRegister = TMR2_PeriodMatchCallbackRegister,
.Tasks = NULL
};
static void (*TMR2_PeriodMatchCallback)(void);
static void TMR2_DefaultPeriodMatchCallback(void);
/**
Section: TMR2 APIs
*/
void TMR2_Initialize(void)
{
T2CLKCON = (1 << _T2CLKCON_T2CS_POSN); // T2CS FOSC/4
T2HLT = (0 << _T2HLT_T2MODE_POSN) // T2MODE Software control
| (0 << _T2HLT_T2CKSYNC_POSN) // T2CKSYNC Not Synchronized
| (0 << _T2HLT_T2CKPOL_POSN) // T2CKPOL Rising Edge
| (0 << _T2HLT_T2PSYNC_POSN); // T2PSYNC Not Synchronized
T2RST = (0 << _T2RST_T2RSEL_POSN); // T2RSEL T2INPPS pin
T2PR = 0xF9; // Period 0.001s; Frequency 250000Hz; Count 249
T2TMR = 0x0;
TMR2_PeriodMatchCallback = TMR2_DefaultPeriodMatchCallback;
PIR4bits.TMR2IF = 0;
PIE4bits.TMR2IE = 1;
T2CON = (5 << _T2CON_T2CKPS_POSN) // T2CKPS 1:32
| (1 << _T2CON_TMR2ON_POSN) // TMR2ON on
| (0 << _T2CON_T2OUTPS_POSN); // T2OUTPS 1:1
}
void TMR2_Deinitialize(void)
{
T2CONbits.TMR2ON = 0;
PIR4bits.TMR2IF = 0;
PIE4bits.TMR2IE = 0;
T2CON = 0x0;
T2CLKCON = 0x0;
T2HLT = 0x0;
T2RST = 0x0;
T2PR = 0xFF;
T2TMR =0x0;
}
void TMR2_Start(void)
{
T2CONbits.TMR2ON = 1;
}
void TMR2_Stop(void)
{
T2CONbits.TMR2ON = 0;
}
uint32_t TMR2_CounterGet(void)
{
return (uint32_t)T2TMR;
}
void TMR2_CounterSet(uint32_t count)
{
T2TMR = (uint8_t)count;
}
void TMR2_PeriodSet(uint32_t periodVal)
{
T2PR = (uint8_t)periodVal;
}
uint32_t TMR2_PeriodGet(void)
{
return (uint32_t)T2PR;
}
uint32_t TMR2_MaxCountGet(void)
{
return (uint32_t)TMR2_MAX_COUNT;
}
void TMR2_ISR(void)
{
// The ticker is set to 1 -> The callback function gets called every time this ISR executes.
if(NULL != TMR2_PeriodMatchCallback)
{
TMR2_PeriodMatchCallback();
}
PIR4bits.TMR2IF = 0;
}
void TMR2_PeriodMatchCallbackRegister(void (* callbackHandler)(void))
{
TMR2_PeriodMatchCallback = callbackHandler;
}
static void TMR2_DefaultPeriodMatchCallback(void)
{
// Default callback function
}

View File

@@ -0,0 +1,110 @@
/**
* TIMER Generated Driver Interface Header File
*
* @file timer_interface.h
*
* @defgroup timerdriver Timer Driver
*
* @brief The Timer driver is an 8-bit, 16-bit or 32-bit timer that can operate as a
* free-running interval timer using PIC<49>, dsPIC<49> and AVR<56> microcontrollers (MCUs).
*
* @skipline @version Firmware Driver Version 1.7.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef TIMER_INTERFACE_H
#define TIMER_INTERFACE_H
// Section: Included Files
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
// Section: Data Type Definitions
/**
* @ingroup timerdriver
* @brief Defines the deprecated SCCPx_Timer_PeriodCountSet or TMRx_PeriodCountSet API.
* Set it to 1 for backward compatibility for 16-bit MCUs only.
*/
#define TIMER_PERIODCOUNTSET_API_SUPPORT 0
/**
* @ingroup timerdriver
* @brief The InterruptPrioritySet API is not supported.
*/
#define TIMER_INTERRUPT_PRIORITY_SUPPORT 0
/**
@ingroup timerdriver
@struct TIMER_INTERFACE
@brief Structure containing the function pointers of the Timer driver
*/
struct TIMER_INTERFACE
{
void (*Initialize)(void);
///< Pointer to MCCPx_Timer_Initialize, SCCPx_Timer_Initialize or TMRx_Initialize (e.g., \ref SCCP1_Timer_Initialize or \ref TMR1_Initialize).
void (*Deinitialize)(void);
///< Pointer to MCCPx_Timer_Deinitialize, SCCPx_Timer_Deinitialize or TMRx_Deinitialize (e.g., \ref SCCP1_Timer_Deinitialize or \ref TMR1_Deinitialize).
void (*Start)(void);
///< Pointer to MCCPx_Timer_Start, SCCPx_Timer_Start or TMRx_Start (e.g., \ref SCCP1_Timer_Start or \ref TMR1_Start).
void (*Stop)(void);
///< Pointer to MCCPx_Timer_Stop, SCCPx_Timer_Stop or TMRx_Stop (e.g., \ref SCCP1_Timer_Stop or \ref TMR1_Stop).
#if TIMER_PERIODCOUNTSET_API_SUPPORT
void (*PeriodCountSet)(size_t count);
///< Pointer to MCCPx_Timer_PeriodCountSet, SCCPx_Timer_PeriodCountSet or TMRx_PeriodCountSet (e.g., \ref SCCP1_Timer_PeriodCountSet or \ref TMR1_PeriodCountSet).
#endif
void (*PeriodSet)(uint32_t count);
///< Pointer to MCCPx_Timer_PeriodSet, SCCPx_Timer_PeriodSet or TMRx_PeriodSet (e.g., \ref SCCP1_Timer_PeriodSet or \ref TMR1_PeriodSet).
uint32_t (*PeriodGet)(void);
///< Pointer to MCCPx_Timer_PeriodGet, SCCPx_Timer_PeriodGet or TMRx_PeriodGet (e.g., \ref SCCP1_Timer_PeriodGet or \ref TMR1_PeriodGet).
uint32_t (*CounterGet)(void);
///< Pointer to MCCPx_Timer_CounterGet, SCCPx_Timer_CounterGet or TMRx_CounterGet (e.g., \ref SCCP1_Timer_CounterGet or \ref TMR1_CounterGet).
void (*CounterSet)(uint32_t count);
///< Pointer to MCCPx_Timer_CounterSet, SCCPx_Timer_CounterSet or TMRx_CounterSet (e.g., \ref SCCP1_Timer_CounterSet or \ref TMR1_CounterSet).
uint32_t (*MaxCountGet)(void);
///< Pointer to MCCPx_Timer_MaxCountGet, SCCPx_Timer_MaxCountGet or TMRx_MaxCountGet (e.g., \ref SCCP1_Timer_MaxCountGet or \ref TMR1_MaxCountGet).
#if TIMER_INTERRUPT_PRIORITY_SUPPORT
void (*InterruptPrioritySet)(enum INTERRUPT_PRIORITY priority);
///< Pointer to MCCPx_Timer_InterruptPrioritySet, SCCPx_Timer_InterruptPrioritySet or TMRx_InterruptPrioritySet (e.g., \ref SCCP1_Timer_InterruptPrioritySet or \ref TMR1_InterruptPrioritySet).
#endif
void (*TimeoutCallbackRegister)(void (*CallbackHandler)(void));
///< Pointer to MCCPx_TimeoutCallbackRegister, SCCPx_TimeoutCallbackRegister or TMRx_TimeoutCallbackRegister (e.g., \ref SCCP1_TimeoutCallbackRegister or \ref TMR1_TimeoutCallbackRegister).
void (*Tasks)(void);
///< Pointer to MCCPx_Timer_Tasks, SCCPx_Timer_Tasks or TMRx_Tasks (e.g., \ref SCCP1_Timer_Tasks or \ref TMR1_Tasks, supported only in Polling mode).
};
#endif // TIMER_INTERFACE_H

View File

@@ -0,0 +1,266 @@
/**
* TMR0 Generated Driver API Header File
*
* @file tmr0.h
*
* @defgroup tmr08bit TMR0 in 8-Bit Mode
*
* @brief This file contains API prototypes and other data types for the TMR0 driver.
*
* @version TMR0 Driver Version 3.0.0
*
* @version Package Version 5.0.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef TMR0_H
#define TMR0_H
#include <stdint.h>
#include <stdbool.h>
#include "tmr0_deprecated.h"
/**
* @misradeviation{@advisory,2.5}
* MCC Melody drivers provide macros that can be added to an application.
* It depends on the application whether a macro is used or not.
*/
/**
* @ingroup tmr08bit
* @brief Defines the maximum count value of the timer.
*/
#define TMR0_MAX_COUNT (255U)
/**
* @ingroup tmr08bit
* @brief Defines the timer prescaled clock frequency in hertz.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR0_CLOCK_FREQ (10000UL)
/**
* @ingroup tmr08bit
* @brief Defines the timer interrupt ticker factor.
*/
#define TMR0_INTERRUPT_TICKER_FACTOR (1U)
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_MAX_COUNT.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_MAX_COUNT TMR0_MAX_COUNT
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_CLOCK_FREQ.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_CLOCK_FREQ TMR0_CLOCK_FREQ
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_Initialize API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_Initialize TMR0_Initialize
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_Deinitialize API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_Deinitialize TMR0_Deinitialize
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_Start API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_Start TMR0_Start
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_Stop API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_Stop TMR0_Stop
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_CounterGet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_CounterGet TMR0_CounterGet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_CounterSet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_CounterSet TMR0_CounterSet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_PeriodSet API
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_PeriodSet TMR0_PeriodSet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_PeriodGet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_PeriodGet TMR0_PeriodGet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_MaxCountGet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_MaxCountGet TMR0_MaxCountGet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_TMRInterruptEnable API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_TMRInterruptEnable TMR0_TMRInterruptEnable
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_TMRInterruptDisable API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_TMRInterruptDisable TMR0_TMRInterruptDisable
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_ISR API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_ISR TMR0_ISR
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_PeriodMatchCallbackRegister API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_PeriodMatchCallbackRegister TMR0_PeriodMatchCallbackRegister
/**
* @ingroup tmr08bit
* @brief Initializes the Timer0 (TMR0) module.
* This routine must be called before any other TMR0 routines.
* @param None.
* @return None.
*/
void TMR0_Initialize(void);
/**
* @ingroup tmr08bit
* @brief Deinitializes the TMR0 module.
* @param None.
* @return None.
*/
void TMR0_Deinitialize(void);
/**
* @ingroup tmr08bit
* @brief Starts the TMR0 timer.
* @pre Initialize TMR0 with TMR0_Initialize() before calling this API.
* @param None.
* @return None.
*/
void TMR0_Start(void);
/**
* @ingroup tmr08bit
* @brief Stops the TMR0 timer.
* @pre Initialize TMR0 with TMR0_Initialize() before calling this API.
* @param None.
* @return None.
*/
void TMR0_Stop(void);
/**
* @ingroup tmr08bit
* @brief Returns the current counter value.
* @pre Initialize TMR0 with TMR0_Initialize() before calling this API.
* @param None.
* @return Counter value from the TMR0L register
*/
uint8_t TMR0_CounterGet(void);
/**
* @ingroup tmr08bit
* @brief Sets the counter value.
* @pre Initialize TMR0 with TMR0_Initialize() before calling this API.
* @param counterValue - Counter value to be written to the TMR0L register
* @return None.
*/
void TMR0_CounterSet(uint8_t counterValue);
/**
* @ingroup tmr08bit
* @brief Sets the period value.
* @pre Initialize TMR0 with TMR0_Initialize() before calling this API.
* @param periodCount - Period count value written to the TMR0H register
* @return None.
*/
void TMR0_PeriodSet(uint8_t periodCount);
/**
* @ingroup tmr08bit
* @brief Returns the current period value.
* @pre Initialize TMR0 with TMR0_Initialize() before calling this API.
* @param None.
* @return Period count value from the TMR0H register
*/
uint8_t TMR0_PeriodGet(void);
/**
* @ingroup tmr08bit
* @brief Returns the maximum count value.
* @param None.
* @return Maximum count value
*/
uint8_t TMR0_MaxCountGet(void);
/**
* @ingroup tmr08bit
* @brief Enables the TMR0 interrupt.
* @param None.
* @return None.
*/
void TMR0_TMRInterruptEnable(void);
/**
* @ingroup tmr08bit
* @brief Disables the TMR0 interrupt.
* @param None.
* @return None.
*/
void TMR0_TMRInterruptDisable(void);
/**
* @ingroup tmr08bit
* @brief Interrupt Service Routine (ISR) for the TMR0 overflow or period match interrupt.
* @param None.
* @return None.
*/
void TMR0_ISR(void);
/**
* @ingroup tmr08bit
* @brief Registers a callback function for the TMR0 overflow or period match event.
* @param CallbackHandler - Address to the custom callback function
* @return None.
*/
void TMR0_PeriodMatchCallbackRegister(void (* CallbackHandler)(void));
#endif //TMR0_H

View File

@@ -0,0 +1,136 @@
/**
* TMR0 Generated Driver API Header File
*
* @file tmr0.h
*
* @defgroup tmr08bit TMR0 in 8-Bit Mode
*
* @brief This file contains the deprecated macros or APIs for the TMR0 driver.
*
* @version TMR0 Driver Version 3.0.0
*
* @version Package Version 5.0.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef TMR0_DEPRECATED_H
#define TMR0_DEPRECATED_H
#include <stdint.h>
#include <stdbool.h>
#warning "The tmr0_deprecated.h file contains the deprecated macros or functions. Replace the deprecated macro or functions with the recommended alternative."
/**
* @misradeviation{@advisory,2.5}
* MCC Melody drivers provide macros that can be added to an application.
* It depends on the application whether a macro is used or not.
*/
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_CounterGet API.
* The TMR0_Read will be deprecated in the future release. Use TMR0_CounterGet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR0_Read TMR0_CounterGet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_CounterGet API.
* The TMR_TX_Read will be deprecated in the future release. Use TMR0_CounterGet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_Read TMR0_CounterGet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_CounterSet API.
* The TMR0_Write will be deprecated in the future release. Use TMR0_CounterSet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR0_Write TMR0_CounterSet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_CounterSet API.
* The TMR_TX_Write will be deprecated in the future release. Use TMR0_CounterSet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_Write TMR0_CounterSet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_PeriodSet API.
* The TMR0_PeriodCountSet will be deprecated in the future release. Use TMR0_PeriodSet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR0_PeriodCountSet TMR0_PeriodSet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_PeriodSet API.
* The TMR_TX_PeriodCountSet will be deprecated in the future release. Use TMR0_PeriodSet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_PeriodCountSet TMR0_PeriodSet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_PeriodSet API.
* The TMR0_Reload will be deprecated in the future release. Use TMR0_PeriodSet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR0_Reload TMR0_PeriodSet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_PeriodSet API.
* The TMR_TX_Reload will be deprecated in the future release. Use TMR0_PeriodSet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_Reload TMR0_PeriodSet
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_ISR API.
* The TMR0_OverflowISR will be deprecated in the future release. Use TMR0_ISR instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR0_OverflowISR TMR0_ISR
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_ISR API.
* The TMR_TX_OverflowISR will be deprecated in the future release. Use TMR0_ISR instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_OverflowISR TMR0_ISR
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_PeriodMatchCallbackRegister API.
* The TMR0_OverflowCallbackRegister will be deprecated in the future release. Use TMR0_PeriodMatchCallbackRegister instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR0_OverflowCallbackRegister TMR0_PeriodMatchCallbackRegister
/**
* @ingroup tmr08bit
* @brief Defines the Custom Name for the \ref TMR0_PeriodMatchCallbackRegister API.
* The TMR_TX_OverflowCallbackRegister will be deprecated in the future release. Use TMR0_PeriodMatchCallbackRegister instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_TX_OverflowCallbackRegister TMR0_PeriodMatchCallbackRegister
/**
* @}
*/
#endif //TMR0_DEPRECATED_H

View File

@@ -0,0 +1,318 @@
/**
* TMR1 Generated Driver API Header File
*
* @file tmr1.h
*
* @defgroup tmr1 TMR1
*
* @brief This file contains API prototypes and other data types for the TMR1 driver.
*
* @version TMR1 Driver Version 4.0.0
*
* @version Package Version 5.0.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef TMR1_H
#define TMR1_H
#include <stdbool.h>
#include <stdint.h>
#include "tmr1_deprecated.h"
/**
* @misradeviation{@advisory,2.5}
* MCC Melody drivers provide macros that can be added to an application.
* It depends on the application whether a macro is used or not.
*/
/**
* @ingroup tmr1
* @brief Defines the maximum count value of the timer.
*/
#define TMR1_MAX_COUNT (65535U)
/**
* @ingroup tmr1
* @brief Defines the TMR1 prescaled clock frequency in hertz.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR1_CLOCK_FREQ (31000UL)
/**
* @ingroup tmr1
* @brief Defines the TMR1 ticker factor for callback function call.
*/
#define TMR1_INTERRUPT_TICKER_FACTOR (5U)
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_MAX_COUNT.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_MAX_COUNT TMR1_MAX_COUNT
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_CLOCK_FREQ.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_CLOCK_FREQ TMR1_CLOCK_FREQ
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_Initialize API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_Initialize TMR1_Initialize
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_Deinitialize API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_Deinitialize TMR1_Deinitialize
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_Start API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_Start TMR1_Start
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_Stop API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_Stop TMR1_Stop
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_CounterGet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_CounterGet TMR1_CounterGet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_CounterSet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_CounterSet TMR1_CounterSet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_PeriodSet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_PeriodSet TMR1_PeriodSet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_PeriodGet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_PeriodGet TMR1_PeriodGet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_MaxCountGet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_MaxCountGet TMR1_MaxCountGet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_Reload API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_Reload TMR1_Reload
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_GateStateGet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_GateStateGet TMR1_GateStateGet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_SinglePulseAcquisitionStart API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_SinglePulseAcquisitionStart TMR1_SinglePulseAcquisitionStart
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_GateCallbackRegister API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_GateCallbackRegister TMR1_GateCallbackRegister
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_TMRInterruptEnable API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_TMRInterruptEnable TMR1_TMRInterruptEnable
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_TMRInterruptDisable API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_TMRInterruptDisable TMR1_TMRInterruptDisable
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_OverflowCallbackRegister API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_OverflowCallbackRegister TMR1_OverflowCallbackRegister
/**
* @ingroup tmr1
* @brief Initializes the Timer1 (TMR1) module.
* This routine must be called before any other TMR1 routines.
* @param None.
* @return None.
*/
void TMR1_Initialize(void);
/**
* @ingroup tmr1
* @brief Deinitializes the TMR1 to POR values.
* @param None.
* @return None.
*/
void TMR1_Deinitialize(void);
/**
* @ingroup tmr1
* @brief Starts the TMR1 timer.
* @pre Initialize TMR1 with TMR1_Initialize() before calling this API.
* @param None.
* @return None.
*/
void TMR1_Start(void);
/**
* @ingroup tmr1
* @brief Stops the TMR1 timer.
* @pre Initialize TMR1 with TMR1_Initialize() before calling this API.
* @param None.
* @return None.
*/
void TMR1_Stop(void);
/**
* @ingroup tmr1
* @brief Returns the current counter value.
* @pre Initialize TMR1 with TMR1_Initialize() before calling this API.
* @param None.
* @return Counter value from the TMR1 register
*/
uint16_t TMR1_CounterGet(void);
/**
* @ingroup tmr1
* @brief Sets the counter value.
* @pre Initialize TMR1 with TMR1_Initialize() before calling this API.
* @param timerVal - Counter value to be written to the TMR1 register
* @return None.
*/
void TMR1_CounterSet(uint16_t timerVal);
/**
* @ingroup tmr1
* @brief Sets the period count value for the TMR1 timer.
* The period count is calculated by subtracting the number of ticks required for the period from the maximum count.
* @param periodVal - Period value to be stored in the timer period variable
* @return None.
*/
void TMR1_PeriodSet(uint16_t periodVal);
/**
* @ingroup tmr1
* @brief Returns the period count value.
* @param None.
* @return Period count value
*/
uint16_t TMR1_PeriodGet(void);
/**
* @ingroup tmr1
* @brief Loads the period count value to the TMR1 register.
* @pre Initialize TMR1 with TMR1_Initialize() before calling this API.
* @param None.
* @return None.
*/
void TMR1_Reload(void);
/**
* @ingroup tmr1
* @brief Returns the TMR1 maximum count value.
* @param None.
* @return Maximum count value of the timer
*/
uint16_t TMR1_MaxCountGet(void);
/**
* @ingroup tmr1
* @brief Starts the single pulse acquisition in TMR1 gate operation.
* @pre Use this function only when the TMR1 gate is enabled.
* @param None.
* @return None.
*/
void TMR1_SinglePulseAcquisitionStart(void);
/**
* @ingroup tmr1
* @brief Returns the TMR1 gate state value.
* @pre Use this function only when the TMR1 gate is enabled.
* @param None.
* @return Gate state value
*/
uint8_t TMR1_GateStateGet(void);
/**
* @ingroup tmr1
* @brief Enables the TMR1 overflow interrupt.
* @param None.
* @return None.
*/
void TMR1_TMRInterruptEnable(void);
/**
* @ingroup tmr1
* @brief Disables the TMR1 overflow interrupt.
* @param None.
* @return None.
*/
void TMR1_TMRInterruptDisable(void);
/**
* @ingroup tmr1
* @brief Interrupt Service Routine (ISR) for the TMR1 overflow interrupt.
* @param None.
* @return None.
*/
void TMR1_OverflowISR(void);
/**
* @ingroup tmr1
* @brief Registers a callback function for the TMR1 overflow event.
* @param CallbackHandler - Address of the custom callback function
* @return None.
*/
void TMR1_OverflowCallbackRegister(void (* CallbackHandler)(void));
/**
* @ingroup tmr1
* @brief Registers a callback function for the TMR1 gate event.
* @param CallbackHandler - Address of the custom callback function
* @return None.
*/
void TMR1_GateCallbackRegister(void (* CallbackHandler)(void));
#endif // TMR1_H

View File

@@ -0,0 +1,117 @@
/**
* TMR1 Generated Driver API Header File
*
* @file tmr1.h
*
* @defgroup tmr1 TMR1
*
* @brief This file contains the deprecated macros or APIs for the TMR1 driver.
*
* @version TMR1 Driver Version 4.0.0
*
* @version Package Version 5.0.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef TMR1_DEPRECATED_H
#define TMR1_DEPRECATED_H
#warning "The tmr1_deprecated.h file contains the deprecated macros or functions. Replace the deprecated macro or functions with the recommended alternative."
/**
* @misradeviation{@advisory,2.5}
* MCC Melody drivers provide macros that can be added to an application.
* It depends on the application whether a macro is used or not.
*/
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_CounterGet API.
* The TMR1_Read will be deprecated in the future release. Use TMR1_CounterGet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR1_Read TMR1_CounterGet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_CounterGet API.
* The TMR_SENSOR_Read will be deprecated in the future release. Use TMR_SENSOR_CounterGet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_Read TMR1_CounterGet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_CounterSet API.
* The TMR1_Write will be deprecated in the future release. Use TMR1_CounterSet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR1_Write TMR1_CounterSet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_CounterSet API.
* The TMR_SENSOR_Write will be deprecated in the future release. Use TMR_SENSOR_CounterSet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_Write TMR1_CounterSet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_PeriodSet API.
* The TMR1_PeriodCountSet will be deprecated in the future release. Use TMR1_PeriodSet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR1_PeriodCountSet TMR1_PeriodSet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_PeriodSet API.
* The TMR_SENSOR_PeriodCountSet will be deprecated in the future release. Use TMR_SENSOR_PeriodSet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_PeriodCountSet TMR1_PeriodSet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_GateStateGet API.
* The TMR1_CheckGateValueStatus will be deprecated in the future release. Use TMR1_GateStateGet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR1_CheckGateValueStatus TMR1_GateStateGet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_GateStateGet API.
* The TMR_SENSOR_CheckGateValueStatus will be deprecated in the future release. Use TMR_SENSOR_GateStateGet instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_CheckGateValueStatus TMR1_GateStateGet
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_SinglePulseAcquisitionStart API.
* The TMR1_StartSinglePulseAcquisition will be deprecated in the future release. Use TMR1_SinglePulseAcquisitionStart instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR1_StartSinglePulseAcquisition TMR1_SinglePulseAcquisitionStart
/**
* @ingroup tmr1
* @brief Defines the Custom Name for the \ref TMR1_SinglePulseAcquisitionStart API.
* The TMR_SENSOR_StartSinglePulseAcquisition will be deprecated in the future release. Use TMR_SENSOR_SinglePulseAcquisitionStart instead.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR_SENSOR_StartSinglePulseAcquisition TMR1_SinglePulseAcquisitionStart
#endif // TMR1_DEPRECATED_H

View File

@@ -0,0 +1,248 @@
/**
* TMR2 Generated Timer Driver API Header File
*
* @file tmr2.h
*
* @ingroup timerdriver
*
* @brief This file contains API prototypes and other data types for the TMR2 Timer driver.
*
* @version Driver Version 4.0.0
*
* @version Package Version 5.0.0
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef TMR2_H
#define TMR2_H
#include <stdint.h>
#include <stdbool.h>
#include "timer_interface.h"
/**
* @misradeviation{@advisory,2.5}
* MCC Melody drivers provide macros that can be added to an application.
* It depends on the application whether a macro is used or not.
*/
/**
* @ingroup timerdriver
* @brief Defines the TMR2 maximum count value.
*/
#define TMR2_MAX_COUNT (255U)
/**
* @ingroup timerdriver
* @brief Defines the TMR2 prescaled clock frequency in hertz.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TMR2_CLOCK_FREQ (250000UL)
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_MAX_COUNT.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TIMER2_MAX_COUNT TMR2_MAX_COUNT
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_CLOCK_FREQ.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define TIMER2_CLOCK_FREQ TMR2_CLOCK_FREQ
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_Initialize API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_Initialize TMR2_Initialize
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_Deinitialize API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_Deinitialize TMR2_Deinitialize
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_Start API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_Start TMR2_Start
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_Stop API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_Stop TMR2_Stop
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_CounterGet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_CounterGet TMR2_CounterGet
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_CounterSet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_CounterSet TMR2_CounterSet
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_PeriodSet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_PeriodSet TMR2_PeriodSet
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_PeriodGet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_PeriodGet TMR2_PeriodGet
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_MaxCountGet API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_MaxCountGet TMR2_MaxCountGet
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_PeriodMatchCallbackRegister API.
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_PeriodMatchCallbackRegister TMR2_PeriodMatchCallbackRegister
/**
* @ingroup timerdriver
* @brief Defines the Custom Name for the \ref TMR2_ISR API
*/
/* cppcheck-suppress misra-c2012-2.5 */
#define Timer2_ISR TMR2_ISR
/**
@ingroup timerdriver
@struct TIMER_INTERFACE
@brief This is an instance of TIMER_INTERFACE for the TMR2 module.
*/
extern const struct TIMER_INTERFACE Timer2;
/**
* Section: TMR2 APIs
*/
/**
* @ingroup timerdriver
* @brief Initializes the Timer2 (TMR2) module.
* This routine must be called before any other TMR2 routines.
* @param None.
* @return None.
*/
void TMR2_Initialize(void);
/**
* @ingroup timerdriver
* @brief Deinitializes the TMR2 to Power-on Reset (POR) values.
* @param None.
* @return None.
*/
void TMR2_Deinitialize(void);
/**
* @ingroup timerdriver
* @brief Starts the TMR2 timer.
* @pre Initialize TMR2 with TMR2_Initialize() before calling this API.
* @param None.
* @return None.
*/
void TMR2_Start(void);
/**
* @ingroup timerdriver
* @brief Stops the TMR2 timer.
* @pre Initialize TMR2 with TMR2_Initialize() before calling this API.
* @param None.
* @return None.
*/
void TMR2_Stop(void);
/**
* @ingroup timerdriver
* @brief Returns the current counter value.
* @pre Initialize TMR2 with TMR2_Initialize() before calling this API.
* @param None.
* @return Counter value from the T2TMR register
*/
uint32_t TMR2_CounterGet(void);
/**
* @ingroup timerdriver
* @brief Sets the counter value.
* @pre Initialize TMR2 with TMR2_Initialize() before calling this API.
* @param count - Counter value to be written to the T2TMR register
* @return None.
*/
void TMR2_CounterSet(uint32_t count);
/**
* @ingroup timerdriver
* @brief Sets the period count value.
* @pre Initialize TMR2 with TMR2_Initialize() before calling this API.
* @param periodVal - Period count value to be written to the T2PR register
* @return None.
*/
void TMR2_PeriodSet(uint32_t periodVal);
/**
* @ingroup timerdriver
* @brief Returns the current period value.
* @pre Initialize TMR2 with TMR2_Initialize() before calling this API.
* @param None.
* @return Period count value
*/
uint32_t TMR2_PeriodGet(void);
/**
* @ingroup timerdriver
* @brief Returns the maximum count value of the timer.
* @param None.
* @return Maximum count value of the timer
*/
uint32_t TMR2_MaxCountGet(void);
/**
* @ingroup timerdriver
* @brief Interrupt Service Routine (ISR) for the TMR2 period match event.
* @param None.
* @return None.
*/
void TMR2_ISR(void);
/**
* @ingroup timerdriver
* @brief Registers a callback function for the TMR2 period match event.
* @param CallbackHandler - Address of the custom callback function
* @return None.
*/
void TMR2_PeriodMatchCallbackRegister(void (* callbackHandler)(void));
#endif // TMR2_H
/**
End of File
*/

View File

@@ -0,0 +1,305 @@
/**
* EUSART1 Generated Driver API Header File
*
* @file eusart1.h
*
* @defgroup eusart1 EUSART1
*
* @brief This file contains API prototypes and other datatypes for the Enhanced Universal Synchronous and Asynchronous Receiver Transceiver (EUSART) module.
*
* @version EUSART1 Driver Version 3.0.1
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef EUSART1_H
#define EUSART1_H
#include <stdbool.h>
#include <stdint.h>
/**
@ingroup eusart1
@def Standard Input Output functions
@misradeviation{@required, 21.6} This inclusion is essential for UART module to use Printf function for print the character.
*/
/* cppcheck-suppress misra-c2012-21.6 */
#include <stdio.h>
#include "../system/system.h"
#include "uart_drv_interface.h"
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
#define UART1_interface UART1
#define UART1_Initialize EUSART1_Initialize
#define UART1_Deinitialize EUSART1_Deinitialize
#define UART1_Write EUSART1_Write
#define UART1_Read EUSART1_Read
#define UART1__IsRxReady EUSART1_IsRxReady
#define UART1_IsTxReady EUSART1_IsTxReady
#define UART1_IsTxDone EUSART1_IsTxDone
#define UART1_TransmitEnable EUSART1_TransmitEnable
#define UART1_TransmitDisable EUSART1_TransmitDisable
#define UART1_AutoBaudSet EUSART1_AutoBaudSet
#define UART1_AutoBaudQuery EUSART1_AutoBaudQuery
#define UART1_BRGCountSet (NULL)
#define UART1_BRGCountGet (NULL)
#define UART1_BaudRateSet (NULL)
#define UART1_BaudRateGet (NULL)
#define UART1__AutoBaudEventEnableGet (NULL)
#define UART1_ErrorGet EUSART1_ErrorGet
#define UART1_TxCompleteCallbackRegister (NULL)
#define UART1_RxCompleteCallbackRegister (NULL)
#define UART1_TxCollisionCallbackRegister (NULL)
#define UART1_FramingErrorCallbackRegister EUSART1_FramingErrorCallbackRegister
#define UART1_OverrunErrorCallbackRegister EUSART1_OverrunErrorCallbackRegister
#define UART1_ParityErrorCallbackRegister (NULL)
#define UART1_EventCallbackRegister (NULL)
/**
@ingroup eusart1
@struct eusart1_status_t
@brief This is a structure defined for errors in reception of data.
*/
typedef union {
struct {
uint8_t perr : 1; /**<This is a bit field for Parity Error status*/
uint8_t ferr : 1; /**<This is a bit field for Framing Error status*/
uint8_t oerr : 1; /**<This is a bit field for Overfrun Error status*/
uint8_t reserved : 5; /**<Reserved*/
};
size_t status; /**<Group byte for status errors*/
}eusart1_status_t;
/**
* @ingroup eusart1
* @brief External object for eusart1_interface.
*/
extern const uart_drv_interface_t UART1;
/**
* @ingroup eusart1
* @brief Initializes the EUSART1 module. This routine is called
* only once during system initialization, before calling other APIs.
* @param None.
* @return None.
*/
void EUSART1_Initialize(void);
/**
* @ingroup eusart1
* @brief Deinitializes and disables the EUSART1 module.
* @param None.
* @return None.
*/
void EUSART1_Deinitialize(void);
/**
* @ingroup eusart1
* @brief This API enables the EUSART1 module.
* @param None.
* @return None.
*/
void EUSART1_Enable(void);
/**
* @ingroup eusart1
* @brief This API disables the EUSART1 module.
* @param None.
* @return None.
*/
void EUSART1_Disable(void);
/**
* @ingroup eusart1
* @brief This API enables the EUSART1 transmitter.
* The EUSART1 must be enabled to send the bytes over to the TX pin.
* @param None.
* @return None.
*/
void EUSART1_TransmitEnable(void);
/**
* @ingroup eusart1
* @brief This API disables the EUSART1 transmitter.
* @param None.
* @return None.
*/
void EUSART1_TransmitDisable(void);
/**
* @ingroup eusart1
* @brief This API enables the EUSART1 receiver.
* The EUSART1 must be enabled to receive the bytes sent by the RX pin.
* @param None.
* @return None.
*/
void EUSART1_ReceiveEnable(void);
/**
* @ingroup eusart1
* @brief This API disables the EUSART1 receiver.
* @param None.
* @return None.
*/
void EUSART1_ReceiveDisable(void);
/**
* @ingroup eusart1
* @brief This API enables the EUSART1 to send a break control.
* @param None.
* @return None.
*/
void EUSART1_SendBreakControlEnable(void);
/**
* @ingroup eusart1
* @brief This API disables the EUSART1 send break control.
* @param None.
* @return None.
*/
void EUSART1_SendBreakControlDisable(void);
/**
* @ingroup eusart1
* @brief This API enables the EUSART1 AutoBaud Detection (ABR).
* @param bool enable.
* @return None.
*/
void EUSART1_AutoBaudSet(bool enable);
/**
* @ingroup eusart1
* @brief This API reads the EUSART1 ABR Complete bit.
* @param None.
* @return bool.
*/
bool EUSART1_AutoBaudQuery(void);
/**
* @ingroup eusart1
* @brief This API reads the EUSART1 ABR Overflow bit.
* @param None.
* @return None.
*/
bool EUSART1_IsAutoBaudDetectOverflow(void);
/**
* @ingroup eusart1
* @brief This API resets the EUSART1 ABR Overflow bit.
* @param None.
* @return None.
*/
void EUSART1_AutoBaudDetectOverflowReset(void);
/**
* @ingroup eusart1
* @brief This API checks if the EUSART1 has received available data.
* @param None.
* @retval true if EUSART1 receiver FIFO has a data
* @retval false EUSART1 receiver FIFO is empty
*/
bool EUSART1_IsRxReady(void);
/**
* @ingroup eusart1
* @brief This function checks if the EUSART1 transmitter is ready to accept a data byte.
* @param None.
* @retval true if EUSART1 transmitter FIFO has atleast 1 byte space
* @retval false if EUSART1 transmitter FIFO is full
*/
bool EUSART1_IsTxReady(void);
/**
* @ingroup eusart1
* @brief This function returns the status of Transmit Shift Register (TSR).
* @param None.
* @retval true if Data completely shifted out from the TSR
* @retval false if Data is present in Transmit FIFO and/or in TSR
*/
bool EUSART1_IsTxDone(void);
/**
* @ingroup eusart1
* @brief This function receives the error status of the last read byte.
* @param None.
* @return Status of the last read byte. See eusart1_status_t struct for more details.
*/
size_t EUSART1_ErrorGet(void);
/**
* @ingroup eusart1
* @brief This function reads the 8 bits from the FIFO register receiver.
* @pre The transfer status must be checked to see if the receiver is not empty
* before calling this function. Verify the EUSART1_IsRxReady(), before calling this API.
* @param None.
* @return 8-bit data from RX FIFO register.
*/
uint8_t EUSART1_Read(void);
/**
* @ingroup eusart1
* @brief This function writes a byte of data to the transmitter FIFO register.
* @pre The transfer status must be checked to see if the transmitter is ready to accept a byte
* before calling this function. Verify the EUSART1_IsTxReady() before calling this API.
* @param txData - Data byte to write to the TX FIFO.
* @return None.
*/
void EUSART1_Write(uint8_t txData);
/**
* @ingroup eusart1
* @brief This API registers the function to be called upon framing error.
* @param callbackHandler - a function pointer which will be called upon framing error condition.
* @return None.
*/
void EUSART1_FramingErrorCallbackRegister(void (* callbackHandler)(void));
/**
* @ingroup eusart1
* @brief This API registers the function to be called upon overrun error.
* @param callbackHandler - a function pointer which will be called upon overrun error condition.
* @return None.
*/
void EUSART1_OverrunErrorCallbackRegister(void (* callbackHandler)(void));
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif // EUSART1_H

View File

@@ -0,0 +1,267 @@
/**
* EUSART1 Generated Driver API Header File
*
* @file eusart1.c
*
* @ingroup eusart1
*
* @brief This is the generated driver implementation file for the EUSART1 driver using the Enhanced Universal Synchronous and Asynchronous Receiver Transceiver (EUSART) module.
*
* @version EUSART1 Driver Version 3.0.1
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
Section: Included Files
*/
#include "../eusart1.h"
/**
Section: Macro Declarations
*/
/**
Section: Driver Interface
*/
const uart_drv_interface_t UART1 = {
.Initialize = &EUSART1_Initialize,
.Deinitialize = &EUSART1_Deinitialize,
.Read = &EUSART1_Read,
.Write = &EUSART1_Write,
.IsRxReady = &EUSART1_IsRxReady,
.IsTxReady = &EUSART1_IsTxReady,
.IsTxDone = &EUSART1_IsTxDone,
.TransmitEnable = &EUSART1_TransmitEnable,
.TransmitDisable = &EUSART1_TransmitDisable,
.AutoBaudSet = &EUSART1_AutoBaudSet,
.AutoBaudQuery = &EUSART1_AutoBaudQuery,
.BRGCountSet = NULL,
.BRGCountGet = NULL,
.BaudRateSet = NULL,
.BaudRateGet = NULL,
.AutoBaudEventEnableGet = NULL,
.ErrorGet = &EUSART1_ErrorGet,
.TxCompleteCallbackRegister = NULL,
.RxCompleteCallbackRegister = NULL,
.TxCollisionCallbackRegister = NULL,
.FramingErrorCallbackRegister = &EUSART1_FramingErrorCallbackRegister,
.OverrunErrorCallbackRegister = &EUSART1_OverrunErrorCallbackRegister,
.ParityErrorCallbackRegister = NULL,
.EventCallbackRegister = NULL,
};
/**
Section: EUSART1 variables
*/
static volatile eusart1_status_t eusart1RxLastError;
/**
Section: EUSART1 APIs
*/
static void (*EUSART1_FramingErrorHandler)(void) = NULL;
static void (*EUSART1_OverrunErrorHandler)(void) = NULL;
static void EUSART1_DefaultFramingErrorCallback(void);
static void EUSART1_DefaultOverrunErrorCallback(void);
/**
Section: EUSART1 APIs
*/
void EUSART1_Initialize(void)
{
// Set the EUSART1 module to the options selected in the user interface.
//ABDEN disabled; WUE disabled; BRG16 16bit_generator; SCKP Non-Inverted;
BAUD1CON = 0x48;
//ADDEN disabled; CREN enabled; SREN disabled; RX9 8-bit; SPEN enabled;
RC1STA = 0x90;
//TX9D 0x0; BRGH hi_speed; SENDB sync_break_complete; SYNC asynchronous; TXEN enabled; TX9 8-bit; CSRC client;
TX1STA = 0x26;
//SPBRGL 64;
SP1BRGL = 0x40;
//SPBRGH 3;
SP1BRGH = 0x3;
EUSART1_FramingErrorCallbackRegister(EUSART1_DefaultFramingErrorCallback);
EUSART1_OverrunErrorCallbackRegister(EUSART1_DefaultOverrunErrorCallback);
eusart1RxLastError.status = 0;
}
void EUSART1_Deinitialize(void)
{
BAUD1CON = 0x00;
RC1STA = 0x00;
TX1STA = 0x00;
SP1BRGL = 0x00;
SP1BRGH = 0x00;
}
void EUSART1_Enable(void)
{
RC1STAbits.SPEN = 1;
}
void EUSART1_Disable(void)
{
RC1STAbits.SPEN = 0;
}
void EUSART1_TransmitEnable(void)
{
TX1STAbits.TXEN = 1;
}
void EUSART1_TransmitDisable(void)
{
TX1STAbits.TXEN = 0;
}
void EUSART1_ReceiveEnable(void)
{
RC1STAbits.CREN = 1;
}
void EUSART1_ReceiveDisable(void)
{
RC1STAbits.CREN = 0;
}
void EUSART1_SendBreakControlEnable(void)
{
TX1STAbits.SENDB = 1;
}
void EUSART1_SendBreakControlDisable(void)
{
TX1STAbits.SENDB = 0;
}
void EUSART1_AutoBaudSet(bool enable)
{
if(enable)
{
BAUD1CONbits.ABDEN = 1;
}
else
{
BAUD1CONbits.ABDEN = 0;
}
}
bool EUSART1_AutoBaudQuery(void)
{
return (bool)(!BAUD1CONbits.ABDEN);
}
bool EUSART1_IsAutoBaudDetectOverflow(void)
{
return (bool)BAUD1CONbits.ABDOVF;
}
void EUSART1_AutoBaudDetectOverflowReset(void)
{
BAUD1CONbits.ABDOVF = 0;
}
bool EUSART1_IsRxReady(void)
{
return (bool)(PIR3bits.RC1IF);
}
bool EUSART1_IsTxReady(void)
{
return (bool)(PIR3bits.TX1IF && TX1STAbits.TXEN);
}
bool EUSART1_IsTxDone(void)
{
return TX1STAbits.TRMT;
}
size_t EUSART1_ErrorGet(void)
{
return eusart1RxLastError.status;
}
uint8_t EUSART1_Read(void)
{
eusart1RxLastError.status = 0;
if(true == RC1STAbits.OERR)
{
eusart1RxLastError.oerr = 1;
if(NULL != EUSART1_OverrunErrorHandler)
{
EUSART1_OverrunErrorHandler();
}
}
if(true == RC1STAbits.FERR)
{
eusart1RxLastError.ferr = 1;
if(NULL != EUSART1_FramingErrorHandler)
{
EUSART1_FramingErrorHandler();
}
}
return RC1REG;
}
void EUSART1_Write(uint8_t txData)
{
TX1REG = txData;
}
static void EUSART1_DefaultFramingErrorCallback(void)
{
}
static void EUSART1_DefaultOverrunErrorCallback(void)
{
//Continuous Receive must be cleared to clear Overrun Error else Rx will not receive upcoming bytes
RC1STAbits.CREN = 0;
RC1STAbits.CREN = 1;
}
void EUSART1_FramingErrorCallbackRegister(void (* callbackHandler)(void))
{
if(NULL != callbackHandler)
{
EUSART1_FramingErrorHandler = callbackHandler;
}
}
void EUSART1_OverrunErrorCallbackRegister(void (* callbackHandler)(void))
{
if(NULL != callbackHandler)
{
EUSART1_OverrunErrorHandler = callbackHandler;
}
}

View File

@@ -0,0 +1,91 @@
/**
* UART Generated Driver Interface Header File
*
* @file uart_drv_interface.h
*
* @defgroup uart_drv_interface UART_DRV_INTERFACE
*
* @brief This file contains API prototypes and data types of the Universal Asynchronous Receiver and Transmitter (UART) interface.
*
* @version UART Driver Version 3.0.2
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef UART_DRV_INTERFACE_H
#define UART_DRV_INTERFACE_H
/**
Section: Included Files
*/
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "uart_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
Section: Data Type Definitions
*/
/**
@ingroup UART
@struct uart_drv_interface_t
@brief Structure containing the function pointers of UART driver.
*/
typedef struct {
void (*Initialize)(void);
void (*Deinitialize)(void);
uint8_t (*Read)(void);
void (*Write)(uint8_t);
bool (*IsRxReady)(void);
bool (*IsTxReady)(void);
bool (*IsTxDone)(void);
void (*TransmitEnable)(void);
void (*TransmitDisable)(void);
void (*AutoBaudSet)(bool enable);
bool (*AutoBaudQuery)(void);
bool (*AutoBaudEventEnableGet)(void);
void (*BRGCountSet)(uint32_t brgValue);
uint32_t (*BRGCountGet)(void);
void (*BaudRateSet)(uint32_t baudRate);
uint32_t (*BaudRateGet)(void);
size_t (*ErrorGet)(void);
void (*TxCompleteCallbackRegister)(void (*CallbackHandler) (void));
void (*RxCompleteCallbackRegister)(void (*CallbackHandler) (void));
void (*TxCollisionCallbackRegister)(void (*CallbackHandler) (void));
void (*FramingErrorCallbackRegister)(void (*CallbackHandler) (void));
void (*OverrunErrorCallbackRegister)(void (*CallbackHandler) (void));
void (*ParityErrorCallbackRegister)(void (*CallbackHandler) (void));
void (*EventCallbackRegister)(void (*CallbackHandler) (void));
}uart_drv_interface_t;
#ifdef __cplusplus
}
#endif
#endif /* UART_DRV_INTERFACE_H */

View File

@@ -0,0 +1,81 @@
/**
* UART Generated Driver Interface Header File
*
* @file uart_types.h
*
* @defgroup uart_types UART_TYPES
*
* @brief This file contains the enumeration of different Universal Asynchronous Receiver and Transmitter (UART) baud rates.
*
* @version UART Driver Version 3.0.2
*/
/*
<EFBFBD> [2025] 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.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef UART_TYPES_H
#define UART_TYPES_H
/**
Section: Included Files
*/
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Section: Data Type Definitions
*/
/**
@ingroup uartdriver
@enum UART_STANDARD_BAUDS
@brief This Enum can be used to set the UART standard
baud rates using \ref UARTx_BRGSet function e.g. \ref UART1_BRGSet.
*/
enum UART_STANDARD_BAUDS{
UART_110 = 0,
UART_300 = 1,
UART_600 = 2,
UART_1200 = 3,
UART_2400 = 4,
UART_4800 = 5,
UART_9600 = 6,
UART_14400 = 7,
UART_19200 = 8,
UART_38400 = 9,
UART_57600 = 10,
UART_115200 = 11,
UART_230400 = 12,
UART_460800 = 13,
UART_921600 = 14,
};
#ifdef __cplusplus
}
#endif
#endif /* UART_TYPES_H */