ajit_nayak87
Member level 5
Dear all
I am looking for simple algorithm input.i cant post whole code. i pasted some part of it
i am using PISO to get input from 74hc165D ic. here i am trying to read data from DIP switch. Fault_Array[0] uses to read 8 position DIP switches
Now i am trying to read above input and identifying which is latest input. IN this code assume i have 4 input F1,F2,F3,F4 where F4 is latest f3 is 3rd and f1 is first. as per below code F4 will be flashing and remaining F1,F2,F3,will be steady. i m expecting First input F1 flash first later should be steady
similarly if order F2 is first, F3,f1,F4 i/p F2 is first i/p it should be flashing and remaining should be steady.
here i am checking which input is latest input.
using this i am trying to flash output
I am looking for simple algorithm input.i cant post whole code. i pasted some part of it
i am using PISO to get input from 74hc165D ic. here i am trying to read data from DIP switch. Fault_Array[0] uses to read 8 position DIP switches
Code:
void PISO_INPUT(void) {
unsigned char i;
unsigned char j, k;
unsigned char value;
byteValue = 0; // accumulates image of 8 switches
bitValue = 0;
PISO_PL_EN = 0; // latch data
PISO_PL_EN = 1; //ADD
for (i = 0; i < Chk_Fault_Counter; i++) { //TBC // 8 bits
bitValue = PISO_FAULT;
byteValue |= (bitValue << ((Chk_Fault_Counter - 1) - i));
PISO_CLK = 1;
PISO_CLK = 0;
}
FAULT_PISO = byteValue;
Fault_Array[0] = (unsigned char)(FAULT_PISO & 0xff);
}
similarly if order F2 is first, F3,f1,F4 i/p F2 is first i/p it should be flashing and remaining should be steady.
here i am checking which input is latest input.
Code:
void CHK_WINDOW() {
for (w = 0; w <= 8; w++) {
switch (w) {
case 1:
if (((Fault_Array[0] & 0x01) == 0x01) != intype.INF25) {
Debounce25++;
if (Debounce25 >9) {
if (((Fault_Array[0] & 0x01) == 0x01) != intype.INF25) {
if ((WINDOW[0] & 0x01) == 0x00) {
WINDOW[0] |= 0x01;
PREVIOUS_FLT1 = PREVIOUS_FLT;
PREVIOUS_FLT = LATEST_FLT;
LATEST_FLT = 0x19;
Debounce25 = 0;
}
}
}
} else
Debounce25 = 0;
break;
case 2:
if (((Fault_Array[0] & 0x02) == 0x02) != intype.INF26) {
Debounce26++;
if (Debounce26 >9) {
if (((Fault_Array[0] & 0x02) == 0x02) != intype.INF26) {
if ((WINDOW[0] & 0x02) == 0x00) {
WINDOW[0] |= 0x02;
PREVIOUS_FLT1 = PREVIOUS_FLT;
PREVIOUS_FLT = LATEST_FLT;
LATEST_FLT = 0x1A;
Debounce26 = 0;
}
}
}
} else
Debounce26 = 0;
break;
case 3:
if (((Fault_Array[0] & 0x04) == 0x04) != intype.INF27) {
Debounce27++;
if (Debounce27 >9) {
if (((Fault_Array[0] & 0x04) == 0x04) != intype.INF27) {
if ((WINDOW[0] & 0x04) == 0x00) {
WINDOW[0] |= 0x04;
PREVIOUS_FLT1 = PREVIOUS_FLT;
PREVIOUS_FLT = LATEST_FLT;
LATEST_FLT = 0x1B;
Debounce27 = 0;
}
}
}
} else
Debounce27 = 0;
break;
case 4:
if (((Fault_Array[0] & 0x08) == 0x08) != intype.INF28) {
Debounce28++;
if (Debounce28 >9) {
if (((Fault_Array[0] & 0x08) == 0x08) != intype.INF28) {
if ((WINDOW[0] & 0x08) == 0x00) {
WINDOW[0] |= 0x08;
PREVIOUS_FLT1 = PREVIOUS_FLT;
PREVIOUS_FLT = LATEST_FLT;
LATEST_FLT = 0x1C;
Debounce28 = 0;
}
}
}
} else
Debounce28 = 0;
break;
default:
break;
}
}
}
Code:
void FLASH_LED(void) {
unsigned char Z;
for (Z = 0; Z <= 8; Z++)
switch (Z) {
case 1:
if (((ACKPRESS[0] & 0x01) == 0x00) && ((WINDOW[0] & 0x01) == 0x01)) {
if (LATEST_FLT == 0X19)
{
if (bits.BLINKFLAG1 == 0)
WINDOW_PATTERN &= 0x7FFFFFFF;
else if (bits.BLINKFLAG1 == 1)
WINDOW_PATTERN |= 0x80000000;
} else if (PREVIOUS_FLT == 0X19) {
if (bits.BLINKFLAG2 == 0)
WINDOW_PATTERN &= 0x7FFFFFFF;
else if (bits.BLINKFLAG2 == 1)
WINDOW_PATTERN |= 0x80000000;
} else if (PREVIOUS_FLT1 == 0X19) {
WINDOW_PATTERN &= 0x7FFFFFFF;
F25_Flag = 1;
} else if (F25_Flag == 1)
WINDOW_PATTERN &= 0x7FFFFFFF;
else if ((WINDOW[0] & 0x01) == 0x01) {
WINDOW_PATTERN &= 0x7FFFFFFF;
}
}
break;
case 2:
if (((ACKPRESS[0] & 0x02) == 0x00) && ((WINDOW[0] & 0x02) == 0x02)) {
if (LATEST_FLT == 0X1A)
{
if (bits.BLINKFLAG1 == 0)
WINDOW_PATTERN &= 0xBFFFFFFF;
else if (bits.BLINKFLAG1 == 1)
WINDOW_PATTERN |= 0x40000000;
} else if (PREVIOUS_FLT == 0X1A) {
if (bits.BLINKFLAG2 == 0)
WINDOW_PATTERN &= 0xBFFFFFFF;
else if (bits.BLINKFLAG2 == 1)
WINDOW_PATTERN |= 0x40000000;
} else if (PREVIOUS_FLT1 == 0X1A) {
WINDOW_PATTERN &= 0xBFFFFFFF;
F26_Flag = 1;
} else if (F26_Flag == 1)
WINDOW_PATTERN &= 0xBFFFFFFF;
}
break;
case 3:
if (((ACKPRESS[0] & 0x04) == 0x00) && ((WINDOW[0] & 0x04) == 0x04)) {
if (LATEST_FLT == 0X1B)
{
if (bits.BLINKFLAG1 == 0)
WINDOW_PATTERN &= 0xDFFFFFFF;
else if (bits.BLINKFLAG1 == 1)
WINDOW_PATTERN |= 0x20000000;
} else if (PREVIOUS_FLT == 0X1B) {
if (bits.BLINKFLAG2 == 0)
WINDOW_PATTERN &= 0xDFFFFFFF;
else if (bits.BLINKFLAG2 == 1)
WINDOW_PATTERN |= 0x20000000;
} else if (PREVIOUS_FLT1 == 0X1B) {
WINDOW_PATTERN &= 0xDFFFFFFF;
F27_Flag = 1;
} else if (F27_Flag == 1)
WINDOW_PATTERN &= 0xDFFFFFFF;
else if ((WINDOW[0] & 0x04) == 0x04) {
WINDOW_PATTERN &= 0xDFFFFFFF;
}
}
break;
case 4:
if (((ACKPRESS[0] & 0x08) == 0x00) && ((WINDOW[0] & 0x08) == 0x08)) {
if (LATEST_FLT == 0X1C)
{
if (bits.BLINKFLAG1 == 0)
WINDOW_PATTERN &= 0xEFFFFFFF;
else if (bits.BLINKFLAG1 == 1)
WINDOW_PATTERN |= 0X10000000;
} else if (PREVIOUS_FLT == 0X1C) {
if (bits.BLINKFLAG2 == 0)
WINDOW_PATTERN &= 0xEFFFFFFF;
else if (bits.BLINKFLAG2 == 1)
WINDOW_PATTERN |= 0X10000000;
} else if (PREVIOUS_FLT1 == 0X1C) {
WINDOW_PATTERN &= 0xEFFFFFFF;
F28_Flag = 1;
} else if (F28_Flag == 1)
WINDOW_PATTERN &= 0xEFFFFFFF;
else if ((WINDOW[0] & 0x08) == 0x08) {
WINDOW_PATTERN &= 0xEFFFFFFF;
}
}
default:
break;
}
}