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,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
*/