From be85c16280015d192128e85170f79eddd487e447 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Fri, 26 Apr 2024 16:41:10 -0500 Subject: Changes made during testing. --- SPI.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'SPI.c') diff --git a/SPI.c b/SPI.c index a526a42..1a1b8b6 100644 --- a/SPI.c +++ b/SPI.c @@ -32,26 +32,30 @@ if (Ohm_68 > 5) Ohm_68 = 5; //WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = (write << 8) | (!write << 7) | 0b000000; WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0b10000000; - WriteBuffer[5] = !(0xFF << Ohm_150); - WriteBuffer[3] = !(0xFF << (Ohm_150 - 8)) | ((Ohm_68 - 4) << 7); - WriteBuffer[1] = !(0xFF << (Ohm_68 - 1)) | (testLED << 7); + //WriteBuffer[1] = 0xFF >> (15-Ohm_150); + //WriteBuffer[3] = 0xFE << (7-(Ohm_150-8)) | (Ohm_68 - 4); + //2WriteBuffer[1] = 0x0F << (4-(Ohm_68 - 1)) | (testLED << 7); + WriteBuffer[1] = (0xf0 >> (Ohm_68 - 1)) | (testLED << 7); + if(Ohm_150>7)WriteBuffer[3] = 0x7f | ((Ohm_68 - 4)<<7); + else WriteBuffer[3] = (0x7f >> (7-Ohm_150)) | ((Ohm_68 - 4)<<7); + WriteBuffer[5] = 0xff >> (15-Ohm_150); //WriteBuffer[1] = 0xFF; //if (Ohm_68 == 5) WriteBuffer[3]|= 0b10000000; readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer); } - uint8_t active150() + int active150() { - WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0b01000000; - WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x00; + WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x40; + WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x02; readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer); - return (bitcount(ReadBuffer[5]) + bitcount(ReadBuffer[3] << 1)); + return bitcount(ReadBuffer[2]&0x7F) + (bitcount(ReadBuffer[4])); //+ bitcount(ReadBuffer[3] << 1)); } - uint8_t active68() + int active68() { - WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0b01000000; - WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x00; + WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x40; + WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x02; readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer); - return ((ReadBuffer[3] >> 7) + bitcount(ReadBuffer[1] << 1)); + return ((ReadBuffer[2] & 0x80) + bitcount(ReadBuffer[0] & 0x0f)); } void Message_BIM(uint8_t outputs[3]) @@ -176,7 +180,7 @@ WriteBuffer[5] = outputs[2]; } -uint8_t bitcount(uint8_t n) +int bitcount(uint8_t n) { uint8_t count = 0; while (n > 0) -- cgit v1.2.3