diff options
Diffstat (limited to 'SPI.c')
-rw-r--r-- | SPI.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -35,17 +35,19 @@ //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); + + if(Ohm_150>7)WriteBuffer[3] = 0x7f; + else WriteBuffer[3] = (0x7f >> (7-Ohm_150));// + ((Ohm_68 - 4)<<7); WriteBuffer[5] = 0xff >> (15-Ohm_150); + if(Ohm_68<5)WriteBuffer[1] = ((0xf0 >> (Ohm_68))&0x0f)| (testLED << 7); + else {WriteBuffer[1] = 0x0f | (testLED << 7); WriteBuffer[3] |= 0x80;} //WriteBuffer[1] = 0xFF; //if (Ohm_68 == 5) WriteBuffer[3]|= 0b10000000; SPI_slaveSelect(); readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer); SPI_slaveDeselect(); } - void active(uint8_t *ohm150, uint8_t *ohm68) + void active(uint8_t *activeResistors) { WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x40; WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x02; @@ -57,9 +59,11 @@ SPI_slaveSelect(); readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer); SPI_slaveDeselect(); - ohm150 = bitcount(ReadBuffer[3]&0x7F) + bitcount(ReadBuffer[5]); //+ bitcount(ReadBuffer[3] << 1)); + activeResistors[0] = bitcount(ReadBuffer[3]&0x7F) + bitcount(ReadBuffer[5]); //+ bitcount(ReadBuffer[3] << 1)); //ohm150 = bitcount(ReadBuffer[3]);// + ReadBuffer[5] + ReadBuffer[3] + ReadBuffer[1]; - ohm68 = ((ReadBuffer[3] & 0x80)>>7) + bitcount(ReadBuffer[0] & 0x0f); + activeResistors[1] = /*((ReadBuffer[3] & 0x80)>>7) +*/ bitcount(ReadBuffer[1] & 0x0f); + //activeResistors[0] = 0; + //activeResistors[0] = 3; } @@ -182,7 +186,7 @@ WriteBuffer[5] = outputs[2]; } -int bitcount(uint8_t n) +uint8_t bitcount(uint8_t n) { uint8_t count = 0; while (n > 0) |