From c73442dc0b44de62e9a2df4007f8772e4bbbcab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 3 Mar 2023 15:00:03 +0100 Subject: [PATCH 1/7] first config of the EUSART and TMR --- solar_panel.X/main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/solar_panel.X/main.c b/solar_panel.X/main.c index e43bd5c..432a126 100644 --- a/solar_panel.X/main.c +++ b/solar_panel.X/main.c @@ -49,6 +49,9 @@ /* Main application */ +void resetTMR0(); +void endFrame(); + void main(void) { // Initialize the device @@ -65,17 +68,19 @@ void main(void) // Use the following macros to: // Enable the Global Interrupts - //INTERRUPT_GlobalInterruptEnable(); + INTERRUPT_GlobalInterruptEnable(); // Disable the Global Interrupts //INTERRUPT_GlobalInterruptDisable(); // Enable the Peripheral Interrupts - //INTERRUPT_PeripheralInterruptEnable(); + INTERRUPT_PeripheralInterruptEnable(); // Disable the Peripheral Interrupts //INTERRUPT_PeripheralInterruptDisable(); uint16_t foo = 512; + EUSART1_SetRxInterruptHandler(resetTMR0()); + TMR0_SetInterruptHandler(endFrame()); while (1) { foo = ++foo%1023; @@ -94,6 +99,17 @@ void main(void) } } + + +void resetTMR0(){ + TMR0_Reload(); + TMR0_StartTimer(); + INTCONbits.TMR0IF = 0; +} + +void endFrame(){ + // TODO +} /** End of File */ \ No newline at end of file From a977d9300d136320b5b757d97a6f83a859496eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 3 Mar 2023 15:03:23 +0100 Subject: [PATCH 2/7] fix error of handlers --- solar_panel.X/main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/solar_panel.X/main.c b/solar_panel.X/main.c index 432a126..a03868e 100644 --- a/solar_panel.X/main.c +++ b/solar_panel.X/main.c @@ -49,8 +49,8 @@ /* Main application */ -void resetTMR0(); -void endFrame(); +void resetTMR0(void); +void endFrame(void); void main(void) { @@ -79,8 +79,8 @@ void main(void) // Disable the Peripheral Interrupts //INTERRUPT_PeripheralInterruptDisable(); uint16_t foo = 512; - EUSART1_SetRxInterruptHandler(resetTMR0()); - TMR0_SetInterruptHandler(endFrame()); + EUSART1_SetRxInterruptHandler(resetTMR0); + TMR0_SetInterruptHandler(endFrame); while (1) { foo = ++foo%1023; @@ -101,13 +101,13 @@ void main(void) } -void resetTMR0(){ +void resetTMR0(void){ + INTCONbits.TMR0IF = 0; TMR0_Reload(); TMR0_StartTimer(); - INTCONbits.TMR0IF = 0; } -void endFrame(){ +void endFrame(void){ // TODO } /** From 95af13e62703d983e385a3e8a63b6c861ca7b9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 3 Mar 2023 15:03:48 +0100 Subject: [PATCH 3/7] i don't understand why it's not commit in MPLAB --- solar_panel.X/mcc_generated_files/eusart1.c | 239 +++++++ solar_panel.X/mcc_generated_files/eusart1.h | 477 ++++++++++++++ .../mcc_generated_files/interrupt_manager.c | 83 +++ .../mcc_generated_files/interrupt_manager.h | 115 ++++ solar_panel.X/mcc_generated_files/mcc.c | 5 +- solar_panel.X/mcc_generated_files/mcc.h | 3 + solar_panel.X/mcc_generated_files/tmr0.c | 167 +++++ solar_panel.X/mcc_generated_files/tmr0.h | 356 +++++++++++ solar_panel.X/nbproject/Makefile-default.mk | 58 +- .../nbproject/Makefile-genesis.properties | 4 +- solar_panel.X/nbproject/configurations.xml | 6 + solar_panel.X/solar_panel.mc3 | 596 +++++++++++++++++- 12 files changed, 2099 insertions(+), 10 deletions(-) create mode 100644 solar_panel.X/mcc_generated_files/eusart1.c create mode 100644 solar_panel.X/mcc_generated_files/eusart1.h create mode 100644 solar_panel.X/mcc_generated_files/interrupt_manager.c create mode 100644 solar_panel.X/mcc_generated_files/interrupt_manager.h create mode 100644 solar_panel.X/mcc_generated_files/tmr0.c create mode 100644 solar_panel.X/mcc_generated_files/tmr0.h diff --git a/solar_panel.X/mcc_generated_files/eusart1.c b/solar_panel.X/mcc_generated_files/eusart1.c new file mode 100644 index 0000000..01e4133 --- /dev/null +++ b/solar_panel.X/mcc_generated_files/eusart1.c @@ -0,0 +1,239 @@ +/** + EUSART1 Generated Driver File + + @Company + Microchip Technology Inc. + + @File Name + eusart1.c + + @Summary + This is the generated driver implementation file for the EUSART1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description + This source file provides APIs for EUSART1. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F97J60 + Driver Version : 2.1.1 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +/** + Section: Included Files +*/ +#include "eusart1.h" + +/** + Section: Macro Declarations +*/ + +#define EUSART1_TX_BUFFER_SIZE 8 +#define EUSART1_RX_BUFFER_SIZE 8 + +/** + Section: Global Variables +*/ + +volatile uint8_t eusart1RxHead = 0; +volatile uint8_t eusart1RxTail = 0; +volatile uint8_t eusart1RxBuffer[EUSART1_RX_BUFFER_SIZE]; +volatile eusart1_status_t eusart1RxStatusBuffer[EUSART1_RX_BUFFER_SIZE]; +volatile uint8_t eusart1RxCount; +volatile eusart1_status_t eusart1RxLastError; + +/** + Section: EUSART1 APIs +*/ +void (*EUSART1_FramingErrorHandler)(void); +void (*EUSART1_OverrunErrorHandler)(void); +void (*EUSART1_ErrorHandler)(void); + +void EUSART1_DefaultFramingErrorHandler(void); +void EUSART1_DefaultOverrunErrorHandler(void); +void EUSART1_DefaultErrorHandler(void); + +void EUSART1_Initialize(void) +{ + // disable interrupts before changing states + PIE1bits.RC1IE = 0; + EUSART1_SetRxInterruptHandler(EUSART1_Receive_ISR); + // Set the EUSART1 module to the options selected in the user interface. + + // ABDOVF no_overflow; SCKP async_noninverted_sync_fallingedge; BRG16 16bit_generator; WUE disabled; ABDEN disabled; RXDTP not_inverted; + BAUDCON1 = 0x08; + + // SPEN enabled; RX9 9-bit; CREN enabled; ADDEN disabled; SREN disabled; + RCSTA1 = 0xD0; + + // TX9 9-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC synchronous; BRGH hi_speed; CSRC master_mode; + TXSTA1 = 0xF4; + + // + SPBRG1 = 0x8A; + + // + SPBRGH1 = 0x02; + + + EUSART1_SetFramingErrorHandler(EUSART1_DefaultFramingErrorHandler); + EUSART1_SetOverrunErrorHandler(EUSART1_DefaultOverrunErrorHandler); + EUSART1_SetErrorHandler(EUSART1_DefaultErrorHandler); + + eusart1RxLastError.status = 0; + + + eusart1RxHead = 0; + eusart1RxTail = 0; + eusart1RxCount = 0; + + // enable receive interrupt + PIE1bits.RC1IE = 1; +} + +bool EUSART1_is_tx_ready(void) +{ + return (bool)(PIR1bits.TX1IF && TXSTA1bits.TXEN); +} + +bool EUSART1_is_rx_ready(void) +{ + return (eusart1RxCount ? true : false); +} + +bool EUSART1_is_tx_done(void) +{ + return TXSTA1bits.TRMT; +} + +eusart1_status_t EUSART1_get_last_status(void){ + return eusart1RxLastError; +} + +uint8_t EUSART1_Read(void) +{ + uint8_t readValue = 0; + RCSTA1bits.SREN = 1; + + while(0 == eusart1RxCount) + { + } + + eusart1RxLastError = eusart1RxStatusBuffer[eusart1RxTail]; + + readValue = eusart1RxBuffer[eusart1RxTail++]; + if(sizeof(eusart1RxBuffer) <= eusart1RxTail) + { + eusart1RxTail = 0; + } + PIE1bits.RC1IE = 0; + eusart1RxCount--; + PIE1bits.RC1IE = 1; + + return readValue; +} + +void EUSART1_Write(uint8_t txData) +{ + RCSTA1bits.SREN = 0; + RCSTA1bits.CREN = 0; + while(0 == PIR1bits.TX1IF) + { + } + + TXREG1 = txData; // Write the data byte to the USART. +} + +void EUSART1_Receive_ISR(void) +{ + + eusart1RxStatusBuffer[eusart1RxHead].status = 0; + + if(RCSTA1bits.FERR){ + eusart1RxStatusBuffer[eusart1RxHead].ferr = 1; + EUSART1_FramingErrorHandler(); + } + + if(RCSTA1bits.OERR){ + eusart1RxStatusBuffer[eusart1RxHead].oerr = 1; + EUSART1_OverrunErrorHandler(); + } + + if(eusart1RxStatusBuffer[eusart1RxHead].status){ + EUSART1_ErrorHandler(); + } else { + EUSART1_RxDataHandler(); + } + + // or set custom function using eusart1_SetRxInterruptHandler() +} + +void EUSART1_RxDataHandler(void){ + // use this default receive interrupt handler code + eusart1RxBuffer[eusart1RxHead++] = RCREG1; + if(sizeof(eusart1RxBuffer) <= eusart1RxHead) + { + eusart1RxHead = 0; + } + eusart1RxCount++; + +} + +void EUSART1_DefaultFramingErrorHandler(void){} + +void EUSART1_DefaultOverrunErrorHandler(void){ + // EUSART1 error - restart + + RCSTA1bits.CREN = 0; + RCSTA1bits.CREN = 1; + +} + +void EUSART1_DefaultErrorHandler(void){ + EUSART1_RxDataHandler(); +} + +void EUSART1_SetFramingErrorHandler(void (* interruptHandler)(void)){ + EUSART1_FramingErrorHandler = interruptHandler; +} + +void EUSART1_SetOverrunErrorHandler(void (* interruptHandler)(void)){ + EUSART1_OverrunErrorHandler = interruptHandler; +} + +void EUSART1_SetErrorHandler(void (* interruptHandler)(void)){ + EUSART1_ErrorHandler = interruptHandler; +} + + +void EUSART1_SetRxInterruptHandler(void (* interruptHandler)(void)){ + EUSART1_RxDefaultInterruptHandler = interruptHandler; +} +/** + End of File +*/ diff --git a/solar_panel.X/mcc_generated_files/eusart1.h b/solar_panel.X/mcc_generated_files/eusart1.h new file mode 100644 index 0000000..79b6300 --- /dev/null +++ b/solar_panel.X/mcc_generated_files/eusart1.h @@ -0,0 +1,477 @@ +/** + EUSART1 Generated Driver API Header File + + @Company + Microchip Technology Inc. + + @File Name + eusart1.h + + @Summary + This is the generated header file for the EUSART1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description + This header file provides APIs for driver for EUSART1. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F97J60 + Driver Version : 2.1.1 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#ifndef EUSART1_H +#define EUSART1_H + +/** + Section: Included Files +*/ + +#include +#include +#include + +#ifdef __cplusplus // Provide C++ Compatibility + + extern "C" { + +#endif + + +/** + Section: Macro Declarations +*/ + +#define EUSART1_DataReady (EUSART1_is_rx_ready()) + +/** + Section: Data Type Definitions +*/ + +typedef union { + struct { + unsigned perr : 1; + unsigned ferr : 1; + unsigned oerr : 1; + unsigned reserved : 5; + }; + uint8_t status; +}eusart1_status_t; + +/** + Section: Global variables + */ +extern volatile uint8_t eusart1TxBufferRemaining; +extern volatile uint8_t eusart1RxCount; + +/** + Section: EUSART1 APIs +*/ + +void (*EUSART1_RxDefaultInterruptHandler)(void); + +/** + @Summary + Initialization routine that takes inputs from the EUSART1 GUI. + + @Description + This routine initializes the EUSART1 driver. + This routine must be called before any other EUSART1 routine is called. + + @Preconditions + None + + @Param + None + + @Returns + None + + @Comment + +*/ +void EUSART1_Initialize(void); + +/** + @Summary + Checks if the EUSART1 transmitter is ready to transmit data + + @Description + This routine checks if EUSART1 transmitter is ready + to accept and transmit data byte + + @Preconditions + EUSART1_Initialize() function should have been called + before calling this function. + EUSART1 transmitter should be enabled before calling + this function + + @Param + None + + @Returns + Status of EUSART1 transmitter + TRUE: EUSART1 transmitter is ready + FALSE: EUSART1 transmitter is not ready + + @Example + + void main(void) + { + volatile uint8_t rxData; + + // Initialize the device + SYSTEM_Initialize(); + + while(1) + { + // Logic to echo received data + if(EUSART1_is_rx_ready()) + { + rxData = UART1_Read(); + if(EUSART1_is_tx_ready()) + { + EUSART1Write(rxData); + } + } + } + } + +*/ +bool EUSART1_is_tx_ready(void); + +/** + @Summary + Checks if the EUSART1 receiver ready for reading + + @Description + This routine checks if EUSART1 receiver has received data + and ready to be read + + @Preconditions + EUSART1_Initialize() function should be called + before calling this function + EUSART1 receiver should be enabled before calling this + function + + @Param + None + + @Returns + Status of EUSART1 receiver + TRUE: EUSART1 receiver is ready for reading + FALSE: EUSART1 receiver is not ready for reading + + @Example + + void main(void) + { + volatile uint8_t rxData; + + // Initialize the device + SYSTEM_Initialize(); + + while(1) + { + // Logic to echo received data + if(EUSART1_is_rx_ready()) + { + rxData = UART1_Read(); + if(EUSART1_is_tx_ready()) + { + EUSART1_Write(rxData); + } + } + } + } + +*/ +bool EUSART1_is_rx_ready(void); + +/** + @Summary + Checks if EUSART1 data is transmitted + + @Description + This function return the status of transmit shift register + + @Preconditions + EUSART1_Initialize() function should be called + before calling this function + EUSART1 transmitter should be enabled and EUSART1_Write + should be called before calling this function + + @Param + None + + @Returns + Status of EUSART1 receiver + TRUE: Data completely shifted out if the USART shift register + FALSE: Data is not completely shifted out of the shift register + + @Example + + void main(void) + { + volatile uint8_t rxData; + + // Initialize the device + SYSTEM_Initialize(); + + while(1) + { + if(EUSART1_is_tx_ready()) + { + LED_0_SetHigh(); + EUSART1Write(rxData); + } + if(EUSART1_is_tx_done() + { + LED_0_SetLow(); + } + } + } + +*/ +bool EUSART1_is_tx_done(void); + +/** + @Summary + Gets the error status of the last read byte. + + @Description + This routine gets the error status of the last read byte. + + @Preconditions + EUSART1_Initialize() function should have been called + before calling this function. The returned value is only + updated after a read is called. + + @Param + None + + @Returns + the status of the last read byte + + @Example + + void main(void) + { + volatile uint8_t rxData; + volatile eusart1_status_t rxStatus; + + // Initialize the device + SYSTEM_Initialize(); + + // Enable the Global Interrupts + INTERRUPT_GlobalInterruptEnable(); + + while(1) + { + // Logic to echo received data + if(EUSART1_is_rx_ready()) + { + rxData = EUSART1_Read(); + rxStatus = EUSART1_get_last_status(); + if(rxStatus.ferr){ + LED_0_SetHigh(); + } + } + } + } + + */ +eusart1_status_t EUSART1_get_last_status(void); + +/** + @Summary + Read a byte of data from the EUSART1. + + @Description + This routine reads a byte of data from the EUSART1. + + @Preconditions + EUSART1_Initialize() function should have been called + before calling this function. The transfer status should be checked to see + if the receiver is not empty before calling this function. + + @Param + None + + @Returns + A data byte received by the driver. +*/ +uint8_t EUSART1_Read(void); + + /** + @Summary + Writes a byte of data to the EUSART1. + + @Description + This routine writes a byte of data to the EUSART1. + + @Preconditions + EUSART1_Initialize() function should have been called + before calling this function. The transfer status should be checked to see + if transmitter is not busy before calling this function. + + @Param + txData - Data byte to write to the EUSART1 + + @Returns + None +*/ +void EUSART1_Write(uint8_t txData); + + +/** + @Summary + Maintains the driver's receiver state machine and implements its ISR + + @Description + This routine is used to maintain the driver's internal receiver state + machine.This interrupt service routine is called when the state of the + receiver needs to be maintained in a non polled manner. + + @Preconditions + EUSART1_Initialize() function should have been called + for the ISR to execute correctly. + + @Param + None + + @Returns + None +*/ +void EUSART1_Receive_ISR(void); + +/** + @Summary + Maintains the driver's receiver state machine + + @Description + This routine is called by the receive state routine and is used to maintain + the driver's internal receiver state machine. It should be called by a custom + ISR to maintain normal behavior + + @Preconditions + EUSART1_Initialize() function should have been called + for the ISR to execute correctly. + + @Param + None + + @Returns + None +*/ +void EUSART1_RxDataHandler(void); + +/** + @Summary + Set EUSART1 Framing Error Handler + + @Description + This API sets the function to be called upon EUSART1 framing error + + @Preconditions + Initialize the EUSART1 before calling this API + + @Param + Address of function to be set as framing error handler + + @Returns + None +*/ +void EUSART1_SetFramingErrorHandler(void (* interruptHandler)(void)); + +/** + @Summary + Set EUSART1 Overrun Error Handler + + @Description + This API sets the function to be called upon EUSART1 overrun error + + @Preconditions + Initialize the EUSART1 module before calling this API + + @Param + Address of function to be set as overrun error handler + + @Returns + None +*/ +void EUSART1_SetOverrunErrorHandler(void (* interruptHandler)(void)); + +/** + @Summary + Set EUSART1 Error Handler + + @Description + This API sets the function to be called upon EUSART1 error + + @Preconditions + Initialize the EUSART1 module before calling this API + + @Param + Address of function to be set as error handler + + @Returns + None +*/ +void EUSART1_SetErrorHandler(void (* interruptHandler)(void)); + + +/** + @Summary + Sets the receive handler function to be called by the interrupt service + + @Description + Calling this function will set a new custom function that will be + called when the receive interrupt needs servicing. + + @Preconditions + EUSART1_Initialize() function should have been called + for the ISR to execute correctly. + + @Param + A pointer to the new function + + @Returns + None +*/ +void EUSART1_SetRxInterruptHandler(void (* interruptHandler)(void)); + +#ifdef __cplusplus // Provide C++ Compatibility + + } + +#endif + +#endif // EUSART1_H +/** + End of File +*/ diff --git a/solar_panel.X/mcc_generated_files/interrupt_manager.c b/solar_panel.X/mcc_generated_files/interrupt_manager.c new file mode 100644 index 0000000..dcd3f6b --- /dev/null +++ b/solar_panel.X/mcc_generated_files/interrupt_manager.c @@ -0,0 +1,83 @@ +/** + Generated Interrupt Manager Source File + + @Company: + Microchip Technology Inc. + + @File Name: + interrupt_manager.c + + @Summary: + This is the Interrupt Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description: + This header file provides implementations for global interrupt handling. + For individual peripheral handlers please see the peripheral driver for + all modules selected in the GUI. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F97J60 + Driver Version : 2.04 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above or later + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#include "interrupt_manager.h" +#include "mcc.h" + +void INTERRUPT_Initialize (void) +{ + // Disable Interrupt Priority Vectors (16CXXX Compatibility Mode) + RCONbits.IPEN = 0; +} + +void __interrupt() INTERRUPT_InterruptManager (void) +{ + // interrupt handler + if(INTCONbits.TMR0IE == 1 && INTCONbits.TMR0IF == 1) + { + TMR0_ISR(); + } + else if(INTCONbits.PEIE == 1) + { + if(PIE1bits.RC1IE == 1 && PIR1bits.RC1IF == 1) + { + EUSART1_RxDefaultInterruptHandler(); + } + else + { + //Unhandled Interrupt + } + } + else + { + //Unhandled Interrupt + } +} +/** + End of File +*/ diff --git a/solar_panel.X/mcc_generated_files/interrupt_manager.h b/solar_panel.X/mcc_generated_files/interrupt_manager.h new file mode 100644 index 0000000..62274b4 --- /dev/null +++ b/solar_panel.X/mcc_generated_files/interrupt_manager.h @@ -0,0 +1,115 @@ +/** + Generated Interrupt Manager Header File + + @Company: + Microchip Technology Inc. + + @File Name: + interrupt_manager.h + + @Summary: + This is the Interrupt Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description: + This header file provides implementations for global interrupt handling. + For individual peripheral handlers please see the peripheral driver for + all modules selected in the GUI. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F97J60 + Driver Version : 2.03 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above or later + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#ifndef INTERRUPT_MANAGER_H +#define INTERRUPT_MANAGER_H + + +/** + * @Param + none + * @Returns + none + * @Description + This macro will enable global interrupts. + * @Example + INTERRUPT_GlobalInterruptEnable(); + */ +#define INTERRUPT_GlobalInterruptEnable() (INTCONbits.GIE = 1) + +/** + * @Param + none + * @Returns + none + * @Description + This macro will disable global interrupts. + * @Example + INTERRUPT_GlobalInterruptDisable(); + */ +#define INTERRUPT_GlobalInterruptDisable() (INTCONbits.GIE = 0) +/** + * @Param + none + * @Returns + none + * @Description + This macro will enable peripheral interrupts. + * @Example + INTERRUPT_PeripheralInterruptEnable(); + */ +#define INTERRUPT_PeripheralInterruptEnable() (INTCONbits.PEIE = 1) + +/** + * @Param + none + * @Returns + none + * @Description + This macro will disable peripheral interrupts. + * @Example + INTERRUPT_PeripheralInterruptDisable(); + */ +#define INTERRUPT_PeripheralInterruptDisable() (INTCONbits.PEIE = 0) + +/** + * @Param + none + * @Returns + none + * @Description + Initializes PIC18 peripheral interrupt priorities; enables/disables priority vectors + * @Example + INTERRUPT_Initialize(); + */ +void INTERRUPT_Initialize (void); + +#endif // INTERRUPT_MANAGER_H +/** + End of File +*/ diff --git a/solar_panel.X/mcc_generated_files/mcc.c b/solar_panel.X/mcc_generated_files/mcc.c index 00f5e92..e33f30d 100644 --- a/solar_panel.X/mcc_generated_files/mcc.c +++ b/solar_panel.X/mcc_generated_files/mcc.c @@ -50,11 +50,14 @@ void SYSTEM_Initialize(void) { + INTERRUPT_Initialize(); PIN_MANAGER_Initialize(); OSCILLATOR_Initialize(); + ADC_Initialize(); EPWM1_Initialize(); TMR2_Initialize(); - ADC_Initialize(); + TMR0_Initialize(); + EUSART1_Initialize(); } void OSCILLATOR_Initialize(void) diff --git a/solar_panel.X/mcc_generated_files/mcc.h b/solar_panel.X/mcc_generated_files/mcc.h index 3e771aa..01e4f94 100644 --- a/solar_panel.X/mcc_generated_files/mcc.h +++ b/solar_panel.X/mcc_generated_files/mcc.h @@ -52,9 +52,12 @@ #include #include #include +#include "interrupt_manager.h" #include "epwm1.h" #include "tmr2.h" #include "adc.h" +#include "tmr0.h" +#include "eusart1.h" diff --git a/solar_panel.X/mcc_generated_files/tmr0.c b/solar_panel.X/mcc_generated_files/tmr0.c new file mode 100644 index 0000000..ad3ca68 --- /dev/null +++ b/solar_panel.X/mcc_generated_files/tmr0.c @@ -0,0 +1,167 @@ +/** + TMR0 Generated Driver File + + @Company + Microchip Technology Inc. + + @File Name + tmr0.c + + @Summary + This is the generated driver implementation file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description + This source file provides APIs for TMR0. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F97J60 + Driver Version : 2.01 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +/** + Section: Included Files +*/ + +#include +#include "tmr0.h" + +/** + Section: Global Variables Definitions +*/ + +void (*TMR0_InterruptHandler)(void); + +volatile uint16_t timer0ReloadVal; + +/** + Section: TMR0 APIs +*/ + + +void TMR0_Initialize(void) +{ + // Set TMR0 to the options selected in the User Interface + + //Enable 16bit timer mode before assigning value to TMR0H + T0CONbits.T08BIT = 0; + + // TMR0H 255; + TMR0H = 0xFF; + + // TMR0L 252; + TMR0L = 0xFC; + + + // Load TMR0 value to the 16-bit reload variable + timer0ReloadVal = (uint16_t)((TMR0H << 8) | TMR0L); + + // Clear Interrupt flag before enabling the interrupt + INTCONbits.TMR0IF = 0; + + // Enabling TMR0 interrupt. + INTCONbits.TMR0IE = 1; + + // Set Default Interrupt Handler + TMR0_SetInterruptHandler(TMR0_DefaultInterruptHandler); + + // T0PS 1:2; T08BIT 16-bit; T0SE Increment_hi_lo; T0CS T0CKI; TMR0ON enabled; PSA not_assigned; + T0CON = 0xB8; +} + +void TMR0_StartTimer(void) +{ + // Start the Timer by writing to TMR0ON bit + T0CONbits.TMR0ON = 1; +} + +void TMR0_StopTimer(void) +{ + // Stop the Timer by writing to TMR0ON bit + T0CONbits.TMR0ON = 0; +} + +uint16_t TMR0_ReadTimer(void) +{ + uint16_t readVal; + uint8_t readValLow; + uint8_t readValHigh; + + readValLow = TMR0L; + readValHigh = TMR0H; + readVal = ((uint16_t)readValHigh << 8) + readValLow; + + return readVal; +} + +void TMR0_WriteTimer(uint16_t timerVal) +{ + // Write to the Timer0 register + TMR0H = timerVal >> 8; + TMR0L = (uint8_t) timerVal; +} + +void TMR0_Reload(void) +{ + // Write to the Timer0 register + TMR0H = timer0ReloadVal >> 8; + TMR0L = (uint8_t) timer0ReloadVal; +} + +void TMR0_ISR(void) +{ + + // clear the TMR0 interrupt flag + INTCONbits.TMR0IF = 0; + + // reload TMR0 + // Write to the Timer0 register + TMR0H = timer0ReloadVal >> 8; + TMR0L = (uint8_t) timer0ReloadVal; + + if(TMR0_InterruptHandler) + { + TMR0_InterruptHandler(); + } + + // add your TMR0 interrupt custom code +} + + +void TMR0_SetInterruptHandler(void (* InterruptHandler)(void)){ + TMR0_InterruptHandler = InterruptHandler; +} + +void TMR0_DefaultInterruptHandler(void){ + // add your TMR0 interrupt custom code + // or set custom function using TMR0_SetInterruptHandler() +} + +/** + End of File +*/ \ No newline at end of file diff --git a/solar_panel.X/mcc_generated_files/tmr0.h b/solar_panel.X/mcc_generated_files/tmr0.h new file mode 100644 index 0000000..38df85d --- /dev/null +++ b/solar_panel.X/mcc_generated_files/tmr0.h @@ -0,0 +1,356 @@ +/** + TMR0 Generated Driver API Header File + + @Company + Microchip Technology Inc. + + @File Name + tmr0.h + + @Summary + This is the generated header file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description + This header file provides APIs for TMR0. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F97J60 + Driver Version : 2.01 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#ifndef TMR0_H +#define TMR0_H + +/** + Section: Included Files +*/ + +#include +#include + +#ifdef __cplusplus // Provide C++ Compatibility + + extern "C" { + +#endif + + + +/** + Section: TMR0 APIs +*/ + +/** + @Summary + Initializes the TMR0. + + @Description + This function initializes the TMR0 Registers. + This function must be called before any other TMR0 function is called. + + @Preconditions + None + + @Param + None + + @Returns + None + + @Comment + + + @Example + + main() + { + // Initialize TMR0 module + TMR0_Initialize(); + + // Do something else... + } + +*/ +void TMR0_Initialize(void); + +/** + @Summary + This function starts the TMR0. + + @Description + This function starts the TMR0 operation. + This function must be called after the initialization of TMR0. + + @Preconditions + Initialize the TMR0 before calling this function. + + @Param + None + + @Returns + None + + @Example + + // Initialize TMR0 module + + // Start TMR0 + TMR0_StartTimer(); + + // Do something else... + +*/ +void TMR0_StartTimer(void); + +/** + @Summary + This function stops the TMR0. + + @Description + This function stops the TMR0 operation. + This function must be called after the start of TMR0. + + @Preconditions + Initialize the TMR0 before calling this function. + + @Param + None + + @Returns + None + + @Example + + // Initialize TMR0 module + + // Start TMR0 + TMR0_StartTimer(); + + // Do something else... + + // Stop TMR0; + TMR0_StopTimer(); + +*/ +void TMR0_StopTimer(void); + + +/** + @Summary + Reads the 16 bits TMR0 register value. + + @Description + This function reads the 16 bits TMR0 register value and return it. + + @Preconditions + Initialize the TMR0 before calling this function. + + @Param + None + + @Returns + This function returns the 16 bits value of TMR0 register. + + @Example + + // Initialize TMR0 module + + // Start TMR0 + TMR0_StartTimer(); + + // Read the current value of TMR0 + if(0 == TMR0_ReadTimer()) + { + // Do something else... + + // Reload the TMR value + TMR0_Reload(); + } + +*/ +uint16_t TMR0_ReadTimer(void); + +/** + @Summary + Writes the 16 bits value to TMR0 register. + + @Description + This function writes the 16 bits value to TMR0 register. + This function must be called after the initialization of TMR0. + + @Preconditions + Initialize the TMR0 before calling this function. + + @Param + timerVal - Value to write into TMR0 register. + + @Returns + None + + @Example + + #define PERIOD 0x8000 + #define ZERO 0x0000 + + while(1) + { + //Read the TMR0 register + if(ZERO == TMR0_ReadTimer()) + { + // Do something else... + + // Write the TMR0 register + TMR0_WriteTimer(PERIOD); + } + + // Do something else... + } + +*/ +void TMR0_WriteTimer(uint16_t timerVal); + +/** + @Summary + Reload the 16 bits value to TMR0 register. + + @Description + This function reloads the 16 bit value to TMR0 register. + This function must be called to write initial value into TMR0 register. + + @Preconditions + Initialize the TMR0 before calling this function. + + @Param + None + + @Returns + None + + @Example + + while(1) + { + if(TMR0IF) + { + // Do something else... + + // clear the TMR0 interrupt flag + TMR0IF = 0; + + // Reload the initial value of TMR0 + TMR0_Reload(); + } + } + +*/ +void TMR0_Reload(void); + +/** + @Summary + Timer Interrupt Service Routine + + @Description + Timer Interrupt Service Routine is called by the Interrupt Manager. + + @Preconditions + Initialize the TMR0 module with interrupt before calling this isr. + + @Param + None + + @Returns + None + */ +void TMR0_ISR(void); + + +/** + @Summary + Set Timer Interrupt Handler + + @Description + This sets the function to be called during the ISR + + @Preconditions + Initialize the TMR0 module with interrupt before calling this. + + @Param + Address of function to be set + + @Returns + None +*/ + void TMR0_SetInterruptHandler(void (* InterruptHandler)(void)); + +/** + @Summary + Timer Interrupt Handler + + @Description + This is a function pointer to the function that will be called during the ISR + + @Preconditions + Initialize the TMR0 module with interrupt before calling this isr. + + @Param + None + + @Returns + None +*/ +extern void (*TMR0_InterruptHandler)(void); + +/** + @Summary + Default Timer Interrupt Handler + + @Description + This is the default Interrupt Handler function + + @Preconditions + Initialize the TMR0 module with interrupt before calling this isr. + + @Param + None + + @Returns + None +*/ +void TMR0_DefaultInterruptHandler(void); + +#ifdef __cplusplus // Provide C++ Compatibility + + } + +#endif + +#endif // TMR0_H +/** + End of File +*/ \ No newline at end of file diff --git a/solar_panel.X/nbproject/Makefile-default.mk b/solar_panel.X/nbproject/Makefile-default.mk index c9750c4..3315f44 100644 --- a/solar_panel.X/nbproject/Makefile-default.mk +++ b/solar_panel.X/nbproject/Makefile-default.mk @@ -57,17 +57,17 @@ OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE} DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE} # Source Files Quoted if spaced -SOURCEFILES_QUOTED_IF_SPACED=lcd/lcd.c mcc_generated_files/device_config.c mcc_generated_files/mcc.c mcc_generated_files/pin_manager.c mcc_generated_files/adc.c main.c crc.c measure.c modbus.c mcc_generated_files/epwm1.c mcc_generated_files/tmr2.c +SOURCEFILES_QUOTED_IF_SPACED=lcd/lcd.c mcc_generated_files/device_config.c mcc_generated_files/mcc.c mcc_generated_files/pin_manager.c mcc_generated_files/adc.c main.c crc.c measure.c modbus.c mcc_generated_files/epwm1.c mcc_generated_files/tmr2.c mcc_generated_files/eusart1.c mcc_generated_files/interrupt_manager.c mcc_generated_files/tmr0.c # Object Files Quoted if spaced -OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/lcd/lcd.p1 ${OBJECTDIR}/mcc_generated_files/device_config.p1 ${OBJECTDIR}/mcc_generated_files/mcc.p1 ${OBJECTDIR}/mcc_generated_files/pin_manager.p1 ${OBJECTDIR}/mcc_generated_files/adc.p1 ${OBJECTDIR}/main.p1 ${OBJECTDIR}/crc.p1 ${OBJECTDIR}/measure.p1 ${OBJECTDIR}/modbus.p1 ${OBJECTDIR}/mcc_generated_files/epwm1.p1 ${OBJECTDIR}/mcc_generated_files/tmr2.p1 -POSSIBLE_DEPFILES=${OBJECTDIR}/lcd/lcd.p1.d ${OBJECTDIR}/mcc_generated_files/device_config.p1.d ${OBJECTDIR}/mcc_generated_files/mcc.p1.d ${OBJECTDIR}/mcc_generated_files/pin_manager.p1.d ${OBJECTDIR}/mcc_generated_files/adc.p1.d ${OBJECTDIR}/main.p1.d ${OBJECTDIR}/crc.p1.d ${OBJECTDIR}/measure.p1.d ${OBJECTDIR}/modbus.p1.d ${OBJECTDIR}/mcc_generated_files/epwm1.p1.d ${OBJECTDIR}/mcc_generated_files/tmr2.p1.d +OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/lcd/lcd.p1 ${OBJECTDIR}/mcc_generated_files/device_config.p1 ${OBJECTDIR}/mcc_generated_files/mcc.p1 ${OBJECTDIR}/mcc_generated_files/pin_manager.p1 ${OBJECTDIR}/mcc_generated_files/adc.p1 ${OBJECTDIR}/main.p1 ${OBJECTDIR}/crc.p1 ${OBJECTDIR}/measure.p1 ${OBJECTDIR}/modbus.p1 ${OBJECTDIR}/mcc_generated_files/epwm1.p1 ${OBJECTDIR}/mcc_generated_files/tmr2.p1 ${OBJECTDIR}/mcc_generated_files/eusart1.p1 ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1 ${OBJECTDIR}/mcc_generated_files/tmr0.p1 +POSSIBLE_DEPFILES=${OBJECTDIR}/lcd/lcd.p1.d ${OBJECTDIR}/mcc_generated_files/device_config.p1.d ${OBJECTDIR}/mcc_generated_files/mcc.p1.d ${OBJECTDIR}/mcc_generated_files/pin_manager.p1.d ${OBJECTDIR}/mcc_generated_files/adc.p1.d ${OBJECTDIR}/main.p1.d ${OBJECTDIR}/crc.p1.d ${OBJECTDIR}/measure.p1.d ${OBJECTDIR}/modbus.p1.d ${OBJECTDIR}/mcc_generated_files/epwm1.p1.d ${OBJECTDIR}/mcc_generated_files/tmr2.p1.d ${OBJECTDIR}/mcc_generated_files/eusart1.p1.d ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1.d ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d # Object Files -OBJECTFILES=${OBJECTDIR}/lcd/lcd.p1 ${OBJECTDIR}/mcc_generated_files/device_config.p1 ${OBJECTDIR}/mcc_generated_files/mcc.p1 ${OBJECTDIR}/mcc_generated_files/pin_manager.p1 ${OBJECTDIR}/mcc_generated_files/adc.p1 ${OBJECTDIR}/main.p1 ${OBJECTDIR}/crc.p1 ${OBJECTDIR}/measure.p1 ${OBJECTDIR}/modbus.p1 ${OBJECTDIR}/mcc_generated_files/epwm1.p1 ${OBJECTDIR}/mcc_generated_files/tmr2.p1 +OBJECTFILES=${OBJECTDIR}/lcd/lcd.p1 ${OBJECTDIR}/mcc_generated_files/device_config.p1 ${OBJECTDIR}/mcc_generated_files/mcc.p1 ${OBJECTDIR}/mcc_generated_files/pin_manager.p1 ${OBJECTDIR}/mcc_generated_files/adc.p1 ${OBJECTDIR}/main.p1 ${OBJECTDIR}/crc.p1 ${OBJECTDIR}/measure.p1 ${OBJECTDIR}/modbus.p1 ${OBJECTDIR}/mcc_generated_files/epwm1.p1 ${OBJECTDIR}/mcc_generated_files/tmr2.p1 ${OBJECTDIR}/mcc_generated_files/eusart1.p1 ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1 ${OBJECTDIR}/mcc_generated_files/tmr0.p1 # Source Files -SOURCEFILES=lcd/lcd.c mcc_generated_files/device_config.c mcc_generated_files/mcc.c mcc_generated_files/pin_manager.c mcc_generated_files/adc.c main.c crc.c measure.c modbus.c mcc_generated_files/epwm1.c mcc_generated_files/tmr2.c +SOURCEFILES=lcd/lcd.c mcc_generated_files/device_config.c mcc_generated_files/mcc.c mcc_generated_files/pin_manager.c mcc_generated_files/adc.c main.c crc.c measure.c modbus.c mcc_generated_files/epwm1.c mcc_generated_files/tmr2.c mcc_generated_files/eusart1.c mcc_generated_files/interrupt_manager.c mcc_generated_files/tmr0.c @@ -182,6 +182,30 @@ ${OBJECTDIR}/mcc_generated_files/tmr2.p1: mcc_generated_files/tmr2.c nbproject/ @-${MV} ${OBJECTDIR}/mcc_generated_files/tmr2.d ${OBJECTDIR}/mcc_generated_files/tmr2.p1.d @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/tmr2.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ +${OBJECTDIR}/mcc_generated_files/eusart1.p1: mcc_generated_files/eusart1.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}/mcc_generated_files" + @${RM} ${OBJECTDIR}/mcc_generated_files/eusart1.p1.d + @${RM} ${OBJECTDIR}/mcc_generated_files/eusart1.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/mcc_generated_files/eusart1.p1 mcc_generated_files/eusart1.c + @-${MV} ${OBJECTDIR}/mcc_generated_files/eusart1.d ${OBJECTDIR}/mcc_generated_files/eusart1.p1.d + @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/eusart1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1: mcc_generated_files/interrupt_manager.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}/mcc_generated_files" + @${RM} ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1.d + @${RM} ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1 mcc_generated_files/interrupt_manager.c + @-${MV} ${OBJECTDIR}/mcc_generated_files/interrupt_manager.d ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1.d + @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/mcc_generated_files/tmr0.p1: mcc_generated_files/tmr0.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}/mcc_generated_files" + @${RM} ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d + @${RM} ${OBJECTDIR}/mcc_generated_files/tmr0.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/mcc_generated_files/tmr0.p1 mcc_generated_files/tmr0.c + @-${MV} ${OBJECTDIR}/mcc_generated_files/tmr0.d ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d + @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + else ${OBJECTDIR}/lcd/lcd.p1: lcd/lcd.c nbproject/Makefile-${CND_CONF}.mk @${MKDIR} "${OBJECTDIR}/lcd" @@ -271,6 +295,30 @@ ${OBJECTDIR}/mcc_generated_files/tmr2.p1: mcc_generated_files/tmr2.c nbproject/ @-${MV} ${OBJECTDIR}/mcc_generated_files/tmr2.d ${OBJECTDIR}/mcc_generated_files/tmr2.p1.d @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/tmr2.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ +${OBJECTDIR}/mcc_generated_files/eusart1.p1: mcc_generated_files/eusart1.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}/mcc_generated_files" + @${RM} ${OBJECTDIR}/mcc_generated_files/eusart1.p1.d + @${RM} ${OBJECTDIR}/mcc_generated_files/eusart1.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/mcc_generated_files/eusart1.p1 mcc_generated_files/eusart1.c + @-${MV} ${OBJECTDIR}/mcc_generated_files/eusart1.d ${OBJECTDIR}/mcc_generated_files/eusart1.p1.d + @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/eusart1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1: mcc_generated_files/interrupt_manager.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}/mcc_generated_files" + @${RM} ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1.d + @${RM} ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1 mcc_generated_files/interrupt_manager.c + @-${MV} ${OBJECTDIR}/mcc_generated_files/interrupt_manager.d ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1.d + @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/mcc_generated_files/tmr0.p1: mcc_generated_files/tmr0.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}/mcc_generated_files" + @${RM} ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d + @${RM} ${OBJECTDIR}/mcc_generated_files/tmr0.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/mcc_generated_files/tmr0.p1 mcc_generated_files/tmr0.c + @-${MV} ${OBJECTDIR}/mcc_generated_files/tmr0.d ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d + @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + endif # ------------------------------------------------------------------------------------ diff --git a/solar_panel.X/nbproject/Makefile-genesis.properties b/solar_panel.X/nbproject/Makefile-genesis.properties index 8b9d6e6..da78265 100644 --- a/solar_panel.X/nbproject/Makefile-genesis.properties +++ b/solar_panel.X/nbproject/Makefile-genesis.properties @@ -1,11 +1,11 @@ # -#Fri Mar 03 13:24:37 CET 2023 +#Fri Mar 03 14:42:22 CET 2023 default.languagetoolchain.version=2.40 default.Pack.dfplocation=C\:\\Program Files\\Microchip\\MPLABX\\v6.00\\packs\\Microchip\\PIC18F-J_DFP\\1.5.44 conf.ids=default default.languagetoolchain.dir=C\:\\Program Files\\Microchip\\xc8\\v2.40\\bin host.id=3awj-afwq-rl -configurations-xml=080b6b0e67e3ef40b76cf6528cd7e334 +configurations-xml=19a2811a74f6d1b3cc6f3802bb8369cf default.com-microchip-mplab-mdbcore-snap-SnapToolImpl.md5=eaa336cefb7fc46db8b50b7b2b6e54ca com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=6e02ca5e9f5042ffd365b42ab82d3a9b user-defined-mime-resolver-xml=none diff --git a/solar_panel.X/nbproject/configurations.xml b/solar_panel.X/nbproject/configurations.xml index 4e9670e..f432be8 100644 --- a/solar_panel.X/nbproject/configurations.xml +++ b/solar_panel.X/nbproject/configurations.xml @@ -16,6 +16,9 @@ mcc_generated_files/adc.h mcc_generated_files/epwm1.h mcc_generated_files/tmr2.h + mcc_generated_files/interrupt_manager.h + mcc_generated_files/tmr0.h + mcc_generated_files/eusart1.h crc.h measure.h @@ -40,6 +43,9 @@ mcc_generated_files/adc.c mcc_generated_files/epwm1.c mcc_generated_files/tmr2.c + mcc_generated_files/eusart1.c + mcc_generated_files/interrupt_manager.c + mcc_generated_files/tmr0.c main.c crc.c diff --git a/solar_panel.X/solar_panel.mc3 b/solar_panel.X/solar_panel.mc3 index 7f6f718..c4cb3de 100644 --- a/solar_panel.X/solar_panel.mc3 +++ b/solar_panel.X/solar_panel.mc3 @@ -9,6 +9,10 @@ ECCP1 class com.microchip.mcc.mcu8.modules.eccp.ECCP + + EUSART1 + class com.microchip.mcc.mcu8.modules.eusart.EUSART + INTERNAL OSCILLATOR class com.microchip.mcc.mcu8.systemManager.osc_v3.Osc @@ -29,6 +33,10 @@ System Module class com.microchip.mcc.mcu8.systemManager.SystemManager + + TMR0 + class com.microchip.mcc.mcu8.modules.tmr0_v1.TMR0 + TMR2 class com.microchip.mcc.mcu8.modules.tmr2_v3.TMR2 @@ -750,6 +758,378 @@ automatic_restart + + + enabled + + + + disabled + + + + RxDefaultInterruptHandler + + + + TxDefaultInterruptHandler + + + + 8 + + + + 8 + + + + 9600 + + + + Error: 0.006 % + + + + easysetup + + + + out + + + + enabled + + + + 25000000 + + + + eusart_interrupt + + + + disabled + + + + 0 + + + + 1 + + + + 0 + + + + 1 + + + + 1 + + + + 0 + + + + 1 + + + + 0 + + + + 0 + + + + 1 + + + + 1 + + + + 0 + + + + 0 + + + + 1 + + + + 0 + + + + 1 + + + + 0 + + + + 1 + + + + 1 + + + + 0 + + + + 1 + + + + 0 + + + + 0 + + + + 1 + + + + 0 + + + + 1 + + + + 0 + + + + 1 + + + + 1 + + + + 0 + + + + 1 + + + + 0 + + + + 1 + + + + 0 + + + + 0 + + + + 1 + + + + 1 + + + + 0 + + + + 0 + + + + 1 + + + + 0 + + + + 1 + + + + 8 + + + + 208 + + + + 2 + + + + 138 + + + + 0 + + + + 244 + + + + disabled + + + + no_overflow + + + + 16bit_generator + + + + not_inverted + + + + idle + + + + async_noninverted_sync_fallingedge + + + + disabled + + + + enabled + + + + disabled + + + + -1 + + + + 1 + + + + disabled + + + + enabled + + + + no_error + + + + no_error + + + + 9-bit + + + + 0 + + + + enabled + + + + disabled + + + + disabled + + + + disabled + + + + -1 + + + + 1 + + + + hi_speed + + + + master_mode + + + + sync_break_complete + + + + synchronous + + + + TSR_empty + + + + 9-bit + + + + 0 + + + + enabled + @@ -5214,6 +5594,194 @@ OFF + + + 0 + + + + ISR + + + + 0.00003 + + + + 25000000 + + + + 100000 + + + + 0.65535 + + + + 0.00001 + + + + enabled + + + + 1 + + + + 100000 + + + + 0.000035 + + + + enabled + + + + 0 + + + + enabled + + + + 6 + + + + 3 + + + + 0 + + + + 7 + + + + 4 + + + + 1 + + + + 5 + + + + 2 + + + + 0 + + + + 1 + + + + 0 + + + + 1 + + + + 0 + + + + 1 + + + + 0 + + + + 1 + + + + 1 + + + + 0 + + + + 184 + + + + 255 + + + + 252 + + + + 1:2 + + + + not_assigned + + + + 16-bit + + + + enabled + + + + T0CKI + + + + Increment_hi_lo + + + + 255 + + + + 252 + + + + enabled + + + + disabled + + + + -1 + + + + 1 + 0 @@ -5402,12 +5970,24 @@ mcc_generated_files\mcc.h - 163eeab73ba2645b62407134fd74f192252b4a78fc740ce8959eebb831a39c2e + 52b447a5dc446f42c76e7a13f2403349cfdc20fc87fe880892a4f08ac41ec7ec mcc_generated_files\device_config.h e658a4cb6ac1c79b2a52ab2754ebce26d229cbe4bd8464122f3272d1e76e5881 + + mcc_generated_files\interrupt_manager.h + 5c311e57ab563c3fadc6e5c40b1e425436e9366c40e5772f46f393a9f8ed9d39 + + + mcc_generated_files\eusart1.h + c6209c27bd9de6f3041c2f8d1df1cccce2b09bdf4b5098ae0b333a7f92205022 + + + mcc_generated_files\tmr0.h + 60487f4faa42d9fec7389ebc68c7a0a01ec6343892ddd4f936b3e776d62a07b0 + main.c 30e3e0e5956e494fcd566f1509f2f2bbc404d25265a77934114af7c9d1fcdbd7 @@ -5436,6 +6016,10 @@ mcc_generated_files\epwm1.h e1dacec839b43c4ec99f1710c3a7872ce32d2ea6dfe3856eb466e690b7ea75c9 + + mcc_generated_files\tmr0.c + 6ee4809b94f1e2488f05488f97e0cdc3e8db39b9f132a99c2d2daf3b13befbf7 + mcc_generated_files\pin_manager.c f23627897b323c5e312c50538e92449a15673b1b943138129b8c0214ac47a4d4 @@ -5450,7 +6034,15 @@ mcc_generated_files\mcc.c - eda682c043199d8627daf3584afc45a08bb3bb8526554f70c327ca6e3b587544 + 32ff3e2dadb25f5b8ccb3d70520f2b25f98e471a9bccb87758edd960e922e48c + + + mcc_generated_files\interrupt_manager.c + 9bec65c4415d6a1861d1d33f5aecfcf2c426de3ac2962449aec821b45c527ef2 + + + mcc_generated_files\eusart1.c + 627becf328c45a7c7ebff85e99496289e162e55eef7d703ea105fffd0439dd76 \ No newline at end of file From 8d56267f66985963a8a53cc3f812579c9c1c7f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 3 Mar 2023 16:10:37 +0100 Subject: [PATCH 4/7] begining of tx, but nothing work TODO fix all ! --- solar_panel.X/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/solar_panel.X/main.c b/solar_panel.X/main.c index a03868e..de0ff6a 100644 --- a/solar_panel.X/main.c +++ b/solar_panel.X/main.c @@ -44,6 +44,7 @@ #include "mcc_generated_files/mcc.h" #include "lcd/lcd.h" #include "measure.h" +#include "modbus.h" #define MAX_COL 16 /* @@ -60,6 +61,7 @@ void main(void) Lcd_Init(); adc_init(); + modbus_init(0x80); uint16_t offsetCurrent = 0; offsetCurrent = measure_current(offsetCurrent); @@ -108,6 +110,9 @@ void resetTMR0(void){ } void endFrame(void){ + TMR0_StopTimer(); + modbus_analyse_and_answer(); + // TODO } /** From 87aa31868aa977c63b9955b54997d20c28a76ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 3 Mar 2023 16:11:29 +0100 Subject: [PATCH 5/7] - --- solar_panel.X/mcc_generated_files/eusart1.c | 18 +- solar_panel.X/mcc_generated_files/eusart1.h | 3 +- .../mcc_generated_files/pin_manager.c | 2 +- .../mcc_generated_files/pin_manager.h | 8 + solar_panel.X/mcc_generated_files/tmr0.c | 12 +- solar_panel.X/modbus.c | 10 +- solar_panel.X/nbproject/Makefile-default.mk | 154 ++++++++++-------- .../nbproject/Makefile-genesis.properties | 4 +- solar_panel.X/nbproject/configurations.xml | 2 + solar_panel.X/nbproject/private/private.xml | 10 +- solar_panel.X/solar_panel.mc3 | 48 +++--- solar_panel.X/uart.c | 7 + solar_panel.X/uart.h | 18 ++ 13 files changed, 176 insertions(+), 120 deletions(-) create mode 100644 solar_panel.X/uart.c create mode 100644 solar_panel.X/uart.h diff --git a/solar_panel.X/mcc_generated_files/eusart1.c b/solar_panel.X/mcc_generated_files/eusart1.c index 01e4133..5700d00 100644 --- a/solar_panel.X/mcc_generated_files/eusart1.c +++ b/solar_panel.X/mcc_generated_files/eusart1.c @@ -70,6 +70,8 @@ volatile eusart1_status_t eusart1RxLastError; /** Section: EUSART1 APIs */ +void (*EUSART1_RxDefaultInterruptHandler)(void); + void (*EUSART1_FramingErrorHandler)(void); void (*EUSART1_OverrunErrorHandler)(void); void (*EUSART1_ErrorHandler)(void); @@ -91,8 +93,8 @@ void EUSART1_Initialize(void) // SPEN enabled; RX9 9-bit; CREN enabled; ADDEN disabled; SREN disabled; RCSTA1 = 0xD0; - // TX9 9-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC synchronous; BRGH hi_speed; CSRC master_mode; - TXSTA1 = 0xF4; + // TX9 9-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC master_mode; + TXSTA1 = 0xE4; // SPBRG1 = 0x8A; @@ -138,12 +140,11 @@ eusart1_status_t EUSART1_get_last_status(void){ uint8_t EUSART1_Read(void) { uint8_t readValue = 0; - RCSTA1bits.SREN = 1; while(0 == eusart1RxCount) { } - + eusart1RxLastError = eusart1RxStatusBuffer[eusart1RxTail]; readValue = eusart1RxBuffer[eusart1RxTail++]; @@ -160,8 +161,6 @@ uint8_t EUSART1_Read(void) void EUSART1_Write(uint8_t txData) { - RCSTA1bits.SREN = 0; - RCSTA1bits.CREN = 0; while(0 == PIR1bits.TX1IF) { } @@ -169,6 +168,8 @@ void EUSART1_Write(uint8_t txData) TXREG1 = txData; // Write the data byte to the USART. } + + void EUSART1_Receive_ISR(void) { @@ -178,7 +179,7 @@ void EUSART1_Receive_ISR(void) eusart1RxStatusBuffer[eusart1RxHead].ferr = 1; EUSART1_FramingErrorHandler(); } - + if(RCSTA1bits.OERR){ eusart1RxStatusBuffer[eusart1RxHead].oerr = 1; EUSART1_OverrunErrorHandler(); @@ -190,7 +191,7 @@ void EUSART1_Receive_ISR(void) EUSART1_RxDataHandler(); } - // or set custom function using eusart1_SetRxInterruptHandler() + // or set custom function using EUSART1_SetRxInterruptHandler() } void EUSART1_RxDataHandler(void){ @@ -201,7 +202,6 @@ void EUSART1_RxDataHandler(void){ eusart1RxHead = 0; } eusart1RxCount++; - } void EUSART1_DefaultFramingErrorHandler(void){} diff --git a/solar_panel.X/mcc_generated_files/eusart1.h b/solar_panel.X/mcc_generated_files/eusart1.h index 79b6300..2a70662 100644 --- a/solar_panel.X/mcc_generated_files/eusart1.h +++ b/solar_panel.X/mcc_generated_files/eusart1.h @@ -91,8 +91,7 @@ extern volatile uint8_t eusart1RxCount; /** Section: EUSART1 APIs */ - -void (*EUSART1_RxDefaultInterruptHandler)(void); +extern void (*EUSART1_RxDefaultInterruptHandler)(void); /** @Summary diff --git a/solar_panel.X/mcc_generated_files/pin_manager.c b/solar_panel.X/mcc_generated_files/pin_manager.c index 0d327cb..4363a88 100644 --- a/solar_panel.X/mcc_generated_files/pin_manager.c +++ b/solar_panel.X/mcc_generated_files/pin_manager.c @@ -71,7 +71,7 @@ void PIN_MANAGER_Initialize(void) TRISG = 0xFF; TRISB = 0xFF; TRISH = 0xFF; - TRISC = 0xFB; + TRISC = 0xBB; TRISD = 0xFF; TRISJ = 0xFF; diff --git a/solar_panel.X/mcc_generated_files/pin_manager.h b/solar_panel.X/mcc_generated_files/pin_manager.h index 47c5454..16dddbc 100644 --- a/solar_panel.X/mcc_generated_files/pin_manager.h +++ b/solar_panel.X/mcc_generated_files/pin_manager.h @@ -75,6 +75,14 @@ #define RC2_SetDigitalInput() do { TRISCbits.TRISC2 = 1; } while(0) #define RC2_SetDigitalOutput() do { TRISCbits.TRISC2 = 0; } while(0) +// get/set RC6 procedures +#define RC6_SetHigh() do { LATCbits.LATC6 = 1; } while(0) +#define RC6_SetLow() do { LATCbits.LATC6 = 0; } while(0) +#define RC6_Toggle() do { LATCbits.LATC6 = ~LATCbits.LATC6; } while(0) +#define RC6_GetValue() PORTCbits.RC6 +#define RC6_SetDigitalInput() do { TRISCbits.TRISC6 = 1; } while(0) +#define RC6_SetDigitalOutput() do { TRISCbits.TRISC6 = 0; } while(0) + // get/set voltage aliases #define voltage_TRIS TRISFbits.TRISF0 #define voltage_LAT LATFbits.LATF0 diff --git a/solar_panel.X/mcc_generated_files/tmr0.c b/solar_panel.X/mcc_generated_files/tmr0.c index ad3ca68..d2d9627 100644 --- a/solar_panel.X/mcc_generated_files/tmr0.c +++ b/solar_panel.X/mcc_generated_files/tmr0.c @@ -71,11 +71,11 @@ void TMR0_Initialize(void) //Enable 16bit timer mode before assigning value to TMR0H T0CONbits.T08BIT = 0; - // TMR0H 255; - TMR0H = 0xFF; + // TMR0H 158; + TMR0H = 0x9E; - // TMR0L 252; - TMR0L = 0xFC; + // TMR0L 87; + TMR0L = 0x57; // Load TMR0 value to the 16-bit reload variable @@ -90,8 +90,8 @@ void TMR0_Initialize(void) // Set Default Interrupt Handler TMR0_SetInterruptHandler(TMR0_DefaultInterruptHandler); - // T0PS 1:2; T08BIT 16-bit; T0SE Increment_hi_lo; T0CS T0CKI; TMR0ON enabled; PSA not_assigned; - T0CON = 0xB8; + // T0PS 1:2; T08BIT 16-bit; T0SE Increment_hi_lo; T0CS FOSC/4; TMR0ON enabled; PSA not_assigned; + T0CON = 0x98; } void TMR0_StartTimer(void) diff --git a/solar_panel.X/modbus.c b/solar_panel.X/modbus.c index 604747c..c6c8523 100644 --- a/solar_panel.X/modbus.c +++ b/solar_panel.X/modbus.c @@ -1,6 +1,6 @@ #include "modbus.h" #include "crc.h" -//#include "uart.h" +#include "uart.h" #include #include #include @@ -37,9 +37,11 @@ void modbus_timer(void) } -uint8_t modbus_analyse_and_answer(void) -{ +uint8_t modbus_analyse_and_answer(void) { // TODO -> complete the modbus analyse and answer + rx_buf[0] = 0; + + //sprintf(tx_buf, "%i", modbusAddress, ); } @@ -63,5 +65,5 @@ void modbus_send(uint8_t length) void modbus_init(uint8_t address) { modbusAddress = address; - // TODO -> configute timer for modbus usage + // TODO -> confikre timer for modbus usage } \ No newline at end of file diff --git a/solar_panel.X/nbproject/Makefile-default.mk b/solar_panel.X/nbproject/Makefile-default.mk index 3315f44..b0689c8 100644 --- a/solar_panel.X/nbproject/Makefile-default.mk +++ b/solar_panel.X/nbproject/Makefile-default.mk @@ -57,17 +57,17 @@ OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE} DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE} # Source Files Quoted if spaced -SOURCEFILES_QUOTED_IF_SPACED=lcd/lcd.c mcc_generated_files/device_config.c mcc_generated_files/mcc.c mcc_generated_files/pin_manager.c mcc_generated_files/adc.c main.c crc.c measure.c modbus.c mcc_generated_files/epwm1.c mcc_generated_files/tmr2.c mcc_generated_files/eusart1.c mcc_generated_files/interrupt_manager.c mcc_generated_files/tmr0.c +SOURCEFILES_QUOTED_IF_SPACED=lcd/lcd.c mcc_generated_files/device_config.c mcc_generated_files/mcc.c mcc_generated_files/pin_manager.c mcc_generated_files/adc.c mcc_generated_files/epwm1.c mcc_generated_files/tmr2.c mcc_generated_files/eusart1.c mcc_generated_files/interrupt_manager.c mcc_generated_files/tmr0.c main.c crc.c measure.c modbus.c uart.c # Object Files Quoted if spaced -OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/lcd/lcd.p1 ${OBJECTDIR}/mcc_generated_files/device_config.p1 ${OBJECTDIR}/mcc_generated_files/mcc.p1 ${OBJECTDIR}/mcc_generated_files/pin_manager.p1 ${OBJECTDIR}/mcc_generated_files/adc.p1 ${OBJECTDIR}/main.p1 ${OBJECTDIR}/crc.p1 ${OBJECTDIR}/measure.p1 ${OBJECTDIR}/modbus.p1 ${OBJECTDIR}/mcc_generated_files/epwm1.p1 ${OBJECTDIR}/mcc_generated_files/tmr2.p1 ${OBJECTDIR}/mcc_generated_files/eusart1.p1 ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1 ${OBJECTDIR}/mcc_generated_files/tmr0.p1 -POSSIBLE_DEPFILES=${OBJECTDIR}/lcd/lcd.p1.d ${OBJECTDIR}/mcc_generated_files/device_config.p1.d ${OBJECTDIR}/mcc_generated_files/mcc.p1.d ${OBJECTDIR}/mcc_generated_files/pin_manager.p1.d ${OBJECTDIR}/mcc_generated_files/adc.p1.d ${OBJECTDIR}/main.p1.d ${OBJECTDIR}/crc.p1.d ${OBJECTDIR}/measure.p1.d ${OBJECTDIR}/modbus.p1.d ${OBJECTDIR}/mcc_generated_files/epwm1.p1.d ${OBJECTDIR}/mcc_generated_files/tmr2.p1.d ${OBJECTDIR}/mcc_generated_files/eusart1.p1.d ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1.d ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d +OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/lcd/lcd.p1 ${OBJECTDIR}/mcc_generated_files/device_config.p1 ${OBJECTDIR}/mcc_generated_files/mcc.p1 ${OBJECTDIR}/mcc_generated_files/pin_manager.p1 ${OBJECTDIR}/mcc_generated_files/adc.p1 ${OBJECTDIR}/mcc_generated_files/epwm1.p1 ${OBJECTDIR}/mcc_generated_files/tmr2.p1 ${OBJECTDIR}/mcc_generated_files/eusart1.p1 ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1 ${OBJECTDIR}/mcc_generated_files/tmr0.p1 ${OBJECTDIR}/main.p1 ${OBJECTDIR}/crc.p1 ${OBJECTDIR}/measure.p1 ${OBJECTDIR}/modbus.p1 ${OBJECTDIR}/uart.p1 +POSSIBLE_DEPFILES=${OBJECTDIR}/lcd/lcd.p1.d ${OBJECTDIR}/mcc_generated_files/device_config.p1.d ${OBJECTDIR}/mcc_generated_files/mcc.p1.d ${OBJECTDIR}/mcc_generated_files/pin_manager.p1.d ${OBJECTDIR}/mcc_generated_files/adc.p1.d ${OBJECTDIR}/mcc_generated_files/epwm1.p1.d ${OBJECTDIR}/mcc_generated_files/tmr2.p1.d ${OBJECTDIR}/mcc_generated_files/eusart1.p1.d ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1.d ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d ${OBJECTDIR}/main.p1.d ${OBJECTDIR}/crc.p1.d ${OBJECTDIR}/measure.p1.d ${OBJECTDIR}/modbus.p1.d ${OBJECTDIR}/uart.p1.d # Object Files -OBJECTFILES=${OBJECTDIR}/lcd/lcd.p1 ${OBJECTDIR}/mcc_generated_files/device_config.p1 ${OBJECTDIR}/mcc_generated_files/mcc.p1 ${OBJECTDIR}/mcc_generated_files/pin_manager.p1 ${OBJECTDIR}/mcc_generated_files/adc.p1 ${OBJECTDIR}/main.p1 ${OBJECTDIR}/crc.p1 ${OBJECTDIR}/measure.p1 ${OBJECTDIR}/modbus.p1 ${OBJECTDIR}/mcc_generated_files/epwm1.p1 ${OBJECTDIR}/mcc_generated_files/tmr2.p1 ${OBJECTDIR}/mcc_generated_files/eusart1.p1 ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1 ${OBJECTDIR}/mcc_generated_files/tmr0.p1 +OBJECTFILES=${OBJECTDIR}/lcd/lcd.p1 ${OBJECTDIR}/mcc_generated_files/device_config.p1 ${OBJECTDIR}/mcc_generated_files/mcc.p1 ${OBJECTDIR}/mcc_generated_files/pin_manager.p1 ${OBJECTDIR}/mcc_generated_files/adc.p1 ${OBJECTDIR}/mcc_generated_files/epwm1.p1 ${OBJECTDIR}/mcc_generated_files/tmr2.p1 ${OBJECTDIR}/mcc_generated_files/eusart1.p1 ${OBJECTDIR}/mcc_generated_files/interrupt_manager.p1 ${OBJECTDIR}/mcc_generated_files/tmr0.p1 ${OBJECTDIR}/main.p1 ${OBJECTDIR}/crc.p1 ${OBJECTDIR}/measure.p1 ${OBJECTDIR}/modbus.p1 ${OBJECTDIR}/uart.p1 # Source Files -SOURCEFILES=lcd/lcd.c mcc_generated_files/device_config.c mcc_generated_files/mcc.c mcc_generated_files/pin_manager.c mcc_generated_files/adc.c main.c crc.c measure.c modbus.c mcc_generated_files/epwm1.c mcc_generated_files/tmr2.c mcc_generated_files/eusart1.c mcc_generated_files/interrupt_manager.c mcc_generated_files/tmr0.c +SOURCEFILES=lcd/lcd.c mcc_generated_files/device_config.c mcc_generated_files/mcc.c mcc_generated_files/pin_manager.c mcc_generated_files/adc.c mcc_generated_files/epwm1.c mcc_generated_files/tmr2.c mcc_generated_files/eusart1.c mcc_generated_files/interrupt_manager.c mcc_generated_files/tmr0.c main.c crc.c measure.c modbus.c uart.c @@ -134,38 +134,6 @@ ${OBJECTDIR}/mcc_generated_files/adc.p1: mcc_generated_files/adc.c nbproject/Ma @-${MV} ${OBJECTDIR}/mcc_generated_files/adc.d ${OBJECTDIR}/mcc_generated_files/adc.p1.d @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/adc.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ -${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk - @${MKDIR} "${OBJECTDIR}" - @${RM} ${OBJECTDIR}/main.p1.d - @${RM} ${OBJECTDIR}/main.p1 - ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/main.p1 main.c - @-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d - @${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ - -${OBJECTDIR}/crc.p1: crc.c nbproject/Makefile-${CND_CONF}.mk - @${MKDIR} "${OBJECTDIR}" - @${RM} ${OBJECTDIR}/crc.p1.d - @${RM} ${OBJECTDIR}/crc.p1 - ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/crc.p1 crc.c - @-${MV} ${OBJECTDIR}/crc.d ${OBJECTDIR}/crc.p1.d - @${FIXDEPS} ${OBJECTDIR}/crc.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ - -${OBJECTDIR}/measure.p1: measure.c nbproject/Makefile-${CND_CONF}.mk - @${MKDIR} "${OBJECTDIR}" - @${RM} ${OBJECTDIR}/measure.p1.d - @${RM} ${OBJECTDIR}/measure.p1 - ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/measure.p1 measure.c - @-${MV} ${OBJECTDIR}/measure.d ${OBJECTDIR}/measure.p1.d - @${FIXDEPS} ${OBJECTDIR}/measure.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ - -${OBJECTDIR}/modbus.p1: modbus.c nbproject/Makefile-${CND_CONF}.mk - @${MKDIR} "${OBJECTDIR}" - @${RM} ${OBJECTDIR}/modbus.p1.d - @${RM} ${OBJECTDIR}/modbus.p1 - ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/modbus.p1 modbus.c - @-${MV} ${OBJECTDIR}/modbus.d ${OBJECTDIR}/modbus.p1.d - @${FIXDEPS} ${OBJECTDIR}/modbus.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ - ${OBJECTDIR}/mcc_generated_files/epwm1.p1: mcc_generated_files/epwm1.c nbproject/Makefile-${CND_CONF}.mk @${MKDIR} "${OBJECTDIR}/mcc_generated_files" @${RM} ${OBJECTDIR}/mcc_generated_files/epwm1.p1.d @@ -206,6 +174,46 @@ ${OBJECTDIR}/mcc_generated_files/tmr0.p1: mcc_generated_files/tmr0.c nbproject/ @-${MV} ${OBJECTDIR}/mcc_generated_files/tmr0.d ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ +${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}" + @${RM} ${OBJECTDIR}/main.p1.d + @${RM} ${OBJECTDIR}/main.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/main.p1 main.c + @-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d + @${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/crc.p1: crc.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}" + @${RM} ${OBJECTDIR}/crc.p1.d + @${RM} ${OBJECTDIR}/crc.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/crc.p1 crc.c + @-${MV} ${OBJECTDIR}/crc.d ${OBJECTDIR}/crc.p1.d + @${FIXDEPS} ${OBJECTDIR}/crc.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/measure.p1: measure.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}" + @${RM} ${OBJECTDIR}/measure.p1.d + @${RM} ${OBJECTDIR}/measure.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/measure.p1 measure.c + @-${MV} ${OBJECTDIR}/measure.d ${OBJECTDIR}/measure.p1.d + @${FIXDEPS} ${OBJECTDIR}/measure.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/modbus.p1: modbus.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}" + @${RM} ${OBJECTDIR}/modbus.p1.d + @${RM} ${OBJECTDIR}/modbus.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/modbus.p1 modbus.c + @-${MV} ${OBJECTDIR}/modbus.d ${OBJECTDIR}/modbus.p1.d + @${FIXDEPS} ${OBJECTDIR}/modbus.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/uart.p1: uart.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}" + @${RM} ${OBJECTDIR}/uart.p1.d + @${RM} ${OBJECTDIR}/uart.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -D__DEBUG=1 -mdebugger=snap -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/uart.p1 uart.c + @-${MV} ${OBJECTDIR}/uart.d ${OBJECTDIR}/uart.p1.d + @${FIXDEPS} ${OBJECTDIR}/uart.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + else ${OBJECTDIR}/lcd/lcd.p1: lcd/lcd.c nbproject/Makefile-${CND_CONF}.mk @${MKDIR} "${OBJECTDIR}/lcd" @@ -247,38 +255,6 @@ ${OBJECTDIR}/mcc_generated_files/adc.p1: mcc_generated_files/adc.c nbproject/Ma @-${MV} ${OBJECTDIR}/mcc_generated_files/adc.d ${OBJECTDIR}/mcc_generated_files/adc.p1.d @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/adc.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ -${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk - @${MKDIR} "${OBJECTDIR}" - @${RM} ${OBJECTDIR}/main.p1.d - @${RM} ${OBJECTDIR}/main.p1 - ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/main.p1 main.c - @-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d - @${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ - -${OBJECTDIR}/crc.p1: crc.c nbproject/Makefile-${CND_CONF}.mk - @${MKDIR} "${OBJECTDIR}" - @${RM} ${OBJECTDIR}/crc.p1.d - @${RM} ${OBJECTDIR}/crc.p1 - ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/crc.p1 crc.c - @-${MV} ${OBJECTDIR}/crc.d ${OBJECTDIR}/crc.p1.d - @${FIXDEPS} ${OBJECTDIR}/crc.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ - -${OBJECTDIR}/measure.p1: measure.c nbproject/Makefile-${CND_CONF}.mk - @${MKDIR} "${OBJECTDIR}" - @${RM} ${OBJECTDIR}/measure.p1.d - @${RM} ${OBJECTDIR}/measure.p1 - ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/measure.p1 measure.c - @-${MV} ${OBJECTDIR}/measure.d ${OBJECTDIR}/measure.p1.d - @${FIXDEPS} ${OBJECTDIR}/measure.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ - -${OBJECTDIR}/modbus.p1: modbus.c nbproject/Makefile-${CND_CONF}.mk - @${MKDIR} "${OBJECTDIR}" - @${RM} ${OBJECTDIR}/modbus.p1.d - @${RM} ${OBJECTDIR}/modbus.p1 - ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/modbus.p1 modbus.c - @-${MV} ${OBJECTDIR}/modbus.d ${OBJECTDIR}/modbus.p1.d - @${FIXDEPS} ${OBJECTDIR}/modbus.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ - ${OBJECTDIR}/mcc_generated_files/epwm1.p1: mcc_generated_files/epwm1.c nbproject/Makefile-${CND_CONF}.mk @${MKDIR} "${OBJECTDIR}/mcc_generated_files" @${RM} ${OBJECTDIR}/mcc_generated_files/epwm1.p1.d @@ -319,6 +295,46 @@ ${OBJECTDIR}/mcc_generated_files/tmr0.p1: mcc_generated_files/tmr0.c nbproject/ @-${MV} ${OBJECTDIR}/mcc_generated_files/tmr0.d ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d @${FIXDEPS} ${OBJECTDIR}/mcc_generated_files/tmr0.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ +${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}" + @${RM} ${OBJECTDIR}/main.p1.d + @${RM} ${OBJECTDIR}/main.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/main.p1 main.c + @-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d + @${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/crc.p1: crc.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}" + @${RM} ${OBJECTDIR}/crc.p1.d + @${RM} ${OBJECTDIR}/crc.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/crc.p1 crc.c + @-${MV} ${OBJECTDIR}/crc.d ${OBJECTDIR}/crc.p1.d + @${FIXDEPS} ${OBJECTDIR}/crc.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/measure.p1: measure.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}" + @${RM} ${OBJECTDIR}/measure.p1.d + @${RM} ${OBJECTDIR}/measure.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/measure.p1 measure.c + @-${MV} ${OBJECTDIR}/measure.d ${OBJECTDIR}/measure.p1.d + @${FIXDEPS} ${OBJECTDIR}/measure.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/modbus.p1: modbus.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}" + @${RM} ${OBJECTDIR}/modbus.p1.d + @${RM} ${OBJECTDIR}/modbus.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/modbus.p1 modbus.c + @-${MV} ${OBJECTDIR}/modbus.d ${OBJECTDIR}/modbus.p1.d + @${FIXDEPS} ${OBJECTDIR}/modbus.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + +${OBJECTDIR}/uart.p1: uart.c nbproject/Makefile-${CND_CONF}.mk + @${MKDIR} "${OBJECTDIR}" + @${RM} ${OBJECTDIR}/uart.p1.d + @${RM} ${OBJECTDIR}/uart.p1 + ${MP_CC} $(MP_EXTRA_CC_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -c -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=$(CND_CONF) -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits $(COMPARISON_BUILD) -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o ${OBJECTDIR}/uart.p1 uart.c + @-${MV} ${OBJECTDIR}/uart.d ${OBJECTDIR}/uart.p1.d + @${FIXDEPS} ${OBJECTDIR}/uart.p1.d $(SILENT) -rsi ${MP_CC_DIR}../ + endif # ------------------------------------------------------------------------------------ diff --git a/solar_panel.X/nbproject/Makefile-genesis.properties b/solar_panel.X/nbproject/Makefile-genesis.properties index da78265..7884d01 100644 --- a/solar_panel.X/nbproject/Makefile-genesis.properties +++ b/solar_panel.X/nbproject/Makefile-genesis.properties @@ -1,11 +1,11 @@ # -#Fri Mar 03 14:42:22 CET 2023 +#Fri Mar 03 16:00:47 CET 2023 default.languagetoolchain.version=2.40 default.Pack.dfplocation=C\:\\Program Files\\Microchip\\MPLABX\\v6.00\\packs\\Microchip\\PIC18F-J_DFP\\1.5.44 conf.ids=default default.languagetoolchain.dir=C\:\\Program Files\\Microchip\\xc8\\v2.40\\bin host.id=3awj-afwq-rl -configurations-xml=19a2811a74f6d1b3cc6f3802bb8369cf +configurations-xml=5e78976b44c48e5125d650f70012f653 default.com-microchip-mplab-mdbcore-snap-SnapToolImpl.md5=eaa336cefb7fc46db8b50b7b2b6e54ca com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=6e02ca5e9f5042ffd365b42ab82d3a9b user-defined-mime-resolver-xml=none diff --git a/solar_panel.X/nbproject/configurations.xml b/solar_panel.X/nbproject/configurations.xml index f432be8..f6809b7 100644 --- a/solar_panel.X/nbproject/configurations.xml +++ b/solar_panel.X/nbproject/configurations.xml @@ -23,6 +23,7 @@ crc.h measure.h modbus.h + uart.h crc.c measure.c modbus.c + uart.c + file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/modbus.c file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/measure.c - file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/measure.h + file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/modbus.h file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/main.c - file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/lcd/lcd.c - file:/C:/Program%20Files/Microchip/xc8/v2.40/pic/sources/c99/common/lomod.c + file:/C:/Program%20Files/Microchip/xc8/v2.40/pic/sources/c99/common/lwmod.c + file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/mcc_generated_files/interrupt_manager.c + file:/C:/Program%20Files/Microchip/xc8/v2.40/pic/sources/c99/common/aomod.c + file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/mcc_generated_files/tmr0.c + file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/mcc_generated_files/eusart1.c diff --git a/solar_panel.X/solar_panel.mc3 b/solar_panel.X/solar_panel.mc3 index c4cb3de..0787f8a 100644 --- a/solar_panel.X/solar_panel.mc3 +++ b/solar_panel.X/solar_panel.mc3 @@ -1004,7 +1004,7 @@ - 244 + 228 @@ -1112,7 +1112,7 @@ - synchronous + asynchronous @@ -4464,7 +4464,7 @@ - 251 + 187 @@ -4936,7 +4936,7 @@ - input + output @@ -5604,7 +5604,7 @@ - 0.00003 + 0.004 @@ -5616,11 +5616,11 @@ - 0.65535 + 0.0104856 - 0.00001 + 0.00000016 @@ -5632,15 +5632,15 @@ - 100000 + 6250000 - 0.000035 + 0.004 - enabled + disabled @@ -5724,15 +5724,15 @@ - 184 + 152 - 255 + 158 - 252 + 87 @@ -5752,7 +5752,7 @@ - T0CKI + FOSC/4 @@ -5760,11 +5760,11 @@ - 255 + 158 - 252 + 87 @@ -5982,7 +5982,7 @@ mcc_generated_files\eusart1.h - c6209c27bd9de6f3041c2f8d1df1cccce2b09bdf4b5098ae0b333a7f92205022 + cb7a354159e217ac3955f23cce6d01d65df54018be773e73654ec951df42a7e9 mcc_generated_files\tmr0.h @@ -6000,14 +6000,14 @@ mcc_generated_files\tmr2.h 9c49623fe191eb686818b525571464bbc0f83e271367728272f8bce53b917f55 - - mcc_generated_files\pin_manager.h - a29093f3260f4f5a4c9bb40015c68aed2bf30664c16fade6df5035f8d97e736e - mcc_generated_files\tmr2.c 05c23c08bae910023f51fd801fa4b4107358a34dbad1624e66d9a30249d1fe86 + + mcc_generated_files\pin_manager.h + 87e93cc6f9494828e660861178e9a299efbe16d73a441d92e3dca2a1cf6d54ed + mcc_generated_files\adc.h 58eb4471903133ed806f7edbfce9c3cc4e0af3536917c8f81ad1cbdb72d919fc @@ -6018,11 +6018,11 @@ mcc_generated_files\tmr0.c - 6ee4809b94f1e2488f05488f97e0cdc3e8db39b9f132a99c2d2daf3b13befbf7 + f8a9d57b93e4810bdf2401ef043ce48c9d645ba81f2241dee96977286f6fb164 mcc_generated_files\pin_manager.c - f23627897b323c5e312c50538e92449a15673b1b943138129b8c0214ac47a4d4 + 1f9236370706611180887eedcb54392c08476036ee99409ce0d9a1f39ef165fb mcc_generated_files\epwm1.c @@ -6042,7 +6042,7 @@ mcc_generated_files\eusart1.c - 627becf328c45a7c7ebff85e99496289e162e55eef7d703ea105fffd0439dd76 + d8ed730bd093892491a853d1821faa71f3a66365e71b5728f5d34612524be6ec \ No newline at end of file diff --git a/solar_panel.X/uart.c b/solar_panel.X/uart.c new file mode 100644 index 0000000..8d8717e --- /dev/null +++ b/solar_panel.X/uart.c @@ -0,0 +1,7 @@ +#include "uart.h" + +void uart_send(uint8_t *tx_buf, uint8_t length){ + for (uint8_t i = 0; i < length; i++){ + EUSART1_Write(tx_buf[i]); + } +} diff --git a/solar_panel.X/uart.h b/solar_panel.X/uart.h new file mode 100644 index 0000000..57db5f4 --- /dev/null +++ b/solar_panel.X/uart.h @@ -0,0 +1,18 @@ +/* + * File: uart.h + * Author: remi + * + * Created on March 3, 2023, 3:23 PM + */ + +#ifndef UART_H +#define UART_H + +#include "mcc_generated_files/mcc.h" + +void uart_send(uint8_t *tx_buf, uint8_t length); + + + +#endif /* UART_H */ + From a5315c03a703f7e54891990c01d5d59abd44138d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Thu, 9 Mar 2023 16:06:17 +0100 Subject: [PATCH 6/7] migration --- main.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 main.c diff --git a/main.c b/main.c new file mode 100644 index 0000000..de0ff6a --- /dev/null +++ b/main.c @@ -0,0 +1,120 @@ +/** + Generated Main Source File + + Company: + Microchip Technology Inc. + + File Name: + main.c + + Summary: + This is the main file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + Description: + This header file provides implementations for driver APIs for all modules selected in the GUI. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F97J60 + Driver Version : 2.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#include "mcc_generated_files/mcc.h" +#include "lcd/lcd.h" +#include "measure.h" +#include "modbus.h" + +#define MAX_COL 16 +/* + Main application + */ +void resetTMR0(void); +void endFrame(void); + +void main(void) +{ + // Initialize the device + SYSTEM_Initialize(); + EPWM1_LoadDutyValue(0); + + Lcd_Init(); + adc_init(); + modbus_init(0x80); + uint16_t offsetCurrent = 0; + offsetCurrent = measure_current(offsetCurrent); + + // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts + // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts + // Use the following macros to: + + // Enable the Global Interrupts + INTERRUPT_GlobalInterruptEnable(); + + // Disable the Global Interrupts + //INTERRUPT_GlobalInterruptDisable(); + + // Enable the Peripheral Interrupts + INTERRUPT_PeripheralInterruptEnable(); + + // Disable the Peripheral Interrupts + //INTERRUPT_PeripheralInterruptDisable(); + uint16_t foo = 512; + EUSART1_SetRxInterruptHandler(resetTMR0); + TMR0_SetInterruptHandler(endFrame); + while (1) + { + foo = ++foo%1023; + EPWM1_LoadDutyValue(foo); + uint16_t valueV = measure_voltage(); + uint16_t valueI = measure_current(offsetCurrent); + + char msg[MAX_COL+1]; + //LCD_2x16_WriteCmd(0x01); // clear display + + sprintf(msg, "U = %04d [mV] ", valueV); + LCD_2x16_WriteMsg(msg,0); + + sprintf(msg, "I = %04d [uA] ", valueI); + LCD_2x16_WriteMsg(msg,1); + + } +} + + +void resetTMR0(void){ + INTCONbits.TMR0IF = 0; + TMR0_Reload(); + TMR0_StartTimer(); +} + +void endFrame(void){ + TMR0_StopTimer(); + modbus_analyse_and_answer(); + + // TODO +} +/** + End of File +*/ \ No newline at end of file From 966ff2ae3a8199c78459d55bfcbf6ebabbd97d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Thu, 9 Mar 2023 16:08:27 +0100 Subject: [PATCH 7/7] migration --- .gitignore | 5 +- solar_panel.X/Makefile => Makefile | 0 solar_panel.X/crc.c => crc.c | 0 solar_panel.X/crc.h => crc.h | 0 .../arialRoundedMTBold18ptBitmaps.c | 0 {solar_panel.X/lcd => lcd}/ft5xx6.c | 0 {solar_panel.X/lcd => lcd}/ft5xx6.h | 0 {solar_panel.X/lcd => lcd}/lcd.c | 0 {solar_panel.X/lcd => lcd}/lcd.h | 0 {solar_panel.X/lcd => lcd}/ssd1963_cmd.h | 0 .../adc.c | 0 .../adc.h | 0 .../device_config.c | 0 .../device_config.h | 0 .../epwm1.c | 0 .../epwm1.h | 0 .../eusart1.c | 0 .../eusart1.h | 0 .../interrupt_manager.c | 0 .../interrupt_manager.h | 0 .../mcc.c | 0 .../mcc.h | 0 .../pin_manager.c | 0 .../pin_manager.h | 0 .../tmr0.c | 0 .../tmr0.h | 0 .../tmr2.c | 0 .../tmr2.h | 0 solar_panel.X/measure.c => measure.c | 0 solar_panel.X/measure.h => measure.h | 0 solar_panel.X/modbus.c => modbus.c | 0 solar_panel.X/modbus.h => modbus.h | 0 .../Makefile-default.mk | 16 +-- .../Makefile-genesis.properties | 4 +- .../nbproject => nbproject}/Makefile-impl.mk | 2 +- .../Makefile-local-default.mk | 0 nbproject/Makefile-variables.mk | 10 ++ .../configurations.xml | 0 .../private/configurations.xml | 0 .../private/private.xml | 0 .../nbproject => nbproject}/project.xml | 0 solar_panel.X/old_main.c => old_main.c | 0 solar_panel.X/main.c | 120 ------------------ solar_panel.X/nbproject/Makefile-variables.mk | 10 -- .../solar_panel.mc3 => solar_panel.mc3 | 0 solar_panel.X/uart.c => uart.c | 0 solar_panel.X/uart.h => uart.h | 0 47 files changed, 25 insertions(+), 142 deletions(-) rename solar_panel.X/Makefile => Makefile (100%) rename solar_panel.X/crc.c => crc.c (100%) rename solar_panel.X/crc.h => crc.h (100%) rename {solar_panel.X/lcd => lcd}/arialRoundedMTBold18ptBitmaps.c (100%) rename {solar_panel.X/lcd => lcd}/ft5xx6.c (100%) rename {solar_panel.X/lcd => lcd}/ft5xx6.h (100%) rename {solar_panel.X/lcd => lcd}/lcd.c (100%) rename {solar_panel.X/lcd => lcd}/lcd.h (100%) rename {solar_panel.X/lcd => lcd}/ssd1963_cmd.h (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/adc.c (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/adc.h (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/device_config.c (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/device_config.h (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/epwm1.c (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/epwm1.h (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/eusart1.c (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/eusart1.h (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/interrupt_manager.c (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/interrupt_manager.h (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/mcc.c (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/mcc.h (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/pin_manager.c (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/pin_manager.h (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/tmr0.c (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/tmr0.h (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/tmr2.c (100%) rename {solar_panel.X/mcc_generated_files => mcc_generated_files}/tmr2.h (100%) rename solar_panel.X/measure.c => measure.c (100%) rename solar_panel.X/measure.h => measure.h (100%) rename solar_panel.X/modbus.c => modbus.c (100%) rename solar_panel.X/modbus.h => modbus.h (100%) rename {solar_panel.X/nbproject => nbproject}/Makefile-default.mk (95%) rename {solar_panel.X/nbproject => nbproject}/Makefile-genesis.properties (86%) rename {solar_panel.X/nbproject => nbproject}/Makefile-impl.mk (98%) rename {solar_panel.X/nbproject => nbproject}/Makefile-local-default.mk (100%) create mode 100644 nbproject/Makefile-variables.mk rename {solar_panel.X/nbproject => nbproject}/configurations.xml (100%) rename {solar_panel.X/nbproject => nbproject}/private/configurations.xml (100%) rename {solar_panel.X/nbproject => nbproject}/private/private.xml (100%) rename {solar_panel.X/nbproject => nbproject}/project.xml (100%) rename solar_panel.X/old_main.c => old_main.c (100%) delete mode 100644 solar_panel.X/main.c delete mode 100644 solar_panel.X/nbproject/Makefile-variables.mk rename solar_panel.X/solar_panel.mc3 => solar_panel.mc3 (100%) rename solar_panel.X/uart.c => uart.c (100%) rename solar_panel.X/uart.h => uart.h (100%) diff --git a/.gitignore b/.gitignore index 4c111fb..013cac4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ solar_panel.X/build/ solar_panel.X/debug/ -solar_panel.X/dist/ \ No newline at end of file +solar_panel.X/dist/ +build/ +debug/ +dist/ \ No newline at end of file diff --git a/solar_panel.X/Makefile b/Makefile similarity index 100% rename from solar_panel.X/Makefile rename to Makefile diff --git a/solar_panel.X/crc.c b/crc.c similarity index 100% rename from solar_panel.X/crc.c rename to crc.c diff --git a/solar_panel.X/crc.h b/crc.h similarity index 100% rename from solar_panel.X/crc.h rename to crc.h diff --git a/solar_panel.X/lcd/arialRoundedMTBold18ptBitmaps.c b/lcd/arialRoundedMTBold18ptBitmaps.c similarity index 100% rename from solar_panel.X/lcd/arialRoundedMTBold18ptBitmaps.c rename to lcd/arialRoundedMTBold18ptBitmaps.c diff --git a/solar_panel.X/lcd/ft5xx6.c b/lcd/ft5xx6.c similarity index 100% rename from solar_panel.X/lcd/ft5xx6.c rename to lcd/ft5xx6.c diff --git a/solar_panel.X/lcd/ft5xx6.h b/lcd/ft5xx6.h similarity index 100% rename from solar_panel.X/lcd/ft5xx6.h rename to lcd/ft5xx6.h diff --git a/solar_panel.X/lcd/lcd.c b/lcd/lcd.c similarity index 100% rename from solar_panel.X/lcd/lcd.c rename to lcd/lcd.c diff --git a/solar_panel.X/lcd/lcd.h b/lcd/lcd.h similarity index 100% rename from solar_panel.X/lcd/lcd.h rename to lcd/lcd.h diff --git a/solar_panel.X/lcd/ssd1963_cmd.h b/lcd/ssd1963_cmd.h similarity index 100% rename from solar_panel.X/lcd/ssd1963_cmd.h rename to lcd/ssd1963_cmd.h diff --git a/solar_panel.X/mcc_generated_files/adc.c b/mcc_generated_files/adc.c similarity index 100% rename from solar_panel.X/mcc_generated_files/adc.c rename to mcc_generated_files/adc.c diff --git a/solar_panel.X/mcc_generated_files/adc.h b/mcc_generated_files/adc.h similarity index 100% rename from solar_panel.X/mcc_generated_files/adc.h rename to mcc_generated_files/adc.h diff --git a/solar_panel.X/mcc_generated_files/device_config.c b/mcc_generated_files/device_config.c similarity index 100% rename from solar_panel.X/mcc_generated_files/device_config.c rename to mcc_generated_files/device_config.c diff --git a/solar_panel.X/mcc_generated_files/device_config.h b/mcc_generated_files/device_config.h similarity index 100% rename from solar_panel.X/mcc_generated_files/device_config.h rename to mcc_generated_files/device_config.h diff --git a/solar_panel.X/mcc_generated_files/epwm1.c b/mcc_generated_files/epwm1.c similarity index 100% rename from solar_panel.X/mcc_generated_files/epwm1.c rename to mcc_generated_files/epwm1.c diff --git a/solar_panel.X/mcc_generated_files/epwm1.h b/mcc_generated_files/epwm1.h similarity index 100% rename from solar_panel.X/mcc_generated_files/epwm1.h rename to mcc_generated_files/epwm1.h diff --git a/solar_panel.X/mcc_generated_files/eusart1.c b/mcc_generated_files/eusart1.c similarity index 100% rename from solar_panel.X/mcc_generated_files/eusart1.c rename to mcc_generated_files/eusart1.c diff --git a/solar_panel.X/mcc_generated_files/eusart1.h b/mcc_generated_files/eusart1.h similarity index 100% rename from solar_panel.X/mcc_generated_files/eusart1.h rename to mcc_generated_files/eusart1.h diff --git a/solar_panel.X/mcc_generated_files/interrupt_manager.c b/mcc_generated_files/interrupt_manager.c similarity index 100% rename from solar_panel.X/mcc_generated_files/interrupt_manager.c rename to mcc_generated_files/interrupt_manager.c diff --git a/solar_panel.X/mcc_generated_files/interrupt_manager.h b/mcc_generated_files/interrupt_manager.h similarity index 100% rename from solar_panel.X/mcc_generated_files/interrupt_manager.h rename to mcc_generated_files/interrupt_manager.h diff --git a/solar_panel.X/mcc_generated_files/mcc.c b/mcc_generated_files/mcc.c similarity index 100% rename from solar_panel.X/mcc_generated_files/mcc.c rename to mcc_generated_files/mcc.c diff --git a/solar_panel.X/mcc_generated_files/mcc.h b/mcc_generated_files/mcc.h similarity index 100% rename from solar_panel.X/mcc_generated_files/mcc.h rename to mcc_generated_files/mcc.h diff --git a/solar_panel.X/mcc_generated_files/pin_manager.c b/mcc_generated_files/pin_manager.c similarity index 100% rename from solar_panel.X/mcc_generated_files/pin_manager.c rename to mcc_generated_files/pin_manager.c diff --git a/solar_panel.X/mcc_generated_files/pin_manager.h b/mcc_generated_files/pin_manager.h similarity index 100% rename from solar_panel.X/mcc_generated_files/pin_manager.h rename to mcc_generated_files/pin_manager.h diff --git a/solar_panel.X/mcc_generated_files/tmr0.c b/mcc_generated_files/tmr0.c similarity index 100% rename from solar_panel.X/mcc_generated_files/tmr0.c rename to mcc_generated_files/tmr0.c diff --git a/solar_panel.X/mcc_generated_files/tmr0.h b/mcc_generated_files/tmr0.h similarity index 100% rename from solar_panel.X/mcc_generated_files/tmr0.h rename to mcc_generated_files/tmr0.h diff --git a/solar_panel.X/mcc_generated_files/tmr2.c b/mcc_generated_files/tmr2.c similarity index 100% rename from solar_panel.X/mcc_generated_files/tmr2.c rename to mcc_generated_files/tmr2.c diff --git a/solar_panel.X/mcc_generated_files/tmr2.h b/mcc_generated_files/tmr2.h similarity index 100% rename from solar_panel.X/mcc_generated_files/tmr2.h rename to mcc_generated_files/tmr2.h diff --git a/solar_panel.X/measure.c b/measure.c similarity index 100% rename from solar_panel.X/measure.c rename to measure.c diff --git a/solar_panel.X/measure.h b/measure.h similarity index 100% rename from solar_panel.X/measure.h rename to measure.h diff --git a/solar_panel.X/modbus.c b/modbus.c similarity index 100% rename from solar_panel.X/modbus.c rename to modbus.c diff --git a/solar_panel.X/modbus.h b/modbus.h similarity index 100% rename from solar_panel.X/modbus.h rename to modbus.h diff --git a/solar_panel.X/nbproject/Makefile-default.mk b/nbproject/Makefile-default.mk similarity index 95% rename from solar_panel.X/nbproject/Makefile-default.mk rename to nbproject/Makefile-default.mk index b0689c8..c184ead 100644 --- a/solar_panel.X/nbproject/Makefile-default.mk +++ b/nbproject/Makefile-default.mk @@ -30,12 +30,12 @@ ifeq ($(TYPE_IMAGE), DEBUG_RUN) IMAGE_TYPE=debug OUTPUT_SUFFIX=elf DEBUGGABLE_SUFFIX=elf -FINAL_IMAGE=${DISTDIR}/solar_panel.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} +FINAL_IMAGE=${DISTDIR}/solar_panel.${IMAGE_TYPE}.${OUTPUT_SUFFIX} else IMAGE_TYPE=production OUTPUT_SUFFIX=hex DEBUGGABLE_SUFFIX=elf -FINAL_IMAGE=${DISTDIR}/solar_panel.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} +FINAL_IMAGE=${DISTDIR}/solar_panel.${IMAGE_TYPE}.${OUTPUT_SUFFIX} endif ifeq ($(COMPARE_BUILD), true) @@ -88,7 +88,7 @@ FIXDEPS=fixDeps ifneq ($(INFORMATION_MESSAGE), ) @echo $(INFORMATION_MESSAGE) endif - ${MAKE} -f nbproject/Makefile-default.mk ${DISTDIR}/solar_panel.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} + ${MAKE} -f nbproject/Makefile-default.mk ${DISTDIR}/solar_panel.${IMAGE_TYPE}.${OUTPUT_SUFFIX} MP_PROCESSOR_OPTION=18F97J60 # ------------------------------------------------------------------------------------ @@ -352,15 +352,15 @@ endif # ------------------------------------------------------------------------------------ # Rules for buildStep: link ifeq ($(TYPE_IMAGE), DEBUG_RUN) -${DISTDIR}/solar_panel.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk +${DISTDIR}/solar_panel.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk @${MKDIR} ${DISTDIR} - ${MP_CC} $(MP_EXTRA_LD_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -Wl,-Map=${DISTDIR}/solar_panel.X.${IMAGE_TYPE}.map -D__DEBUG=1 -mdebugger=snap -DXPRJ_default=$(CND_CONF) -Wl,--defsym=__MPLAB_BUILD=1 -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto $(COMPARISON_BUILD) -Wl,--memorysummary,${DISTDIR}/memoryfile.xml -o ${DISTDIR}/solar_panel.X.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED} - @${RM} ${DISTDIR}/solar_panel.X.${IMAGE_TYPE}.hex + ${MP_CC} $(MP_EXTRA_LD_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -Wl,-Map=${DISTDIR}/solar_panel.${IMAGE_TYPE}.map -D__DEBUG=1 -mdebugger=snap -DXPRJ_default=$(CND_CONF) -Wl,--defsym=__MPLAB_BUILD=1 -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto $(COMPARISON_BUILD) -Wl,--memorysummary,${DISTDIR}/memoryfile.xml -o ${DISTDIR}/solar_panel.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED} + @${RM} ${DISTDIR}/solar_panel.${IMAGE_TYPE}.hex else -${DISTDIR}/solar_panel.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk +${DISTDIR}/solar_panel.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk @${MKDIR} ${DISTDIR} - ${MP_CC} $(MP_EXTRA_LD_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -Wl,-Map=${DISTDIR}/solar_panel.X.${IMAGE_TYPE}.map -DXPRJ_default=$(CND_CONF) -Wl,--defsym=__MPLAB_BUILD=1 -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto $(COMPARISON_BUILD) -Wl,--memorysummary,${DISTDIR}/memoryfile.xml -o ${DISTDIR}/solar_panel.X.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED} + ${MP_CC} $(MP_EXTRA_LD_PRE) -mcpu=$(MP_PROCESSOR_OPTION) -Wl,-Map=${DISTDIR}/solar_panel.${IMAGE_TYPE}.map -DXPRJ_default=$(CND_CONF) -Wl,--defsym=__MPLAB_BUILD=1 -mdfp="${DFP_DIR}/xc8" -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto $(COMPARISON_BUILD) -Wl,--memorysummary,${DISTDIR}/memoryfile.xml -o ${DISTDIR}/solar_panel.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED} endif diff --git a/solar_panel.X/nbproject/Makefile-genesis.properties b/nbproject/Makefile-genesis.properties similarity index 86% rename from solar_panel.X/nbproject/Makefile-genesis.properties rename to nbproject/Makefile-genesis.properties index 7884d01..2dac5f0 100644 --- a/solar_panel.X/nbproject/Makefile-genesis.properties +++ b/nbproject/Makefile-genesis.properties @@ -1,5 +1,5 @@ # -#Fri Mar 03 16:00:47 CET 2023 +#Thu Mar 09 15:57:40 CET 2023 default.languagetoolchain.version=2.40 default.Pack.dfplocation=C\:\\Program Files\\Microchip\\MPLABX\\v6.00\\packs\\Microchip\\PIC18F-J_DFP\\1.5.44 conf.ids=default @@ -10,5 +10,5 @@ default.com-microchip-mplab-mdbcore-snap-SnapToolImpl.md5=eaa336cefb7fc46db8b50b com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=6e02ca5e9f5042ffd365b42ab82d3a9b user-defined-mime-resolver-xml=none default.com-microchip-mplab-nbide-toolchain-xc8-XC8LanguageToolchain.md5=ab1e0737b447a24f7366e9fd8fe5a2f0 -proj.dir=C\:\\Users\\remi\\Downloads\\MCU\\solar_panel\\solar_panel.X +proj.dir=C\:\\Users\\remi\\MPLABXProjects\\solar_panel host.platform=windows diff --git a/solar_panel.X/nbproject/Makefile-impl.mk b/nbproject/Makefile-impl.mk similarity index 98% rename from solar_panel.X/nbproject/Makefile-impl.mk rename to nbproject/Makefile-impl.mk index f72cccd..a5b9960 100644 --- a/solar_panel.X/nbproject/Makefile-impl.mk +++ b/nbproject/Makefile-impl.mk @@ -24,7 +24,7 @@ CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}} # Project Name -PROJECTNAME=solar_panel.X +PROJECTNAME=solar_panel # Active Configuration DEFAULTCONF=default diff --git a/solar_panel.X/nbproject/Makefile-local-default.mk b/nbproject/Makefile-local-default.mk similarity index 100% rename from solar_panel.X/nbproject/Makefile-local-default.mk rename to nbproject/Makefile-local-default.mk diff --git a/nbproject/Makefile-variables.mk b/nbproject/Makefile-variables.mk new file mode 100644 index 0000000..3b32a6c --- /dev/null +++ b/nbproject/Makefile-variables.mk @@ -0,0 +1,10 @@ +# +# Generated - do not edit! +# +# NOCDDL +# +CND_BASEDIR=`pwd` +# default configuration +CND_ARTIFACT_DIR_default=dist/default/production +CND_ARTIFACT_NAME_default=solar_panel.production.hex +CND_ARTIFACT_PATH_default=dist/default/production/solar_panel.production.hex diff --git a/solar_panel.X/nbproject/configurations.xml b/nbproject/configurations.xml similarity index 100% rename from solar_panel.X/nbproject/configurations.xml rename to nbproject/configurations.xml diff --git a/solar_panel.X/nbproject/private/configurations.xml b/nbproject/private/configurations.xml similarity index 100% rename from solar_panel.X/nbproject/private/configurations.xml rename to nbproject/private/configurations.xml diff --git a/solar_panel.X/nbproject/private/private.xml b/nbproject/private/private.xml similarity index 100% rename from solar_panel.X/nbproject/private/private.xml rename to nbproject/private/private.xml diff --git a/solar_panel.X/nbproject/project.xml b/nbproject/project.xml similarity index 100% rename from solar_panel.X/nbproject/project.xml rename to nbproject/project.xml diff --git a/solar_panel.X/old_main.c b/old_main.c similarity index 100% rename from solar_panel.X/old_main.c rename to old_main.c diff --git a/solar_panel.X/main.c b/solar_panel.X/main.c deleted file mode 100644 index de0ff6a..0000000 --- a/solar_panel.X/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** - Generated Main Source File - - Company: - Microchip Technology Inc. - - File Name: - main.c - - Summary: - This is the main file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs - - Description: - This header file provides implementations for driver APIs for all modules selected in the GUI. - Generation Information : - Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 - Device : PIC18F97J60 - Driver Version : 2.00 -*/ - -/* - (c) 2018 Microchip Technology Inc. and its subsidiaries. - - Subject to your compliance with these terms, you may use Microchip software and any - derivatives exclusively with Microchip products. It is your responsibility to comply with third party - license terms applicable to your use of third party software (including open source software) that - may accompany Microchip software. - - THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER - EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY - IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS - FOR A PARTICULAR PURPOSE. - - IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, - INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND - WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP - HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO - THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL - CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT - OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS - SOFTWARE. -*/ - -#include "mcc_generated_files/mcc.h" -#include "lcd/lcd.h" -#include "measure.h" -#include "modbus.h" - -#define MAX_COL 16 -/* - Main application - */ -void resetTMR0(void); -void endFrame(void); - -void main(void) -{ - // Initialize the device - SYSTEM_Initialize(); - EPWM1_LoadDutyValue(0); - - Lcd_Init(); - adc_init(); - modbus_init(0x80); - uint16_t offsetCurrent = 0; - offsetCurrent = measure_current(offsetCurrent); - - // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts - // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts - // Use the following macros to: - - // Enable the Global Interrupts - INTERRUPT_GlobalInterruptEnable(); - - // Disable the Global Interrupts - //INTERRUPT_GlobalInterruptDisable(); - - // Enable the Peripheral Interrupts - INTERRUPT_PeripheralInterruptEnable(); - - // Disable the Peripheral Interrupts - //INTERRUPT_PeripheralInterruptDisable(); - uint16_t foo = 512; - EUSART1_SetRxInterruptHandler(resetTMR0); - TMR0_SetInterruptHandler(endFrame); - while (1) - { - foo = ++foo%1023; - EPWM1_LoadDutyValue(foo); - uint16_t valueV = measure_voltage(); - uint16_t valueI = measure_current(offsetCurrent); - - char msg[MAX_COL+1]; - //LCD_2x16_WriteCmd(0x01); // clear display - - sprintf(msg, "U = %04d [mV] ", valueV); - LCD_2x16_WriteMsg(msg,0); - - sprintf(msg, "I = %04d [uA] ", valueI); - LCD_2x16_WriteMsg(msg,1); - - } -} - - -void resetTMR0(void){ - INTCONbits.TMR0IF = 0; - TMR0_Reload(); - TMR0_StartTimer(); -} - -void endFrame(void){ - TMR0_StopTimer(); - modbus_analyse_and_answer(); - - // TODO -} -/** - End of File -*/ \ No newline at end of file diff --git a/solar_panel.X/nbproject/Makefile-variables.mk b/solar_panel.X/nbproject/Makefile-variables.mk deleted file mode 100644 index dcae15c..0000000 --- a/solar_panel.X/nbproject/Makefile-variables.mk +++ /dev/null @@ -1,10 +0,0 @@ -# -# Generated - do not edit! -# -# NOCDDL -# -CND_BASEDIR=`pwd` -# default configuration -CND_ARTIFACT_DIR_default=dist/default/production -CND_ARTIFACT_NAME_default=solar_panel.X.production.hex -CND_ARTIFACT_PATH_default=dist/default/production/solar_panel.X.production.hex diff --git a/solar_panel.X/solar_panel.mc3 b/solar_panel.mc3 similarity index 100% rename from solar_panel.X/solar_panel.mc3 rename to solar_panel.mc3 diff --git a/solar_panel.X/uart.c b/uart.c similarity index 100% rename from solar_panel.X/uart.c rename to uart.c diff --git a/solar_panel.X/uart.h b/uart.h similarity index 100% rename from solar_panel.X/uart.h rename to uart.h