From a4055061108975b41e34602c29ed2185d8a654d1 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Thu, 25 Apr 2024 16:59:11 -0500 Subject: Commit Prior to testing. --- main.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 8625c42..c4efe2a 100644 --- a/main.c +++ b/main.c @@ -53,6 +53,11 @@ Main application */ uint8_t nullarray = {0x00, 0x00, 0x00}; +uint8_t desired150, desired68, current150, current68 = 0; +uint8_t relay_delay_counter = 0; + +void TMR1_Process(void); + int main(void) { // initialize the device @@ -70,21 +75,59 @@ int main(void) _LATB7 = 1; _LATB8 = 1; + TMR1_SetInterruptHandler(&TMR1_Process); + //MSSP2_I2C_ReadPointerSet(0b00000011); // MSSP2_I2C_WritePointerSet(0x00); while (1) { - - if (_LATB8) { + desired150 = getI2CArray(0x01) & 0b00001111; + desired68 = (getI2CArray(0x01) & 0b01110000) >> 4; + + if((relay_delay_counter % 2 == 0)&&(getTimeoutCounter() < 2)) + { + SPI_slaveSelect(); + current150 = active150(); + SPI_slaveDeselect(); + + SPI_slaveSelect(); + current68 = active68(); + SPI_slaveDeselect(); + + if(desired150 < current150) + { + SPI_slaveSelect(); + Message_OUT(current150-1, current68, 1); + SPI_slaveDeselect(); + } + else if(desired150 > current150) + { + SPI_slaveSelect(); + Message_OUT(current150+1, current68, 1); + SPI_slaveDeselect(); + } + else if(desired68 < current68) + { SPI_slaveSelect(); - Message_OUT(15, 5, 1); + Message_OUT(current150, current68-1, 1); SPI_slaveDeselect(); + } + else if(desired68 > current68) + { + SPI_slaveSelect(); + Message_OUT(current150, current68+1, 1); + SPI_slaveDeselect(); + } } - else { + + else { //Open contactors if I2C communication is broken. SPI_slaveSelect(); - Message_OUT(15, 5, 0); + Message_OUT(0, 0, 0); SPI_slaveDeselect(); + + _LATB8 = 0; + _LATB7 = 1; } /* SPI_slaveSelect(); @@ -110,6 +153,12 @@ int main(void) return 1; } + +void __attribute__ ((weak)) TMR1_Process(void) +{ + relay_delay_counter++; + incrementTimeoutCounter(); +} /** End of File */ -- cgit v1.2.3