int main (void) { //############################################# Main program begin ############################################# unsigned char EqualFailuresCounter=0x00; // For checking if the failure is stable unsigned char BDPreviousSingleFailureByte=0xFF; // For recording the previous single failure byte unsigned char CCPreviousSingleFailureByte=0xFF; // For recording the previous single failure byte unsigned char BDStableFailureByte=0x00; // Stable failure is recorded when the single failure did not change 30 times unsigned char CCStableFailureByte=0x00; // Stable failure is recorded when the single failure did not change 30 times unsigned char BDPreviousStableFailureByte=0xFF; // For recording the previous stable failure byte unsigned char CCPreviousStableFailureByte=0xFF; // For recording the previous stable failure byte unsigned char BDHighestFailureByte=0x00; // The highest failure byte ever observed unsigned char CCHighestFailureByte=0x00; // The highest failure byte ever observed OutputsInputsConfiguration (); for(;;) { //############################ Endless loop begin ############################ TestPattern (); LEDsFailureSignalisation (); // Check if the single failure bytes changed since the last test pattern loop run if ((BDPreviousSingleFailureByte==BDSingleFailureByte)&(CCPreviousSingleFailureByte==CCSingleFailureByte)) {EqualFailuresCounter++;} // Increase the counter if the single failure bytes did not change else {EqualFailuresCounter=0;} // Reset the counter if the single failure bytes changed BDPreviousSingleFailureByte=BDSingleFailureByte; // Record the previous single failure byte for the next comparison CCPreviousSingleFailureByte=CCSingleFailureByte; // Record the previous single failure byte for the next comparison if (EqualFailuresCounter>30) // If the single failure did not change during the last 30 test pattern loop run... { EqualFailuresCounter=0; // Reset the counter BDStableFailureByte=BDSingleFailureByte; // Take over the failure as stable CCStableFailureByte=CCSingleFailureByte; // Take over the failure as stable } // Beep only once at a change of the stable failure, else too loud: if ((BDPreviousStableFailureByte!=BDStableFailureByte)|(CCPreviousStableFailureByte!=CCStableFailureByte)) { // Do not beep at the highest failure byte if ((BDStableFailureByteBDHighestFailureByte) // Find out the highest BDFailureByte ever seen {BDHighestFailureByte=BDStableFailureByte;} // Find out the highest BDFailureByte ever seen if (CCStableFailureByte>CCHighestFailureByte) // Find out the highest CCFailureByte ever seen {CCHighestFailureByte=CCStableFailureByte;} // Find out the highest CCFailureByte ever seen PORTB=BDHighestFailureByte; // For debugging _delay_ms(100); PORTB=0x00; _delay_ms(100); PORTB=BDHighestFailureByte; _delay_ms(100); PORTB=0x00; _delay_ms(100); PORTB=BDHighestFailureByte; _delay_ms(100); PORTB=0x00; _delay_ms(100); } //############################ Endless loop end ############################ } //############################################# Main program end #############################################