summaryrefslogtreecommitdiff
path: root/mcc_generated_files
diff options
context:
space:
mode:
authorJoshua Drake <joshua.ellis.drake@gmail.com>2024-04-23 01:27:55 -0500
committerJoshua Drake <joshua.ellis.drake@gmail.com>2024-04-23 01:27:55 -0500
commit319b3a68ee64d8549524b53fba2934e94c07d19e (patch)
treeffe9a3f58471d139a3020d0592e040242b145ab5 /mcc_generated_files
parentbe339d49fcfd3a09b8fdf590001e8e0f4369e4d3 (diff)
Added files that were forgotten in previous commits.
Diffstat (limited to 'mcc_generated_files')
-rw-r--r--mcc_generated_files/clock.c72
-rw-r--r--mcc_generated_files/clock.h80
-rw-r--r--mcc_generated_files/interrupt_manager.c62
-rw-r--r--mcc_generated_files/interrupt_manager.h167
-rw-r--r--mcc_generated_files/mcc.c47
-rw-r--r--mcc_generated_files/mcc.h65
-rw-r--r--mcc_generated_files/mssp1_spi.c148
-rw-r--r--mcc_generated_files/mssp1_spi.h254
-rw-r--r--mcc_generated_files/mssp2_i2c.c386
-rw-r--r--mcc_generated_files/mssp2_i2c.h488
-rw-r--r--mcc_generated_files/pin_manager.c92
-rw-r--r--mcc_generated_files/pin_manager.h1113
-rw-r--r--mcc_generated_files/system.c106
-rw-r--r--mcc_generated_files/system.h70
-rw-r--r--mcc_generated_files/tmr1.c219
-rw-r--r--mcc_generated_files/tmr1.h331
-rw-r--r--mcc_generated_files/traps.c122
-rw-r--r--mcc_generated_files/traps.h86
18 files changed, 3908 insertions, 0 deletions
diff --git a/mcc_generated_files/clock.c b/mcc_generated_files/clock.c
new file mode 100644
index 0000000..2d07d28
--- /dev/null
+++ b/mcc_generated_files/clock.c
@@ -0,0 +1,72 @@
+/**
+ @Generated PIC24 / dsPIC33 / PIC32MM MCUs Source File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ clock.c
+
+ @Summary:
+ This is the clock.c file generated using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description:
+ This header file provides implementations for driver APIs for all modules selected in the GUI.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#include <stdint.h>
+#include "xc.h"
+#include "clock.h"
+
+void CLOCK_Initialize(void)
+{
+ // RCDIV FRC/2; DOZE 1:8; DOZEN disabled; ROI disabled;
+ CLKDIV = 0x3100;
+ // TUN Center frequency;
+ OSCTUN = 0x00;
+ // ROEN disabled; ROSEL FOSC; RODIV 0; ROSSLP disabled;
+ REFOCON = 0x00;
+ // ADC1MD enabled; SSP1MD enabled; T1MD enabled; U2MD enabled; U1MD enabled;
+ PMD1 = 0x00;
+ // CCP2MD enabled; CCP1MD enabled; CCP4MD enabled; CCP3MD enabled; CCP5MD enabled;
+ PMD2 = 0x00;
+ // SSP2MD enabled; RTCCMD enabled; CMPMD enabled; DAC1MD enabled;
+ PMD3 = 0x00;
+ // CTMUMD enabled; REFOMD enabled; ULPWUMD enabled; HLVDMD enabled;
+ PMD4 = 0x00;
+ // AMP2MD enabled; AMP1MD enabled; DAC2MD enabled;
+ PMD6 = 0x00;
+ // CLC1MD enabled; CLC2MD enabled;
+ PMD8 = 0x00;
+ // CF no clock failure; NOSC PRI; SOSCEN disabled; SOSCDRV disabled; CLKLOCK unlocked; OSWEN Switch is Complete;
+ __builtin_write_OSCCONH((uint8_t) (0x02));
+ __builtin_write_OSCCONL((uint8_t) (0x00));
+}
diff --git a/mcc_generated_files/clock.h b/mcc_generated_files/clock.h
new file mode 100644
index 0000000..6b6c2d7
--- /dev/null
+++ b/mcc_generated_files/clock.h
@@ -0,0 +1,80 @@
+/**
+ @Generated PIC24 / dsPIC33 / PIC32MM MCUs Source File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ clock.h
+
+ @Summary:
+ This is the clock.h file generated using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description:
+ This header file provides implementations for driver APIs for all modules selected in the GUI.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#ifndef CLOCK_H
+#define CLOCK_H
+
+/**
+ Section: Included Files
+*/
+
+#include <stdbool.h>
+
+#ifndef _XTAL_FREQ
+#define _XTAL_FREQ 20000000UL
+#endif
+
+#define CLOCK_SystemFrequencyGet() (20000000UL)
+
+#define CLOCK_PeripheralFrequencyGet() (CLOCK_SystemFrequencyGet() / 2)
+
+#define CLOCK_InstructionFrequencyGet() (CLOCK_SystemFrequencyGet() / 2)
+/**
+ * @Param
+ none
+ * @Returns
+ none
+ * @Description
+ Initializes the oscillator to the default states configured in the
+ * MCC GUI
+ * @Example
+ CLOCK_Initialize(void);
+ */
+void CLOCK_Initialize(void);
+
+
+#endif /* CLOCK_H */
+/**
+ End of File
+*/ \ No newline at end of file
diff --git a/mcc_generated_files/interrupt_manager.c b/mcc_generated_files/interrupt_manager.c
new file mode 100644
index 0000000..cc601c1
--- /dev/null
+++ b/mcc_generated_files/interrupt_manager.c
@@ -0,0 +1,62 @@
+/**
+ System Interrupts Generated Driver File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ interrupt_manager.h
+
+ @Summary:
+ This is the generated driver implementation file for setting up the
+ interrupts using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description:
+ This source file provides implementations for PIC24 / dsPIC33 / PIC32MM MCUs interrupts.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+/**
+ Section: Includes
+*/
+#include <xc.h>
+
+/**
+ void INTERRUPT_Initialize (void)
+*/
+void INTERRUPT_Initialize (void)
+{
+ // SSPI: MSSP2 - I2C/SPI Interrupt
+ // Priority: 1
+ IPC12bits.SSP2IP = 1;
+ // TI: T1 - Timer1
+ // Priority: 1
+ IPC0bits.T1IP = 1;
+
+}
diff --git a/mcc_generated_files/interrupt_manager.h b/mcc_generated_files/interrupt_manager.h
new file mode 100644
index 0000000..e88d4cc
--- /dev/null
+++ b/mcc_generated_files/interrupt_manager.h
@@ -0,0 +1,167 @@
+/**
+ System Interrupts Generated Driver File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ interrupt_manager.h
+
+ @Summary:
+ This is the generated driver implementation file for setting up the
+ interrupts using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description:
+ This source file provides implementations for PIC24 / dsPIC33 / PIC32MM MCUs interrupts.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#ifndef _INTERRUPT_MANAGER_H
+#define _INTERRUPT_MANAGER_H
+
+/**
+ @Summary
+ Initializes the interrupt priorities of the PIC24FV16KM202
+
+ @Description
+ This routine sets the interrupt priorities of the modules that have been configured
+ for the PIC24FV16KM202
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ void SYSTEM_Initialize(void)
+ {
+ // Other initializers are called from this function
+ INTERRUPT_Initialize ();
+ }
+ </code>
+
+*/
+void INTERRUPT_Initialize(void);
+
+/**
+ @Summary
+ Enables global interrupts of the PIC24FV16KM202
+
+ @Description
+ This routine enables the global interrupt bit for the PIC24FV16KM202
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ void SYSTEM_Initialize(void)
+ {
+ // Other initializers are called from this function
+ INTERRUPT_GlobalEnable ();
+ }
+ </code>
+
+*/
+inline static void INTERRUPT_GlobalEnable(void)
+{
+ __builtin_enable_interrupts();
+}
+
+/**
+ @Summary
+ Disables global interrupts of the PIC24FV16KM202
+
+ @Description
+ This routine disables the global interrupt bit for the PIC24FV16KM202
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ void SYSTEM_Initialize(void)
+ {
+ // Other initializers are called from this function
+ INTERRUPT_GlobalDisable ();
+ }
+ </code>
+
+*/
+inline static void INTERRUPT_GlobalDisable(void)
+{
+ __builtin_disable_interrupts();
+}
+
+/**
+ @Summary
+ Returns the interrupt vector number of the interrupt which is pending.
+
+ @Description
+ This routine returns the interrupt vector number of the interrupt which is pending.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ uint16_t ivrNum;
+ ivrNum = INTERRUPT_VectorNumberGet();
+ </code>
+
+*/
+inline static uint16_t INTERRUPT_VectorNumberGet(void)
+{
+ return _VECNUM;
+}
+
+#endif \ No newline at end of file
diff --git a/mcc_generated_files/mcc.c b/mcc_generated_files/mcc.c
new file mode 100644
index 0000000..f842343
--- /dev/null
+++ b/mcc_generated_files/mcc.c
@@ -0,0 +1,47 @@
+/**
+ @Generated PIC24 / dsPIC33 / PIC32MM MCUs Source File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ mcc.c
+
+ @Summary:
+ This is the mcc.c file generated using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description:
+ The configuration contents of this file are moved to system.c and this file will be removed in future MCC releases.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+/**
+ End of File
+*/ \ No newline at end of file
diff --git a/mcc_generated_files/mcc.h b/mcc_generated_files/mcc.h
new file mode 100644
index 0000000..090afe8
--- /dev/null
+++ b/mcc_generated_files/mcc.h
@@ -0,0 +1,65 @@
+/**
+ @Generated PIC24 / dsPIC33 / PIC32MM MCUs Header File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ mcc.h
+
+ @Summary:
+ This is the mcc.h file generated using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description:
+ This file will be removed in future MCC releases. Use system.h instead.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#ifndef MCC_H
+#define MCC_H
+#include <xc.h>
+#include "system.h"
+#include "clock.h"
+#include "pin_manager.h"
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "tmr1.h"
+#include "interrupt_manager.h"
+#include "traps.h"
+#include "mssp1_spi.h"
+#include "mssp2_i2c.h"
+
+#warning "This file will be removed in future MCC releases. Use system.h instead."
+
+#endif /* MCC_H */
+/**
+ End of File
+*/ \ No newline at end of file
diff --git a/mcc_generated_files/mssp1_spi.c b/mcc_generated_files/mssp1_spi.c
new file mode 100644
index 0000000..d776f9e
--- /dev/null
+++ b/mcc_generated_files/mssp1_spi.c
@@ -0,0 +1,148 @@
+/**
+ MSSP1_SPI Generated Driver API Header File
+
+ @Company
+ Microchip Technology Inc.
+
+ @File Name
+ mssp1_spi.c
+
+ @Summary
+ This is the generated source file for the MSSP1_SPI driver using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description
+ This source file provides APIs for driver for MSSP1_SPI.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+/**
+ Section: Included Files
+*/
+
+#include "mssp1_spi.h"
+
+/**
+ Section: Driver Interface
+*/
+
+
+void MSSP1_SPI_Initialize (void)
+{
+ // SMP End; CKE Idle to Active;
+ SSP1STAT = 0x80;
+ // SSPEN enabled; WCOL no_collision; CKP Idle:Low, Active:High; SSPM FOSC/(2 * (BRG_Value_SPI + 1)); SSPOV no_overflow;
+ SSP1CON1 = 0x2A;
+ // ACKEN disabled; GCEN disabled; PEN disabled; ACKDT acknowledge; RSEN disabled; RCEN disabled; SEN disabled;
+ SSP1CON2 = 0x00;
+ // SBCDE disabled; BOEN disabled; SCIE disabled; PCIE disabled; DHEN disabled; SDAHT 100ns; AHEN disabled;
+ SSP1CON3 = 0x00;
+ // AMSK 0;
+ SSP1MSK = 0x00;
+ // SSPADD 1;
+ SSP1ADD = 0x01;
+}
+
+uint8_t MSSP1_SPI_Exchange8bit( uint8_t data )
+{
+
+ SSP1BUF = data;
+
+ while (SSP1STATbits.BF == false)
+ {
+
+ }
+
+ return SSP1BUF;
+}
+
+uint8_t MSSP1_SPI_Exchange8bitBuffer(uint8_t *dataTransmitted, uint8_t bufLen, uint8_t *dataReceived)
+{
+ uint16_t bytesWritten = 0;
+
+ if(dataTransmitted != NULL)
+ {
+ if(dataReceived != NULL)
+ {
+ while(bytesWritten < bufLen )
+ {
+ dataReceived[bytesWritten] = MSSP1_SPI_Exchange8bit(dataTransmitted[bytesWritten]);
+ bytesWritten++;
+ }
+ }else
+ {
+ while(bytesWritten < bufLen )
+ {
+ MSSP1_SPI_Exchange8bit(dataTransmitted[bytesWritten]);
+ bytesWritten++;
+ }
+ }
+ }
+ else
+ {
+ if(dataReceived != NULL)
+ {
+ while(bytesWritten < bufLen )
+ {
+ dataReceived[bytesWritten] = MSSP1_SPI_Exchange8bit(MSSP1_SPI_DUMMY_DATA);
+ bytesWritten++;
+ }
+ }
+ }
+ return bytesWritten;
+}
+
+bool MSSP1_SPI_IsBufferFull( void )
+{
+ return (!SSP1STATbits.BF);
+}
+
+bool MSSP1_SPI_HasWriteCollisionOccured( void )
+{
+ return (!SSP1CON1bits.WCOL);
+}
+
+bool MSSP1_SPI_HasReceiveOverflowOccured( void )
+{
+ return (!SSP1CON1bits.SSPOV);
+}
+void SPI_slaveSelect(void)
+{
+ _LATB15 = 0;
+}
+
+
+void SPI_slaveDeselect(void)
+{
+ _LATB15 = 1;
+}
+
+/**
+ End of File
+*/
diff --git a/mcc_generated_files/mssp1_spi.h b/mcc_generated_files/mssp1_spi.h
new file mode 100644
index 0000000..83b648d
--- /dev/null
+++ b/mcc_generated_files/mssp1_spi.h
@@ -0,0 +1,254 @@
+/**
+ MSSP1_SPI Generated Driver API Header File
+
+ @Company
+ Microchip Technology Inc.
+
+ @File Name
+ mssp1_spi.h
+
+ @Summary
+ This is the generated header file for the MSSP1_SPI driver using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description
+ This header file provides APIs for driver for MSSP1_SPI.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#ifndef _MSSP1_SPI_H
+#define _MSSP1_SPI_H
+
+/**
+ Section: Included Files
+*/
+#include <xc.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+#ifdef __cplusplus // Provide C++ Compatibility
+
+ extern "C" {
+
+#endif
+
+/**
+ Section: Data Type Definitions
+*/
+//This definition is used during read operation of SPI
+#define MSSP1_SPI_DUMMY_DATA 0x0
+
+/**
+ Section: Interface Routines
+*/
+
+/**
+ @Summary
+ Initializes the MSSP instance : 1
+
+ @Description
+ This routine initializes the mssp1_spi driver instance for : 1
+ index, making it ready for clients to open and use it.
+ This routine must be called before any other MSSP1_SPI routine is called.
+ This routine should only be called once during system initialization.
+
+ @Preconditions
+ None.
+
+ @Param
+ None.
+
+ @Returns
+ None.
+
+ @Example
+ <code>
+ uint16_t myWriteBuffer[MY_BUFFER_SIZE];
+ uint16_t myReadBuffer[MY_BUFFER_SIZE];
+ uint16_t writeData;
+ uint16_t readData;
+ unsigned int total;
+ MSSP1_SPI_Initialize;
+
+ total = 0;
+ do
+ {
+ total = MSSP1_SPI_Exchange8bitBuffer( &myWriteBuffer[total], MY_BUFFER_SIZE - total, &myWriteBuffer[total]);
+
+ // Do something else...
+
+ } while( total < MY_BUFFER_SIZE );
+
+ readData = MSSP1_SPI_Exchange8bit( writeData);
+
+ </code>
+
+*/
+void MSSP1_SPI_Initialize (void);
+
+/**
+ @Summary
+ Exchanges one byte of data from MSSP1_SPI
+
+ @Description
+ This routine exchanges one byte of data from the MSSP1_SPI.
+ This is a blocking routine.
+
+ @Preconditions
+ The MSSP1_SPI_Initialize routine must have been called for the specified
+ MSSP1_SPI driver instance.
+
+ @Param
+ data - Data to be written onto MSSP1_SPI.
+
+ @Returns
+ Data read from MSSP1_SPI
+
+ @Example
+ Refer to MSSP1_SPI_Initialize() for an example
+
+*/
+uint8_t MSSP1_SPI_Exchange8bit( uint8_t data );
+
+/**
+ @Summary
+ Exchanges data from a buffer of size one byte from MSSP1_SPI
+
+ @Description
+ This routine exchanges data from a buffer of size one byte from the MSSP1_SPI.
+ This is a blocking routine.
+
+ @Preconditions
+ The MSSP1_SPI_Initialize routine must have been called for the specified
+ MSSP1_SPI driver instance.
+
+ @Param
+ dataTransmitted - Buffer of data to be written from MSSP1_SPI.
+ bufLen - Number of words to be exchanged.
+ dataReceived - Buffer of data to be read into MSSP1_SPI.
+
+ @Returns
+ Number of words written/read.
+
+ @Example
+ Refer to MSSP1_SPI_Initialize() for an example
+
+*/
+uint8_t MSSP1_SPI_Exchange8bitBuffer(uint8_t *dataTransmitted, uint8_t bufLen, uint8_t *dataReceived);
+
+/**
+ @Summary
+ Gets the status of the buffer if its full.
+
+ @Description
+ This routine gets the status of the buffer if its full.
+
+ @Preconditions
+ The MSSP1_SPI_Initialize routine must have been called for the specified
+ MSSP1_SPI driver instance.
+
+ @Param
+ None.
+
+ @Returns
+ true - if the buffer is full
+ false - if the buffer is not full.
+
+ @Example
+ Refer to MSSP1_SPI_Initialize() for an example
+
+*/
+bool MSSP1_SPI_IsBufferFull( void );
+
+/**
+ @Summary
+ Gets the status of write collision.
+
+ @Description
+ This routine gets the status of write collision.
+
+ @Preconditions
+ The MSSP1_SPI_Initialize routine must have been called for the specified
+ MSSP1_SPI driver instance.
+
+ @Param
+ None.
+
+ @Returns
+ true - if the write collision has occurred.
+ false - if the write collision has not occurred.
+
+ @Example
+ Refer to MSSP1_SPI_Initialize() for an example
+
+*/
+bool MSSP1_SPI_HasWriteCollisionOccured( void );
+
+/**
+ @Summary
+ Gets the status of receive overflow.
+
+ @Description
+ This routine gets the status of receive overflow.
+
+ @Preconditions
+ The MSSP1_SPI_Initialize routine must have been called for the specified
+ MSSP1_SPI driver instance.
+
+ @Param
+ None.
+
+ @Returns
+ true - if receive overflow has occurred.
+ false - if receive overflow has not occurred.
+
+ @Example
+ Refer to MSSP1_SPI_Initialize() for an example
+
+*/
+bool MSSP1_SPI_HasReceiveOverflowOccured( void );
+
+void SPI_slaveSelect(void);
+
+
+void SPI_slaveDeselect(void);
+
+
+#ifdef __cplusplus // Provide C++ Compatibility
+
+ }
+
+#endif
+
+#endif //_MSSP1_SPI_H
+
+/**
+ End of File
+*/
diff --git a/mcc_generated_files/mssp2_i2c.c b/mcc_generated_files/mssp2_i2c.c
new file mode 100644
index 0000000..67646e1
--- /dev/null
+++ b/mcc_generated_files/mssp2_i2c.c
@@ -0,0 +1,386 @@
+/**
+ MSSP2_I2C Generated Driver File
+
+ @Company
+ Microchip Technology Inc.
+
+ @File Name
+ mssp2_i2c.c
+
+ @Summary
+ This is the generated source file for the MSSP2_I2C driver using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description
+ This source file provides APIs for driver for MSSP2_I2C.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#include "mssp2_i2c.h"
+
+/**
+ Section: Data Types
+*/
+
+/**
+ I2C Slave Driver State Enumeration
+
+ @Summary
+ Defines the different states of the i2c slave.
+
+ @Description
+ This defines the different states that the i2c slave
+ used to process transactions on the i2c bus.
+*/
+typedef enum
+{
+ S_SLAVE_IDLE,
+ S_SLAVE_RECEIVE_MODE,
+ S_SLAVE_TRANSMIT_MODE,
+ S_SLAVE_LOW_BYTE_ADDRESS_DETECT,
+
+} I2C_SLAVE_STATES;
+
+/**
+ I2C uint16_t union
+
+ @Summary
+ Defines the data type to easily manage the slave addresses.
+
+ @Description
+ This defines the data type to easily swap between lsb and msb
+ of the slave address when doing 10-bit addressing.
+ */
+typedef union
+{
+ uint8_t uint168BitValue[2];
+ uint16_t uint16Value;
+}UINT16_UNION;
+
+/**
+ Section: Macro Definitions
+*/
+
+/* defined for MSSP2_I2C */
+
+#define MSSP2_I2C_TRANSMIT_REG SSP2BUF // Defines the transmit register used to send data.
+#define MSSP2_I2C_RECEIVE_REG SSP2BUF // Defines the receive register used to receive data.
+
+#define MSSP2_I2C_MASK_REG SSP2MSK // Defines the address mask register.
+#define MSSP2_I2C_ADDRESS_REG SSP2ADD // Defines the address register.
+
+// The following control bits are used in the I2C state machine to manage
+// the I2C module and determine next states.
+#define MSSP2_I2C_SERIAL_PORT_ENABLE_BIT SSP2CON1bits.SSPEN // I2C port enable control bit.
+#define MSSP2_I2C_MODE_SELECT_BITS SSP2CON1bits.SSPM // I2C Slave Mode control bit.
+#define MSSP2_I2C_RELEASE_SCL_CLOCK_CONTROL_BIT SSP2CON1bits.CKP // I2C clock stretch/release control bit.
+#define MSSP2_I2C_RECEIVE_OVERFLOW_STATUS_BIT SSP2CON1bits.SSPOV // I2C receive buffer overflow status bit.
+#define MSSP2_I2C_ACKNOWLEDGE_STATUS_BIT SSP2CON2bits.ACKSTAT // I2C ACK status bit.
+
+// The following status bits are used in the I2C state machine to determine
+// the next states.
+#define MSSP2_I2C_READ_NOT_WRITE_STATUS_BIT SSP2STATbits.R_NOT_W // I2C current transaction read/write status bit.
+#define MSSP2_I2C_DATA_NOT_ADDRESS_STATUS_BIT SSP2STATbits.D_NOT_A // I2C last byte receive was data/address status bit.
+
+/**
+ Section: Local Functions
+*/
+
+inline void __attribute__ ((always_inline)) MSSP2_I2C_TransmitProcess(void);
+inline void __attribute__ ((always_inline)) MSSP2_I2C_ReceiveProcess(void);
+
+/**
+ Section: Local Variables
+*/
+
+static I2C_SLAVE_STATES mssp2_i2c_slave_state;
+static uint8_t *p_mssp2_i2c_write_pointer;
+static uint8_t *p_mssp2_i2c_read_pointer;
+static UINT16_UNION mssp2_i2c_slave_address;
+uint8_t yeah;
+
+#define ARRAY_CNT 6 // Number of bytes in array
+uint8_t slaveAddress = 0x30; // 7-bit slave address
+uint8_t index = 0; // Array pointer
+uint8_t temp = 0; // Temp register
+uint8_t regAdd = 1; // First data byte was reg add
+uint8_t i2cArray[ARRAY_CNT] =
+{0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+
+/**
+ Prototype: void MSSP2_I2C_Initialize(void)
+ Input: none
+ Output: none
+ Description: MSSP2_I2C_Initialize is an
+ initialization routine that takes inputs from the GUI.
+ Usage: MSSP2_I2C_Initialize();
+*/
+void MSSP2_I2C_Initialize(void)
+{
+
+ // initialize the state
+ mssp2_i2c_slave_state = S_SLAVE_IDLE;
+
+ MSSP2_I2C_ReadPointerSet(NULL);
+ MSSP2_I2C_WritePointerSet(NULL);
+
+ // initialize the hardware
+ // SMP Standard Speed; CKE Idle to Active;
+ SSP2STAT = 0x80;
+ // SSPEN enabled; WCOL no_collision; CKP Clock Stretch; SSPM 7 Bit; SSPOV no_overflow;
+ SSP2CON1 = 0x2E & 0x26;
+ // ACKEN disabled; GCEN disabled; PEN disabled; ACKDT acknowledge; RSEN disabled; RCEN disabled; SEN enabled;
+ SSP2CON2 = 0x01;
+ // SBCDE disabled; BOEN enabled; SCIE disabled; PCIE disabled; DHEN disabled; SDAHT 300ns; AHEN disabled;
+ SSP2CON3 = 0x18 | 0x01;
+ // AMSK 0;
+ SSP2MSK = 0x00;
+ // Set up the slave address: SSPADD 7;
+ //MSSP2_I2C_SlaveAddressSet(0x07);
+
+ SSP2ADD = 0x30;
+ IFS3bits.BCL2IF = 0; // Clear Bus Collision IF
+
+
+ /* MSSP2 - I2C/SPI Interrupt */
+ // clear the master interrupt flag
+ IFS3bits.SSP2IF = 0;
+ // enable the master interrupt
+ IEC3bits.SSP2IE = 1;
+}
+
+void __attribute__((interrupt, no_auto_psv)) _MSSP2Interrupt(void) {
+ if (IFS3bits.SSP2IF) // Check for SSPIF
+ {
+ if (SSP2STATbits.R_NOT_W == 1) // Master read (slave transmit)
+ {
+ temp = SSP2BUF;
+ SSP2BUF = i2cArray[1]; // Load array value
+ SSP2CON1bits.CKP = 1; // Release clock stretch
+ }
+ if (SSP2STATbits.R_NOT_W == 0) // Master write (slave receive)
+ {
+ TMR1 = 0x00; //Reset our timer when a message is received.
+ if (SSP2STATbits.D_NOT_A == 0) // Last byte was an address
+ {
+ _LATB7 = !_LATB7;
+ regAdd = 1; // Next byte register address
+ temp = SSP2BUF; // Clear BF
+ SSP2CON1bits.CKP = 1; // Release clock stretch
+ }
+ if (SSP2STATbits.D_NOT_A == 1) // Last byte was data
+ {
+ if (regAdd == 1) // Last byte was register add
+ {
+ index = SSP2BUF; // Load register address
+ regAdd = 0; // Next byte will be true data
+ } else {
+ if (index < ARRAY_CNT) // Within boundaries?
+ {
+ i2cArray[index] = SSP2BUF; // Yes, read SSP1BUF
+ } else {
+ temp = SSP2BUF; // No, discard data
+ }
+ }
+ SSP2CON1bits.CKP = 1; // Release clock stretch
+ }
+ }
+ }
+ if ((IFS3bits.BCL2IF == 1) || (SSP2CON1bits.SSPOV == 1)) {
+ temp = SSP2BUF; // Clear BF
+ IFS3bits.BCL2IF = 0; // Clear BCLIF
+ SSP2CON1bits.SSPOV = 0;
+ SSP2CON1bits.CKP = 1; // Release clock stretching
+ }
+ IFS3bits.SSP2IF = 0; // Clear SSP1IF
+ _LATB8 = !SSP2CON1bits.SSPOV;
+}
+
+void MSSP2_I2C_ReadPointerSet(uint8_t *p)
+{
+ p_mssp2_i2c_read_pointer = p;
+}
+
+
+void MSSP2_I2C_WritePointerSet(uint8_t *p)
+{
+ p_mssp2_i2c_write_pointer = p;
+}
+
+
+uint8_t *MSSP2_I2C_ReadPointerGet(void)
+{
+ return (p_mssp2_i2c_read_pointer);
+}
+
+
+uint8_t *MSSP2_I2C_WritePointerGet(void)
+{
+ return (p_mssp2_i2c_write_pointer);
+}
+
+void MSSP2_I2C_SlaveAddressMaskSet(
+ uint16_t mask)
+{
+ MSSP2_I2C_MASK_REG = mask;
+}
+
+void MSSP2_I2C_SlaveAddressSet(
+ uint16_t address)
+{
+ UINT16_UNION add;
+
+ add.uint16Value = address;
+
+ if (address > 0xFF)
+ {
+ // use 10 bit address
+ add.uint168BitValue[1] = (0xF0 | ((add.uint168BitValue[1] << 1) & 0x06));
+ MSSP2_I2C_ADDRESS_REG = add.uint168BitValue[1];
+ }
+ else
+ {
+ // use 7 bit address
+ MSSP2_I2C_ADDRESS_REG = add.uint168BitValue[0];
+ }
+ mssp2_i2c_slave_address.uint16Value = add.uint16Value;
+
+}
+
+inline void __attribute__ ((always_inline)) MSSP2_I2C_TransmitProcess(void)
+{
+ // get the data to be transmitted
+
+ // sanity check (to avoid stress)
+ if (p_mssp2_i2c_read_pointer == NULL)
+ return;
+
+ //MSSP2_I2C_TRANSMIT_REG = *p_mssp2_i2c_read_pointer;
+ MSSP2_I2C_TRANSMIT_REG = yeah;
+
+ // set the SCL clock to be released
+ MSSP2_I2C_RELEASE_SCL_CLOCK_CONTROL_BIT = 1;
+
+}
+
+inline void __attribute__ ((always_inline)) MSSP2_I2C_ReceiveProcess(void)
+{
+ // store the received data
+
+ // sanity check (to avoid stress)
+ if (p_mssp2_i2c_write_pointer == NULL)
+ return;
+
+ *p_mssp2_i2c_write_pointer = MSSP2_I2C_RECEIVE_REG;
+
+}
+
+/* Note: This is an example of the MSSP2_I2C_StatusCallback()
+ implementation. This is an emulated EEPROM Memory
+ configured to act as a I2C Slave Device.
+ For specific slave device implementation, remove
+ or modify this function to the specific slave device
+ behavior.
+*/
+
+static uint8_t mssp2_i2c_slaveWriteData = 0xAA;
+
+bool MSSP2_I2C_StatusCallback(MSSP2_I2C_SLAVE_DRIVER_STATUS status)
+{
+
+ // this emulates the slave device memory where data written to slave
+ // is placed and data read from slave is taken
+ static uint8_t EMULATE_EEPROM_Memory[5] =
+ {
+ 0x30, 0x31, 0x32, 0x33, 0x34
+ };
+
+ static uint16_t address = 0;
+ static bool addressState = true;
+
+ switch (status)
+ {
+ case MSSP2_I2C_SLAVE_TRANSMIT_REQUEST_DETECTED:
+
+ // set up the slave driver buffer transmit pointer
+ //MSSP2_I2C_ReadPointerSet(&EMULATE_EEPROM_Memory[address]);
+ //address++;
+ //if(address > 5) address = 0;
+ SSP2BUF = yeah;
+
+ break;
+
+ case MSSP2_I2C_SLAVE_RECEIVE_REQUEST_DETECTED:
+
+ addressState = true;
+
+ // set up the slave driver buffer receive pointer
+ MSSP2_I2C_WritePointerSet(&mssp2_i2c_slaveWriteData);
+
+ break;
+
+ case MSSP2_I2C_SLAVE_RECEIVED_DATA_DETECTED:
+
+ /* if (addressState == true)
+ {
+
+ address = mssp2_i2c_slaveWriteData;
+ addressState = false;
+ if(address > 31) _LATB6=0;
+ else _LATB6=1;
+ }
+ else // if (addressState == false)
+ {
+ // set the memory with the received data
+ EMULATE_EEPROM_Memory[address] = mssp2_i2c_slaveWriteData;
+
+ }*/
+ yeah = SSP2BUF;
+ if(yeah > 100) _LATB6=0;
+ else _LATB6=1;
+
+ break;
+
+ case MSSP2_I2C_SLAVE_10BIT_RECEIVE_REQUEST_DETECTED:
+
+ // do something here when 10-bit address is detected
+
+ // 10-bit address is detected
+
+ break;
+
+ default:
+ break;
+
+ }
+
+ return true;
+}
+
diff --git a/mcc_generated_files/mssp2_i2c.h b/mcc_generated_files/mssp2_i2c.h
new file mode 100644
index 0000000..3fbd36c
--- /dev/null
+++ b/mcc_generated_files/mssp2_i2c.h
@@ -0,0 +1,488 @@
+/**
+ MSSP2_I2C Generated Driver API Header File
+
+ @Company
+ Microchip Technology Inc.
+
+ @File Name
+ mssp2_i2c.h
+
+ @Summary
+ This is the generated header file for the MSSP2_I2C driver using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description
+ This header file provides APIs for driver for MSSP2_I2C.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#ifndef _MSSP2_I2C_H
+#define _MSSP2_I2C_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <xc.h>
+
+#ifdef __cplusplus //* Provide C++ Compatibility */
+
+ extern "C" {
+
+#endif
+
+/**
+ I2C Slave Driver Status
+
+ @Summary
+ Defines the different status that the slave driver has
+ detected over the i2c bus.
+
+ @Description
+ This defines the different status that the slave driver has
+ detected over the i2c bus. The status is passed to the
+ MSSP2_I2C_StatusCallback() callback function that is implemented by
+ the user of the slave driver as a parameter to inform the user
+ that there was a change in the status of the driver due to
+ transactions on the i2c bus. User of the slave driver can use these
+ to manage the read or write buffers.
+
+ */
+
+typedef enum
+{
+ /* This state indicates that the slave driver has detected a transmit request from the master.
+ The next transaction will be a read transaction. Application should prime the transmit
+ buffer with the valid data to be sent to the master using the: I2C2_ReadPointerSet()
+
+ */
+ MSSP2_I2C_SLAVE_TRANSMIT_REQUEST_DETECTED,
+
+ /* This state indicates that the slave driver has detected a reception request from the master.
+ The next transaction will be a write transaction. Application should set up the receive
+ buffer by setting the location of the receive buffer using the: I2C2_WritePointerSet()
+ */
+ MSSP2_I2C_SLAVE_RECEIVE_REQUEST_DETECTED,
+
+ /* This state indicates that the slave driver has received data from the master.
+ Application can use this status to process the received data set up the receive
+ buffer in anticipation of next reception in case the master sends more data.
+ See MSSP2_I2C_SLAVE_RECEIVE_REQUEST_DETECTED.
+ */
+ MSSP2_I2C_SLAVE_RECEIVED_DATA_DETECTED,
+
+ /* This state indicates that the slave driver has detected the most significant
+ byte of the 10-bit slave address. Another transaction with the least
+ significant byte of the 10-bit address with a read/write request will
+ be detected next. This second detection is automatically done by the
+ driver which may return one of the following:
+ a. MSSP2_I2C_SLAVE_RECEIVE_REQUEST_DETECTED
+ b. MSSP2_I2C_SLAVE_TRANSMIT_REQUEST_DETECTED
+ c. MSSP2_I2C_SLAVE_10BIT_RECEIVE_REQUEST_DETECTED
+ a or b is detected depending on the read/write bit of the received
+ control data. If c is detected next, the master decided to resend
+ the most significant address.
+ */
+ MSSP2_I2C_SLAVE_10BIT_RECEIVE_REQUEST_DETECTED,
+
+} MSSP2_I2C_SLAVE_DRIVER_STATUS;
+
+#define MSSP2_I2C_SLAVE_DEFAULT_ADDRESS 0x7
+
+/**
+ @Summary
+ Initializes and enables the i2c slave instance : 2
+
+ @Description
+ This routine initializes the i2c slave driver instance for : 2
+ index, making it ready for clients to open and use it.
+
+ @Preconditions
+ None
+
+ @Param
+ None
+
+ @Returns
+ None
+
+ @Example
+ <code>
+
+ uint8_t SlaveReadBuffer;
+ uint8_t SlaveWriteBuffer;
+
+ // initialize the i2c slave driver
+ MSSP2_I2C_Initialize();
+
+ // set up the slave driver
+
+ // initialize the location of the read buffer
+ MSSP2_I2C_ReadPointerSet(SlaveReadBuffer);
+ // initialize the location of the write buffer
+ MSSP2_I2C_WritePointerSet(SlaveWriteBuffer);
+
+ </code>
+*/
+
+void MSSP2_I2C_Initialize(void);
+
+
+/**
+ @Summary
+ This function sets the slave address mask.
+
+ @Description
+ This function sets the 10-bit slave address mask to be able to
+ respond to multiple addresses. This function should be called
+ after the initialization of the module.
+
+ @Preconditions
+ None
+
+ @Param
+ mask - The address mask to be used when filtering
+ addresses from the i2c master transactions.
+
+ @Returns
+ None
+
+ @Example
+ <code>
+ Refer to MSSP2_I2C_SlaveAddressSet() for an example
+ </code>
+
+*/
+
+void MSSP2_I2C_SlaveAddressMaskSet(
+ uint16_t mask);
+
+/**
+ @Summary
+ This function sets the slave address.
+
+ @Description
+ This function sets the 10-bit slave address to be used by the
+ module when filtering transactions from the i2c masters in the
+ bus. The function analyzes the given address and decides if
+ the 10-bit or 7-bit mode will be enabled. Once the function
+ returns, the given address is set for the slave module.
+
+ This function should be called after the initialization of
+ the module.
+
+ When changing the slave address the module must be idle.
+
+ @Preconditions
+ None
+
+ @Param
+ address - The address to be used to determine if the transaction
+ is intended for this slave module.
+
+ @Returns
+ None
+
+ @Example
+ <code>
+ // initialize the i2c slave driver
+ MSSP2_I2C_Initializer();
+
+ // set the slave address and address mask if the default
+ // values set in the initialize is not the desired values.
+ MSSP2_I2C_SlaveAddressMaskSet(0x0xF);
+ MSSP2_I2C_SlaveAddressSet(0x3C);
+
+ </code>
+
+*/
+
+void MSSP2_I2C_SlaveAddressSet(
+ uint16_t address);
+
+/**
+ @Summary
+ This function sets the read pointer for the slave driver.
+
+ @Description
+ This function sets the read pointer that the driver will
+ need to retrieve data that will be transmitted to the master
+ whenever the master requests a read.
+
+ @Preconditions
+ None
+
+ @Param
+ *p - The pointer to the read buffer, that will be used to transmit
+ data to the requesting i2c master.
+
+ @Returns
+ None
+
+ @Example
+ <code>
+ Refer to MSSP2_I2C_Initialize() for an example
+ </code>
+
+*/
+
+void MSSP2_I2C_ReadPointerSet(uint8_t *p);
+
+/**
+ @Summary
+ This function sets the write pointer for the slave driver.
+
+ @Description
+ This function sets the write pointer that the driver will
+ need to save data that will be received from the master
+ whenever the master requests a write.
+
+ @Preconditions
+ None
+
+ @Param
+ *p - The pointer to the read buffer, that will be used to transmit
+ data to the requesting i2c master.
+
+ @Returns
+ None
+
+ @Example
+ <code>
+ Refer to MSSP2_I2C_Initialize() for an example
+ </code>
+
+*/
+
+void MSSP2_I2C_WritePointerSet(uint8_t *p);
+
+/**
+ @Summary
+ This function returns the current read pointer used by the
+ slave driver.
+
+ @Description
+ This function returns the current read pointer used by the
+ slave driver. As the operation executes, the pointer is
+ incremented. User of the slave driver can use this function
+ to check on the current address that the pointer is pointing to.
+
+ @Preconditions
+ None
+
+ @Param
+ None
+
+ @Returns
+ The current pointer used to transmit data to the requesting
+ i2c master
+
+ @Example
+ <code>
+ uint8_t *pReadBuffer;
+
+ pReadBuffer = MSSP2_I2C_ReadPointerGet();
+
+ </code>
+
+*/
+
+uint8_t *MSSP2_I2C_ReadPointerGet(void);
+
+/**
+ @Summary
+ This function returns the current write pointer used by the
+ slave driver.
+
+ @Description
+ This function returns the current write pointer used by the
+ slave driver. As the operation executes, the pointer is
+ incremented. User of the slave driver can use this function
+ to check on the current address that the pointer is pointing to.
+
+ @Preconditions
+ None
+
+ @Param
+ None
+
+ @Returns
+ The current pointer used to save received data from the requesting
+ i2c master
+
+ @Example
+ <code>
+ uint8_t *pWriteBuffer;
+
+ pWriteBuffer = MSSP2_I2C_WritePointerGet();
+
+ </code>
+
+*/
+
+uint8_t *MSSP2_I2C_WritePointerGet(void);
+
+/**
+ @Summary
+ This application implemented function passes the
+ status of the i2c slave driver.
+
+ @Description
+ This application implemented function passes the
+ status of the i2c slave driver. The status passed
+ can be used by the application to manage the read and
+ write buffers. This function is called by the slave
+ driver everytime there is an event in the i2c bus that caused
+ an interrupt in the i2c slave module to be asserted.
+
+ The function will return boolean. The value of the return
+ will determine if the next received byte will be ack'ed or
+ nack'ed. By doing that, the application can have the
+ ability to delay incoming transactions. When a false is
+ returned, the next transactions will be nack'ed forcing the
+ master to restart the transactions.
+
+ Returning a false will give the application a chance to
+ prepare for the next transactions (for example: a read
+ requests from the master) or process the recently received
+ data.
+
+ @Preconditions
+ None
+
+ @Param
+ status - The latest status of the slave driver due
+ to an event in the i2c bus.
+
+ @Returns
+ True, if the application is ready for the next transaction.
+ False, if the application is not ready for the next transaction.
+
+ @Example
+ <code>
+
+
+ // Example implementation of the callback
+
+ static uint8_t mssp2_i2c_slaveWriteData = 0xAA;
+
+ bool MSSP2_I2C_StatusCallback(MSSP2_I2C_SLAVE_DRIVER_STATUS status)
+ {
+
+ // this emulates the slave device memory where data written to slave
+ // is placed and data read from slave is taken
+ static uint8_t EMULATE_EEPROM_Memory[64] =
+ {
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ };
+
+ static uint16_t address, addrByteCount;
+ static bool addressState = true;
+
+ switch (status)
+ {
+ case MSSP2_I2C_SLAVE_TRANSMIT_REQUEST_DETECTED:
+
+ // set up the slave driver buffer transmit pointer
+ MSSP2_I2C_ReadPointerSet(&EMULATE_EEPROM_Memory[address]);
+ address++;
+
+ break;
+
+ case MSSP2_I2C_SLAVE_RECEIVE_REQUEST_DETECTED:
+
+ addrByteCount = 0;
+ addressState = true;
+
+ // set up the slave driver buffer receive pointer
+ MSSP2_I2C_WritePointerSet(&mssp2_i2c_slaveWriteData);
+
+ break;
+
+ case MSSP2_I2C_SLAVE_RECEIVED_DATA_DETECTED:
+
+ if (addressState == true)
+ {
+ // get the address of the memory being written
+ if (addrByteCount == 0)
+ {
+ address = (mssp2_i2c_slaveWriteData << 8) & 0xFF00;
+ addrByteCount++;
+ }
+ else if (addrByteCount == 1)
+ {
+ address = address | mssp2_i2c_slaveWriteData;
+ addrByteCount = 0;
+ addressState = false;
+ }
+ }
+ else // if (addressState == false)
+ {
+ // set the memory with the received data
+ EMULATE_EEPROM_Memory[address] = mssp2_i2c_slaveWriteData;
+ }
+
+ break;
+
+ case MSSP2_I2C_SLAVE_10BIT_RECEIVE_REQUEST_DETECTED:
+
+ // do something here when 10-bit address is detected
+
+ // 10-bit address is detected
+
+ break;
+
+ default:
+ break;
+
+ }
+
+ return true;
+ }
+
+ </code>
+
+ */
+
+#pragma message "MSSP2_I2C_StatusCallback() is an Application implemented function. If this function is already implemented, you can turn off this message by deleting or commenting out this message."
+bool MSSP2_I2C_StatusCallback(MSSP2_I2C_SLAVE_DRIVER_STATUS status);
+
+#ifdef __cplusplus // Provide C++ Compatibility
+
+ }
+
+#endif
+
+#endif /* _MSSP2_I2C_H */ \ No newline at end of file
diff --git a/mcc_generated_files/pin_manager.c b/mcc_generated_files/pin_manager.c
new file mode 100644
index 0000000..8aa798a
--- /dev/null
+++ b/mcc_generated_files/pin_manager.c
@@ -0,0 +1,92 @@
+/**
+ PIN MANAGER Generated Driver File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ pin_manager.c
+
+ @Summary:
+ This is the generated manager file for the PIC24 / dsPIC33 / PIC32MM MCUs device. This manager
+ configures the pins direction, initial state, analog setting.
+
+ @Description:
+ This source file provides implementations for PIN MANAGER.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+
+/**
+ Section: Includes
+*/
+
+#include <xc.h>
+#include <stdio.h>
+#include "pin_manager.h"
+
+/**
+ Section: Driver Interface Function Definitions
+*/
+void PIN_MANAGER_Initialize (void)
+{
+ /****************************************************************************
+ * Setting the Output Latch SFR(s)
+ ***************************************************************************/
+ LATA = 0x0000;
+ LATB = 0x0000;
+
+ /****************************************************************************
+ * Setting the GPIO Direction SFR(s)
+ ***************************************************************************/
+ TRISA = 0x00A4;
+ TRISB = 0x543F;
+
+ /****************************************************************************
+ * Setting the Weak Pull Up and Weak Pull Down SFR(s)
+ ***************************************************************************/
+ CNPD1 = 0x0000;
+ CNPD2 = 0x0000;
+ CNPU1 = 0x0000;
+ CNPU2 = 0x0000;
+
+ /****************************************************************************
+ * Setting the Open Drain SFR(s)
+ ***************************************************************************/
+ ODCA = 0x0000;
+ ODCB = 0x01C0;
+
+ /****************************************************************************
+ * Setting the Analog/Digital Configuration SFR(s)
+ ***************************************************************************/
+ ANSA = 0x0000;
+ ANSB = 0x5030;
+}
+
diff --git a/mcc_generated_files/pin_manager.h b/mcc_generated_files/pin_manager.h
new file mode 100644
index 0000000..8f18362
--- /dev/null
+++ b/mcc_generated_files/pin_manager.h
@@ -0,0 +1,1113 @@
+/**
+ PIN MANAGER Generated Driver File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ pin_manager.h
+
+ @Summary:
+ This is the generated manager file for the PIC24 / dsPIC33 / PIC32MM MCUs device. This manager
+ configures the pins direction, initial state, analog setting.
+
+ @Description:
+ This source file provides implementations for PIN MANAGER.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#ifndef _PIN_MANAGER_H
+#define _PIN_MANAGER_H
+/**
+ Section: Includes
+*/
+#include <xc.h>
+
+/**
+ Section: Device Pin Macros
+*/
+/**
+ @Summary
+ Sets the GPIO pin, RA0, high using LATA0.
+
+ @Description
+ Sets the GPIO pin, RA0, high using LATA0.
+
+ @Preconditions
+ The RA0 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RA0 high (1)
+ IO_RA0_SetHigh();
+ </code>
+
+*/
+#define IO_RA0_SetHigh() (_LATA0 = 1)
+/**
+ @Summary
+ Sets the GPIO pin, RA0, low using LATA0.
+
+ @Description
+ Sets the GPIO pin, RA0, low using LATA0.
+
+ @Preconditions
+ The RA0 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RA0 low (0)
+ IO_RA0_SetLow();
+ </code>
+
+*/
+#define IO_RA0_SetLow() (_LATA0 = 0)
+/**
+ @Summary
+ Toggles the GPIO pin, RA0, using LATA0.
+
+ @Description
+ Toggles the GPIO pin, RA0, using LATA0.
+
+ @Preconditions
+ The RA0 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Toggle RA0
+ IO_RA0_Toggle();
+ </code>
+
+*/
+#define IO_RA0_Toggle() (_LATA0 ^= 1)
+/**
+ @Summary
+ Reads the value of the GPIO pin, RA0.
+
+ @Description
+ Reads the value of the GPIO pin, RA0.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ uint16_t portValue;
+
+ // Read RA0
+ postValue = IO_RA0_GetValue();
+ </code>
+
+*/
+#define IO_RA0_GetValue() _RA0
+/**
+ @Summary
+ Configures the GPIO pin, RA0, as an input.
+
+ @Description
+ Configures the GPIO pin, RA0, as an input.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RA0 as an input
+ IO_RA0_SetDigitalInput();
+ </code>
+
+*/
+#define IO_RA0_SetDigitalInput() (_TRISA0 = 1)
+/**
+ @Summary
+ Configures the GPIO pin, RA0, as an output.
+
+ @Description
+ Configures the GPIO pin, RA0, as an output.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RA0 as an output
+ IO_RA0_SetDigitalOutput();
+ </code>
+
+*/
+#define IO_RA0_SetDigitalOutput() (_TRISA0 = 0)
+/**
+ @Summary
+ Sets the GPIO pin, RA1, high using LATA1.
+
+ @Description
+ Sets the GPIO pin, RA1, high using LATA1.
+
+ @Preconditions
+ The RA1 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RA1 high (1)
+ IO_RA1_SetHigh();
+ </code>
+
+*/
+#define IO_RA1_SetHigh() (_LATA1 = 1)
+/**
+ @Summary
+ Sets the GPIO pin, RA1, low using LATA1.
+
+ @Description
+ Sets the GPIO pin, RA1, low using LATA1.
+
+ @Preconditions
+ The RA1 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RA1 low (0)
+ IO_RA1_SetLow();
+ </code>
+
+*/
+#define IO_RA1_SetLow() (_LATA1 = 0)
+/**
+ @Summary
+ Toggles the GPIO pin, RA1, using LATA1.
+
+ @Description
+ Toggles the GPIO pin, RA1, using LATA1.
+
+ @Preconditions
+ The RA1 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Toggle RA1
+ IO_RA1_Toggle();
+ </code>
+
+*/
+#define IO_RA1_Toggle() (_LATA1 ^= 1)
+/**
+ @Summary
+ Reads the value of the GPIO pin, RA1.
+
+ @Description
+ Reads the value of the GPIO pin, RA1.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ uint16_t portValue;
+
+ // Read RA1
+ postValue = IO_RA1_GetValue();
+ </code>
+
+*/
+#define IO_RA1_GetValue() _RA1
+/**
+ @Summary
+ Configures the GPIO pin, RA1, as an input.
+
+ @Description
+ Configures the GPIO pin, RA1, as an input.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RA1 as an input
+ IO_RA1_SetDigitalInput();
+ </code>
+
+*/
+#define IO_RA1_SetDigitalInput() (_TRISA1 = 1)
+/**
+ @Summary
+ Configures the GPIO pin, RA1, as an output.
+
+ @Description
+ Configures the GPIO pin, RA1, as an output.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RA1 as an output
+ IO_RA1_SetDigitalOutput();
+ </code>
+
+*/
+#define IO_RA1_SetDigitalOutput() (_TRISA1 = 0)
+/**
+ @Summary
+ Sets the GPIO pin, RA4, high using LATA4.
+
+ @Description
+ Sets the GPIO pin, RA4, high using LATA4.
+
+ @Preconditions
+ The RA4 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RA4 high (1)
+ IO_RA4_SetHigh();
+ </code>
+
+*/
+#define IO_RA4_SetHigh() (_LATA4 = 1)
+/**
+ @Summary
+ Sets the GPIO pin, RA4, low using LATA4.
+
+ @Description
+ Sets the GPIO pin, RA4, low using LATA4.
+
+ @Preconditions
+ The RA4 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RA4 low (0)
+ IO_RA4_SetLow();
+ </code>
+
+*/
+#define IO_RA4_SetLow() (_LATA4 = 0)
+/**
+ @Summary
+ Toggles the GPIO pin, RA4, using LATA4.
+
+ @Description
+ Toggles the GPIO pin, RA4, using LATA4.
+
+ @Preconditions
+ The RA4 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Toggle RA4
+ IO_RA4_Toggle();
+ </code>
+
+*/
+#define IO_RA4_Toggle() (_LATA4 ^= 1)
+/**
+ @Summary
+ Reads the value of the GPIO pin, RA4.
+
+ @Description
+ Reads the value of the GPIO pin, RA4.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ uint16_t portValue;
+
+ // Read RA4
+ postValue = IO_RA4_GetValue();
+ </code>
+
+*/
+#define IO_RA4_GetValue() _RA4
+/**
+ @Summary
+ Configures the GPIO pin, RA4, as an input.
+
+ @Description
+ Configures the GPIO pin, RA4, as an input.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RA4 as an input
+ IO_RA4_SetDigitalInput();
+ </code>
+
+*/
+#define IO_RA4_SetDigitalInput() (_TRISA4 = 1)
+/**
+ @Summary
+ Configures the GPIO pin, RA4, as an output.
+
+ @Description
+ Configures the GPIO pin, RA4, as an output.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RA4 as an output
+ IO_RA4_SetDigitalOutput();
+ </code>
+
+*/
+#define IO_RA4_SetDigitalOutput() (_TRISA4 = 0)
+/**
+ @Summary
+ Sets the GPIO pin, RB6, high using LATB6.
+
+ @Description
+ Sets the GPIO pin, RB6, high using LATB6.
+
+ @Preconditions
+ The RB6 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RB6 high (1)
+ IO_RB6_SetHigh();
+ </code>
+
+*/
+#define IO_RB6_SetHigh() (_LATB6 = 1)
+/**
+ @Summary
+ Sets the GPIO pin, RB6, low using LATB6.
+
+ @Description
+ Sets the GPIO pin, RB6, low using LATB6.
+
+ @Preconditions
+ The RB6 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RB6 low (0)
+ IO_RB6_SetLow();
+ </code>
+
+*/
+#define IO_RB6_SetLow() (_LATB6 = 0)
+/**
+ @Summary
+ Toggles the GPIO pin, RB6, using LATB6.
+
+ @Description
+ Toggles the GPIO pin, RB6, using LATB6.
+
+ @Preconditions
+ The RB6 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Toggle RB6
+ IO_RB6_Toggle();
+ </code>
+
+*/
+#define IO_RB6_Toggle() (_LATB6 ^= 1)
+/**
+ @Summary
+ Reads the value of the GPIO pin, RB6.
+
+ @Description
+ Reads the value of the GPIO pin, RB6.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ uint16_t portValue;
+
+ // Read RB6
+ postValue = IO_RB6_GetValue();
+ </code>
+
+*/
+#define IO_RB6_GetValue() _RB6
+/**
+ @Summary
+ Configures the GPIO pin, RB6, as an input.
+
+ @Description
+ Configures the GPIO pin, RB6, as an input.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RB6 as an input
+ IO_RB6_SetDigitalInput();
+ </code>
+
+*/
+#define IO_RB6_SetDigitalInput() (_TRISB6 = 1)
+/**
+ @Summary
+ Configures the GPIO pin, RB6, as an output.
+
+ @Description
+ Configures the GPIO pin, RB6, as an output.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RB6 as an output
+ IO_RB6_SetDigitalOutput();
+ </code>
+
+*/
+#define IO_RB6_SetDigitalOutput() (_TRISB6 = 0)
+/**
+ @Summary
+ Sets the GPIO pin, RB7, high using LATB7.
+
+ @Description
+ Sets the GPIO pin, RB7, high using LATB7.
+
+ @Preconditions
+ The RB7 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RB7 high (1)
+ IO_RB7_SetHigh();
+ </code>
+
+*/
+#define IO_RB7_SetHigh() (_LATB7 = 1)
+/**
+ @Summary
+ Sets the GPIO pin, RB7, low using LATB7.
+
+ @Description
+ Sets the GPIO pin, RB7, low using LATB7.
+
+ @Preconditions
+ The RB7 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RB7 low (0)
+ IO_RB7_SetLow();
+ </code>
+
+*/
+#define IO_RB7_SetLow() (_LATB7 = 0)
+/**
+ @Summary
+ Toggles the GPIO pin, RB7, using LATB7.
+
+ @Description
+ Toggles the GPIO pin, RB7, using LATB7.
+
+ @Preconditions
+ The RB7 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Toggle RB7
+ IO_RB7_Toggle();
+ </code>
+
+*/
+#define IO_RB7_Toggle() (_LATB7 ^= 1)
+/**
+ @Summary
+ Reads the value of the GPIO pin, RB7.
+
+ @Description
+ Reads the value of the GPIO pin, RB7.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ uint16_t portValue;
+
+ // Read RB7
+ postValue = IO_RB7_GetValue();
+ </code>
+
+*/
+#define IO_RB7_GetValue() _RB7
+/**
+ @Summary
+ Configures the GPIO pin, RB7, as an input.
+
+ @Description
+ Configures the GPIO pin, RB7, as an input.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RB7 as an input
+ IO_RB7_SetDigitalInput();
+ </code>
+
+*/
+#define IO_RB7_SetDigitalInput() (_TRISB7 = 1)
+/**
+ @Summary
+ Configures the GPIO pin, RB7, as an output.
+
+ @Description
+ Configures the GPIO pin, RB7, as an output.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RB7 as an output
+ IO_RB7_SetDigitalOutput();
+ </code>
+
+*/
+#define IO_RB7_SetDigitalOutput() (_TRISB7 = 0)
+/**
+ @Summary
+ Sets the GPIO pin, RB8, high using LATB8.
+
+ @Description
+ Sets the GPIO pin, RB8, high using LATB8.
+
+ @Preconditions
+ The RB8 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RB8 high (1)
+ IO_RB8_SetHigh();
+ </code>
+
+*/
+#define IO_RB8_SetHigh() (_LATB8 = 1)
+/**
+ @Summary
+ Sets the GPIO pin, RB8, low using LATB8.
+
+ @Description
+ Sets the GPIO pin, RB8, low using LATB8.
+
+ @Preconditions
+ The RB8 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RB8 low (0)
+ IO_RB8_SetLow();
+ </code>
+
+*/
+#define IO_RB8_SetLow() (_LATB8 = 0)
+/**
+ @Summary
+ Toggles the GPIO pin, RB8, using LATB8.
+
+ @Description
+ Toggles the GPIO pin, RB8, using LATB8.
+
+ @Preconditions
+ The RB8 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Toggle RB8
+ IO_RB8_Toggle();
+ </code>
+
+*/
+#define IO_RB8_Toggle() (_LATB8 ^= 1)
+/**
+ @Summary
+ Reads the value of the GPIO pin, RB8.
+
+ @Description
+ Reads the value of the GPIO pin, RB8.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ uint16_t portValue;
+
+ // Read RB8
+ postValue = IO_RB8_GetValue();
+ </code>
+
+*/
+#define IO_RB8_GetValue() _RB8
+/**
+ @Summary
+ Configures the GPIO pin, RB8, as an input.
+
+ @Description
+ Configures the GPIO pin, RB8, as an input.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RB8 as an input
+ IO_RB8_SetDigitalInput();
+ </code>
+
+*/
+#define IO_RB8_SetDigitalInput() (_TRISB8 = 1)
+/**
+ @Summary
+ Configures the GPIO pin, RB8, as an output.
+
+ @Description
+ Configures the GPIO pin, RB8, as an output.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RB8 as an output
+ IO_RB8_SetDigitalOutput();
+ </code>
+
+*/
+#define IO_RB8_SetDigitalOutput() (_TRISB8 = 0)
+/**
+ @Summary
+ Sets the GPIO pin, RB9, high using LATB9.
+
+ @Description
+ Sets the GPIO pin, RB9, high using LATB9.
+
+ @Preconditions
+ The RB9 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RB9 high (1)
+ IO_RB9_SetHigh();
+ </code>
+
+*/
+#define IO_RB9_SetHigh() (_LATB9 = 1)
+/**
+ @Summary
+ Sets the GPIO pin, RB9, low using LATB9.
+
+ @Description
+ Sets the GPIO pin, RB9, low using LATB9.
+
+ @Preconditions
+ The RB9 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Set RB9 low (0)
+ IO_RB9_SetLow();
+ </code>
+
+*/
+#define IO_RB9_SetLow() (_LATB9 = 0)
+/**
+ @Summary
+ Toggles the GPIO pin, RB9, using LATB9.
+
+ @Description
+ Toggles the GPIO pin, RB9, using LATB9.
+
+ @Preconditions
+ The RB9 must be set to an output.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Toggle RB9
+ IO_RB9_Toggle();
+ </code>
+
+*/
+#define IO_RB9_Toggle() (_LATB9 ^= 1)
+/**
+ @Summary
+ Reads the value of the GPIO pin, RB9.
+
+ @Description
+ Reads the value of the GPIO pin, RB9.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ uint16_t portValue;
+
+ // Read RB9
+ postValue = IO_RB9_GetValue();
+ </code>
+
+*/
+#define IO_RB9_GetValue() _RB9
+/**
+ @Summary
+ Configures the GPIO pin, RB9, as an input.
+
+ @Description
+ Configures the GPIO pin, RB9, as an input.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RB9 as an input
+ IO_RB9_SetDigitalInput();
+ </code>
+
+*/
+#define IO_RB9_SetDigitalInput() (_TRISB9 = 1)
+/**
+ @Summary
+ Configures the GPIO pin, RB9, as an output.
+
+ @Description
+ Configures the GPIO pin, RB9, as an output.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ // Sets the RB9 as an output
+ IO_RB9_SetDigitalOutput();
+ </code>
+
+*/
+#define IO_RB9_SetDigitalOutput() (_TRISB9 = 0)
+
+/**
+ Section: Function Prototypes
+*/
+/**
+ @Summary
+ Configures the pin settings of the PIC24FV16KM202
+
+ @Description
+ This is the generated manager file for the PIC24 / dsPIC33 / PIC32MM MCUs device. This manager
+ configures the pins direction, initial state, analog setting.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ <code>
+ void SYSTEM_Initialize(void)
+ {
+ // Other initializers are called from this function
+ PIN_MANAGER_Initialize();
+ }
+ </code>
+
+*/
+void PIN_MANAGER_Initialize (void);
+
+
+
+#endif
diff --git a/mcc_generated_files/system.c b/mcc_generated_files/system.c
new file mode 100644
index 0000000..a128daf
--- /dev/null
+++ b/mcc_generated_files/system.c
@@ -0,0 +1,106 @@
+/**
+ @Generated PIC24 / dsPIC33 / PIC32MM MCUs Source File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ system.h
+
+ @Summary:
+ This is the sysetm.h file generated using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description:
+ This header file provides implementations for driver APIs for all modules selected in the GUI.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+// Configuration bits: selected in the GUI
+
+// FBS
+#pragma config BWRP = OFF //Boot Segment Write Protect->Disabled
+#pragma config BSS = OFF //Boot segment Protect->No boot program flash segment
+
+// FGS
+#pragma config GWRP = OFF //General Segment Write Protect->General segment may be written
+#pragma config GCP = OFF //General Segment Code Protect->No Protection
+
+// FOSCSEL
+#pragma config FNOSC = PRI //Oscillator Select->Primary Oscillator (XT, HS, EC)
+#pragma config SOSCSRC = DIG //SOSC Source Type->Digital Mode for use with external source
+#pragma config LPRCSEL = HP //LPRC Oscillator Power and Accuracy->High Power, High Accuracy Mode
+#pragma config IESO = OFF //Internal External Switch Over bit->Internal External Switchover mode disabled (Two-speed Start-up disabled)
+
+// FOSC
+#pragma config POSCMOD = HS //Primary Oscillator Configuration bits->HS oscillator mode selected
+#pragma config OSCIOFNC = IO //CLKO Enable Configuration bit->Port I/O enabled (CLKO disabled)
+#pragma config POSCFREQ = HS //Primary Oscillator Frequency Range Configuration bits->Primary oscillator/external clock input frequency greater than 8MHz
+#pragma config SOSCSEL = SOSCHP //SOSC Power Selection Configuration bits->Secondary Oscillator configured for high-power operation
+#pragma config FCKSM = CSDCMD //Clock Switching and Monitor Selection->Both Clock Switching and Fail-safe Clock Monitor are disabled
+
+// FWDT
+#pragma config WDTPS = PS32768 //Watchdog Timer Postscale Select bits->1:32768
+#pragma config FWPSA = PR128 //WDT Prescaler bit->WDT prescaler ratio of 1:128
+#pragma config FWDTEN = OFF //Watchdog Timer Enable bits->WDT disabled in hardware; SWDTEN bit disabled
+#pragma config WINDIS = OFF //Windowed Watchdog Timer Disable bit->Standard WDT selected(windowed WDT disabled)
+
+// FPOR
+#pragma config BOREN = BOR3 //Brown-out Reset Enable bits->Brown-out Reset enabled in hardware, SBOREN bit disabled
+#pragma config RETCFG = OFF //->Retention regulator is not available
+#pragma config PWRTEN = ON //Power-up Timer Enable bit->PWRT enabled
+#pragma config I2C1SEL = PRI //Alternate I2C1 Pin Mapping bit->Use Default SCL1/SDA1 Pins For I2C1
+#pragma config BORV = V18 //Brown-out Reset Voltage bits->Brown-out Reset set to lowest voltage (1.8V)
+#pragma config MCLRE = ON //MCLR Pin Enable bit->RA5 input pin disabled, MCLR pin enabled
+
+// FICD
+#pragma config ICS = PGx1 //ICD Pin Placement Select bits->EMUC/EMUD share PGC1/PGD1
+
+#include "pin_manager.h"
+#include "clock.h"
+#include "system.h"
+#include "tmr1.h"
+#include "interrupt_manager.h"
+#include "traps.h"
+#include "mssp1_spi.h"
+#include "mssp2_i2c.h"
+
+void SYSTEM_Initialize(void)
+{
+ PIN_MANAGER_Initialize();
+ CLOCK_Initialize();
+ INTERRUPT_Initialize();
+ MSSP2_I2C_Initialize();
+ MSSP1_SPI_Initialize();
+ TMR1_Initialize();
+}
+
+/**
+ End of File
+*/ \ No newline at end of file
diff --git a/mcc_generated_files/system.h b/mcc_generated_files/system.h
new file mode 100644
index 0000000..1125509
--- /dev/null
+++ b/mcc_generated_files/system.h
@@ -0,0 +1,70 @@
+/**
+ @Generated PIC24 / dsPIC33 / PIC32MM MCUs Source File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ system.h
+
+ @Summary:
+ This is the system.h file generated using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description:
+ This header file provides implementations for driver APIs for all modules selected in the GUI.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#ifndef _XTAL_FREQ
+#define _XTAL_FREQ 20000000UL
+#endif
+
+#include "xc.h"
+#include "stdint.h"
+
+#ifndef SYSTEM_H
+#define SYSTEM_H
+
+/**
+ * @Param
+ none
+ * @Returns
+ none
+ * @Description
+ Initializes the device to the default states configured in the
+ * MCC GUI
+ * @Example
+ SYSTEM_Initialize(void);
+ */
+void SYSTEM_Initialize(void);
+#endif /* SYSTEM_H */
+/**
+ End of File
+*/ \ No newline at end of file
diff --git a/mcc_generated_files/tmr1.c b/mcc_generated_files/tmr1.c
new file mode 100644
index 0000000..25bc139
--- /dev/null
+++ b/mcc_generated_files/tmr1.c
@@ -0,0 +1,219 @@
+
+/**
+ TMR1 Generated Driver API Source File
+
+ @Company
+ Microchip Technology Inc.
+
+ @File Name
+ tmr1.c
+
+ @Summary
+ This is the generated source file for the TMR1 driver using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description
+ This source file provides APIs for driver for TMR1.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+/**
+ Section: Included Files
+*/
+
+#include <stdio.h>
+#include "tmr1.h"
+
+/**
+ Section: File specific functions
+*/
+void (*TMR1_InterruptHandler)(void) = NULL;
+void TMR1_CallBack(void);
+
+/**
+ Section: Data Type Definitions
+*/
+
+/** TMR Driver Hardware Instance Object
+
+ @Summary
+ Defines the object required for the maintenance of the hardware instance.
+
+ @Description
+ This defines the object required for the maintenance of the hardware
+ instance. This object exists once per hardware instance of the peripheral.
+
+ Remarks:
+ None.
+*/
+
+typedef struct _TMR_OBJ_STRUCT
+{
+ /* Timer Elapsed */
+ volatile bool timerElapsed;
+ /*Software Counter value*/
+ volatile uint8_t count;
+
+} TMR_OBJ;
+
+static TMR_OBJ tmr1_obj;
+
+/**
+ Section: Driver Interface
+*/
+
+void TMR1_Initialize (void)
+{
+ //TMR1 0;
+ TMR1 = 0x00;
+ //Period = 1.5000128 s; Frequency = 10000000 Hz; PR1 39062;
+ PR1 = 0xE4E1;
+ //TCKPS 1:256; TON enabled; TSIDL disabled; TCS FOSC/2; TECS SOSC; TSYNC disabled; TGATE disabled;
+ T1CON = 0x8030;
+
+ if(TMR1_InterruptHandler == NULL)
+ {
+ TMR1_SetInterruptHandler(&TMR1_CallBack);
+ }
+
+ IFS0bits.T1IF = false;
+ IEC0bits.T1IE = true;
+
+ tmr1_obj.timerElapsed = false;
+
+}
+
+
+void __attribute__ ( ( interrupt, no_auto_psv ) ) _T1Interrupt ( )
+{
+ /* Check if the Timer Interrupt/Status is set */
+
+ //***User Area Begin
+
+ // ticker function call;
+ // ticker is 1 -> Callback function gets called everytime this ISR executes
+ if(TMR1_InterruptHandler)
+ {
+ TMR1_InterruptHandler();
+ }
+
+ //***User Area End
+
+ tmr1_obj.count++;
+ tmr1_obj.timerElapsed = true;
+ IFS0bits.T1IF = false;
+}
+
+void TMR1_Period16BitSet( uint16_t value )
+{
+ /* Update the counter values */
+ PR1 = value;
+ /* Reset the status information */
+ tmr1_obj.timerElapsed = false;
+}
+
+uint16_t TMR1_Period16BitGet( void )
+{
+ return( PR1 );
+}
+
+void TMR1_Counter16BitSet ( uint16_t value )
+{
+ /* Update the counter values */
+ TMR1 = value;
+ /* Reset the status information */
+ tmr1_obj.timerElapsed = false;
+}
+
+uint16_t TMR1_Counter16BitGet( void )
+{
+ return( TMR1 );
+}
+
+
+void __attribute__ ((weak)) TMR1_CallBack(void)
+{
+ _LATB8 = 0;
+ _LATB7 = 1;
+}
+
+void TMR1_SetInterruptHandler(void (* InterruptHandler)(void))
+{
+ IEC0bits.T1IE = false;
+ TMR1_InterruptHandler = InterruptHandler;
+ IEC0bits.T1IE = true;
+}
+
+void TMR1_Start( void )
+{
+ /* Reset the status information */
+ tmr1_obj.timerElapsed = false;
+
+ /*Enable the interrupt*/
+ IEC0bits.T1IE = true;
+
+ /* Start the Timer */
+ T1CONbits.TON = 1;
+}
+
+void TMR1_Stop( void )
+{
+ /* Stop the Timer */
+ T1CONbits.TON = false;
+
+ /*Disable the interrupt*/
+ IEC0bits.T1IE = false;
+}
+
+bool TMR1_GetElapsedThenClear(void)
+{
+ bool status;
+
+ status = tmr1_obj.timerElapsed;
+
+ if(status == true)
+ {
+ tmr1_obj.timerElapsed = false;
+ }
+ return status;
+}
+
+int TMR1_SoftwareCounterGet(void)
+{
+ return tmr1_obj.count;
+}
+
+void TMR1_SoftwareCounterClear(void)
+{
+ tmr1_obj.count = 0;
+}
+
+/**
+ End of File
+*/
diff --git a/mcc_generated_files/tmr1.h b/mcc_generated_files/tmr1.h
new file mode 100644
index 0000000..cf60e9b
--- /dev/null
+++ b/mcc_generated_files/tmr1.h
@@ -0,0 +1,331 @@
+/**
+ TMR1 Generated Driver API Header File
+
+ @Company
+ Microchip Technology Inc.
+
+ @File Name
+ tmr1.h
+
+ @Summary
+ This is the generated header file for the TMR1 driver using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description
+ This header file provides APIs for driver for TMR1.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#ifndef _TMR1_H
+#define _TMR1_H
+
+/**
+ Section: Included Files
+*/
+
+#include <xc.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus // Provide C++ Compatibility
+
+ extern "C" {
+
+#endif
+
+#define TMR1_INTERRUPT_TICKER_FACTOR 1
+
+/**
+ Section: Interface Routines
+*/
+
+/**
+ @Summary
+ Initializes hardware and data for the given instance of the TMR module
+
+ @Description
+ This routine initializes hardware for the instance of the TMR module,
+ using the hardware initialization given data. It also initializes all
+ necessary internal data.
+
+ @Param
+ None.
+
+ @Returns
+ None
+
+ @Example
+ <code>
+ bool statusTimer1;
+ uint16_t period;
+ uint16_t value;
+
+ period = 0x20;
+
+ TMR1_Initialize();
+
+ TMR1_Period16BitSet(period);
+
+ if((value = TMR1_Period16BitGet())== period)
+ {
+ TMR1_Start();
+ }
+
+ while(1)
+ {
+ TMR1_Tasks();
+ if( (statusTimer1 = TMR1_GetElapsedThenClear()) == true)
+ {
+ TMR1_Stop();
+ }
+ }
+ </code>
+*/
+void TMR1_Initialize (void);
+
+
+/**
+ @Summary
+ Updates 16-bit timer value
+
+ @Description
+ This routine updates 16-bit timer value
+
+ @Param
+ None.
+
+ @Returns
+ None
+
+ @Example
+ Refer to the example of TMR1_Initialize();
+*/
+
+void TMR1_Period16BitSet( uint16_t value );
+
+/**
+
+ @Summary
+ Provides the timer 16-bit period value
+
+ @Description
+ This routine provides the timer 16-bit period value
+
+ @Param
+ None.
+
+ @Returns
+ Timer 16-bit period value
+
+ @Example
+ Refer to the example of TMR1_Initialize();
+*/
+
+uint16_t TMR1_Period16BitGet( void );
+
+/**
+ @Summary
+ Updates the timer's 16-bit value
+
+ @Description
+ This routine updates the timer's 16-bit value
+
+ @Param
+ None.
+
+ @Returns
+ None
+
+ @Example
+ <code>
+ uint16_t value=0xF0F0;
+
+ TMR1_Counter16BitSet(value));
+
+ while(1)
+ {
+ TMR1_Tasks();
+ if( (value == TMR1_Counter16BitGet()))
+ {
+ TMR1_Stop();
+ }
+ }
+ </code>
+*/
+
+void TMR1_Counter16BitSet ( uint16_t value );
+
+/**
+ @Summary
+ Provides 16-bit current counter value
+
+ @Description
+ This routine provides 16-bit current counter value
+
+ @Param
+ None.
+
+ @Returns
+ 16-bit current counter value
+
+ @Example
+ Refer to the example of TMR1_Counter16BitSet();
+*/
+
+uint16_t TMR1_Counter16BitGet( void );
+
+/**
+ @Summary
+ Assigns a function pointer with a callback address.
+
+ @Description
+ This routine assigns a function pointer with a callback address.
+
+ @Param
+ Address of the callback routine.
+
+ @Returns
+ None
+
+ @Example
+ <code>
+ TMR1_SetInterruptHandler(&TMR1_CallBack);
+ </code>
+*/
+
+void TMR1_SetInterruptHandler(void (* InterruptHandler)(void));
+
+/**
+ @Summary
+ Starts the TMR
+
+ @Description
+ This routine starts the TMR
+
+ @Param
+ None.
+
+ @Returns
+ None
+
+ @Example
+ Refer to the example of TMR1_Initialize();
+*/
+
+void TMR1_Start( void );
+
+/**
+ @Summary
+ Stops the TMR
+
+ @Description
+ This routine stops the TMR
+
+ @Param
+ None.
+
+ @Returns
+ None
+
+ @Example
+ Refer to the example of TMR1_Initialize();
+*/
+
+void TMR1_Stop( void );
+
+/**
+ @Summary
+ Returns the elapsed status of the timer and clears if flag is set.
+
+ @Description
+ This routine returns the elapsed status of the timer and clears
+ flag if its set.
+
+ @Param
+ None.
+
+ @Returns
+ True - Timer has elapsed.
+ False - Timer has not elapsed.
+
+ @Example
+ Refer to the example of TMR1_Initialize();
+*/
+
+bool TMR1_GetElapsedThenClear(void);
+
+/**
+ @Summary
+ Returns the software counter value.
+
+ @Description
+ This routine returns the software counter value.
+
+ @Param
+ None.
+
+ @Returns
+ Software counter value.
+
+ @Example
+ Refer to the example of TMR1_Initialize();
+*/
+
+int TMR1_SoftwareCounterGet(void);
+
+/**
+ @Summary
+ Clears the software counter value.
+
+ @Description
+ This routine clears the software counter value.
+
+ @Param
+ None.
+
+ @Returns
+ None
+
+ @Example
+ Refer to the example of TMR1_Initialize();
+*/
+
+void TMR1_SoftwareCounterClear(void);
+
+#ifdef __cplusplus // Provide C++ Compatibility
+
+ }
+
+#endif
+
+#endif //_TMR1_H
+
+/**
+ End of File
+*/
diff --git a/mcc_generated_files/traps.c b/mcc_generated_files/traps.c
new file mode 100644
index 0000000..65b5ccf
--- /dev/null
+++ b/mcc_generated_files/traps.c
@@ -0,0 +1,122 @@
+/**
+ System Traps Generated Driver File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ traps.h
+
+ @Summary:
+ This is the generated driver implementation file for handling traps
+ using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description:
+ This source file provides implementations for PIC24 / dsPIC33 / PIC32MM MCUs traps.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+/**
+ Section: Includes
+*/
+#include <xc.h>
+#include "traps.h"
+
+#define ERROR_HANDLER __attribute__((interrupt,no_auto_psv))
+#define FAILSAFE_STACK_GUARDSIZE 8
+
+/**
+ * a private place to store the error code if we run into a severe error
+ */
+static uint16_t TRAPS_error_code = -1;
+
+/**
+ * Halts
+ *
+ * @param code error code
+ */
+void __attribute__((weak)) TRAPS_halt_on_error(uint16_t code)
+{
+ TRAPS_error_code = code;
+#ifdef __DEBUG
+ __builtin_software_breakpoint();
+ /* If we are in debug mode, cause a software breakpoint in the debugger */
+#endif
+ while(1);
+
+}
+
+/**
+ * Sets the stack pointer to a backup area of memory, in case we run into
+ * a stack error (in which case we can't really trust the stack pointer)
+ */
+inline static void use_failsafe_stack(void)
+{
+ static uint8_t failsafe_stack[32];
+ asm volatile (
+ " mov %[pstack], W15\n"
+ :
+ : [pstack]"r"(failsafe_stack)
+ );
+/* Controls where the stack pointer limit is, relative to the end of the
+ * failsafe stack
+ */
+ SPLIM = (uint16_t)(((uint8_t *)failsafe_stack) + sizeof(failsafe_stack)
+ - FAILSAFE_STACK_GUARDSIZE);
+}
+
+/** Oscillator Fail Trap vector**/
+void ERROR_HANDLER _OscillatorFail(void)
+{
+ INTCON1bits.OSCFAIL = 0; //Clear the trap flag
+ TRAPS_halt_on_error(TRAPS_OSC_FAIL);
+}
+/** Stack Error Trap Vector**/
+void ERROR_HANDLER _StackError(void)
+{
+ /* We use a failsafe stack: the presence of a stack-pointer error
+ * means that we cannot trust the stack to operate correctly unless
+ * we set the stack pointer to a safe place.
+ */
+ use_failsafe_stack();
+ INTCON1bits.STKERR = 0; //Clear the trap flag
+ TRAPS_halt_on_error(TRAPS_STACK_ERR);
+}
+/** Address Error Trap Vector**/
+void ERROR_HANDLER _AddressError(void)
+{
+ INTCON1bits.ADDRERR = 0; //Clear the trap flag
+ TRAPS_halt_on_error(TRAPS_ADDRESS_ERR);
+}
+/** Math Error Trap Vector**/
+void ERROR_HANDLER _MathError(void)
+{
+ INTCON1bits.MATHERR = 0; //Clear the trap flag
+ TRAPS_halt_on_error(TRAPS_MATH_ERR);
+}
diff --git a/mcc_generated_files/traps.h b/mcc_generated_files/traps.h
new file mode 100644
index 0000000..80443bc
--- /dev/null
+++ b/mcc_generated_files/traps.h
@@ -0,0 +1,86 @@
+/**
+ System Traps Generated Driver File
+
+ @Company:
+ Microchip Technology Inc.
+
+ @File Name:
+ traps.h
+
+ @Summary:
+ This is the generated driver implementation file for handling traps
+ using PIC24 / dsPIC33 / PIC32MM MCUs
+
+ @Description:
+ This source file provides implementations for PIC24 / dsPIC33 / PIC32MM MCUs traps.
+ Generation Information :
+ Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.171.4
+ Device : PIC24FV16KM202
+ The generated drivers are tested against the following:
+ Compiler : XC16 v2.10
+ MPLAB : MPLAB X v6.05
+*/
+/*
+ (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
+ software and any derivatives exclusively with Microchip products.
+
+ THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
+ EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
+ PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
+ WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
+
+ IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
+ INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
+ WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
+ BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
+ FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
+ ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+
+ MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
+ TERMS.
+*/
+
+#ifndef _TRAPS_H
+#define _TRAPS_H
+
+#include <stdint.h>
+
+/**
+ * Error codes
+ */
+typedef enum
+{
+ /* ----- Traps ----- */
+ TRAPS_OSC_FAIL = 0, /** Oscillator Fail Trap vector */
+ TRAPS_STACK_ERR = 1, /** Stack Error Trap Vector */
+ TRAPS_ADDRESS_ERR = 2, /** Address Error Trap Vector */
+ TRAPS_MATH_ERR = 3, /** Math Error Trap Vector */
+} TRAPS_ERROR_CODE;
+
+/**
+ @Summary
+ Default handler for the traps
+
+ @Description
+ This routine will be called whenever a trap happens. It stores the trap
+ error code and waits forever.
+ This routine has a weak attribute and can be over written.
+
+ @Preconditions
+ None.
+
+ @Returns
+ None.
+
+ @Param
+ None.
+
+ @Example
+ None.
+
+*/
+void TRAPS_halt_on_error(uint16_t code);
+
+#endif \ No newline at end of file