summaryrefslogtreecommitdiff
path: root/SPI.c
diff options
context:
space:
mode:
authorJoshua Drake <Joshua.Ellis.Drake@gmail.com>2024-05-04 11:11:46 -0500
committerJoshua Drake <Joshua.Ellis.Drake@gmail.com>2024-05-04 11:11:46 -0500
commit3ee1a69c65589a744b67f770001022a884fe32ba (patch)
treeef53fc0b4d58ceee84a1e9d6b2956e6775cd5003 /SPI.c
parentdf6a4c2b5711ba7cda3cadd91d4b625c7a06da9d (diff)
Code is fully functional with delay timer at uC level.
Diffstat (limited to 'SPI.c')
-rw-r--r--SPI.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/SPI.c b/SPI.c
index a6590b4..96a18a8 100644
--- a/SPI.c
+++ b/SPI.c
@@ -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)