From ed2644ef4e934f2f7cf93890760737790925a1c8 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Thu, 6 Jun 2024 16:23:43 -0500 Subject: Changed loss of connection behavior and cleaned up code. --- main.c | 79 ++++++++++++++++++++++-------------------------------------------- 1 file changed, 26 insertions(+), 53 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 11787fd..ca5aa4b 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,4 @@ /** - Generated main.c file from MPLAB Code Configurator - - @Company - Microchip Technology Inc. - @File Name main.c @@ -19,29 +14,6 @@ Compiler : XC16 v2.10 MPLAB : MPLAB X v6.05 */ - -/* - (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this - software and any derivatives exclusively with Microchip products. - - THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER - EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED - WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A - PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION - WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. - - IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, - INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND - WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS - BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE - FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN - ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, - THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. - - MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE - TERMS. -*/ - /** Section: Included Files */ @@ -83,36 +55,37 @@ int main(void) desired150 = getI2CArray(1) & 0x0F; desired68 = (getI2CArray(1) >> 4) & 0x07; - if((relay_delay)&&(*timeoutcounter < 2)) + if (relay_delay) { - _LATB8 = 1; - relay_delay = false; - active(activeResistors); - - if(desired150 < activeResistors[0]) - { - Message_OUT(activeResistors[0]-1, activeResistors[1], 1); - } - else if(desired150 > activeResistors[0]) - { - Message_OUT(activeResistors[0]+1, activeResistors[1], 1); - } - else if(desired68 < activeResistors[1]) + active(activeResistors); + if (*timeoutcounter < 2) { - Message_OUT(activeResistors[0], activeResistors[1]-1, 0); - } - else if(desired68 > activeResistors[1]) + _LATB8 = 1; + relay_delay = false; + + if (desired150 < activeResistors[0]) + { + Message_OUT(activeResistors[0] - 1, activeResistors[1], 1); + } else if (desired150 > activeResistors[0]) + { + Message_OUT(activeResistors[0] + 1, activeResistors[1], 1); + } else if (desired68 < activeResistors[1]) + { + Message_OUT(activeResistors[0], activeResistors[1] - 1, 0); + } else if (desired68 > activeResistors[1]) + { + Message_OUT(activeResistors[0], activeResistors[1] + 1, 0); + } + } + else //Open contactors if I2C communication is broken. { - Message_OUT(activeResistors[0], activeResistors[1]+1, 0); + if (relay_delay) Message_OUT(activeResistors[0] - 1, activeResistors[1] - 1, 0); + _LATB7 = 1; //Make sure activity light is off + _LATB8 = 0; + //Message_HWCROCL(); } } - - if(*timeoutcounter > 0x02) //Open contactors if I2C communication is broken. - { - Message_OUT(0, 0, 0); - _LATB7 = 1; //Make sure activity light is off - _LATB8 = 0; - } + //Message_OUT(15, 0, 1); //(desired150, desired68, relay_delay); //if(activeResistors[1]==3){_LATB8=0;} -- cgit v1.2.3