void IOTest(void) { int p; PMD1bits.AD1MD = 1; PMD3bits.AD2MD = 1; // Set as inputs for (p=0; p<NUM_PINS_IN_GROUP_1+NUM_PINS_IN_GROUP_2; p++) { setPinState(p, INPUT); } delay(1000); // Test that we're all pulled high for (p=0; p<NUM_PINS_IN_GROUP_1+NUM_PINS_IN_GROUP_2; p++) { if (getPinValue(p) == 0) failPin(p, 1); } int testPin; for (testPin=0; testPin<NUM_PINS_IN_GROUP_1; testPin++) { // Set testPin in group 1 to output low setPinState(PIN_IN_GROUP(1,testPin), OUTPUT); setPinValue(PIN_IN_GROUP(1,testPin), 0); delay(1000); // Test that group 1 is low, and 2 is high for (p=0; p<NUM_PINS_IN_GROUP_1; p++) { if (p == testPin) continue; if (getPinValue(PIN_IN_GROUP(1,p)) == 1) failPin(PIN_IN_GROUP(1,p), 2); } for (p=0; p<NUM_PINS_IN_GROUP_2; p++) { if (getPinValue(PIN_IN_GROUP(2,p)) == 0) failPin(PIN_IN_GROUP(2,p), 3); } setPinState(PIN_IN_GROUP(1,testPin), INPUT); } for (testPin=0; testPin<NUM_PINS_IN_GROUP_2; testPin++) { // Set testPin in group 2 to output low setPinState(PIN_IN_GROUP(2,testPin), OUTPUT); setPinValue(PIN_IN_GROUP(2,testPin), 0); delay(1000); // Test that group 1 is high, and 2 is low for (p=0; p<NUM_PINS_IN_GROUP_1; p++) { if (getPinValue(PIN_IN_GROUP(1,p)) == 0) failPin(PIN_IN_GROUP(1,p), 4); } for (p=0; p<NUM_PINS_IN_GROUP_2; p++) { if (p == testPin) continue; if (getPinValue(PIN_IN_GROUP(2,p)) == 1) failPin(PIN_IN_GROUP(2,p), 5); } setPinState(PIN_IN_GROUP(2,testPin), INPUT); } PMD1bits.AD1MD = 0; PMD3bits.AD2MD = 0; }
void IOTest(void) { int g; PMD1bits.AD1MD = 1; PMD3bits.AD2MD = 1; for (g=0; g<=10; g++) { // Set as inputs setPinState(PIN_IN_GROUP(g,0), INPUT); setPinState(PIN_IN_GROUP(g,1), INPUT); setPinState(PIN_IN_GROUP(g,2), INPUT); setPinState(PIN_IN_GROUP(g,3), INPUT); if (g == 10) setPinState(PIN_IN_GROUP(g,4), INPUT); delay(1000); // Fail if low if (getPinValue(PIN_IN_GROUP(g,0)) == 0) failPin(PIN_IN_GROUP(g,0), 0); if (getPinValue(PIN_IN_GROUP(g,1)) == 0) failPin(PIN_IN_GROUP(g,1), 0); if (getPinValue(PIN_IN_GROUP(g,2)) == 0) failPin(PIN_IN_GROUP(g,2), 0); if (getPinValue(PIN_IN_GROUP(g,3)) == 0) failPin(PIN_IN_GROUP(g,3), 0); if (g == 10 && getPinValue(PIN_IN_GROUP(g,4)) == 0) failPin(PIN_IN_GROUP(g,4), 0); // Set pin A as output low setPinState(PIN_IN_GROUP(g,0), OUTPUT); setPinValue(PIN_IN_GROUP(g,0), 0); delay(1000); // Fail if C is high or if B or D is low if (getPinValue(PIN_IN_GROUP(g,1)) == 0) failPin(PIN_IN_GROUP(g,1), 1); if (getPinValue(PIN_IN_GROUP(g,2)) == 1) failPin(PIN_IN_GROUP(g,2), 1); if (getPinValue(PIN_IN_GROUP(g,3)) == 0) failPin(PIN_IN_GROUP(g,3), 1); if (g == 10 && getPinValue(PIN_IN_GROUP(g,4)) == 1) failPin(PIN_IN_GROUP(g,4), 1); // Set pin B as output low setPinState(PIN_IN_GROUP(g,0), INPUT); setPinState(PIN_IN_GROUP(g,1), OUTPUT); setPinValue (PIN_IN_GROUP(g,1), 0); delay(1000); // Fail if D is high or if A or C is low if (getPinValue(PIN_IN_GROUP(g,0)) == 0) failPin(PIN_IN_GROUP(g,0), 2); if (getPinValue(PIN_IN_GROUP(g,2)) == 0) failPin(PIN_IN_GROUP(g,2), 2); if (getPinValue(PIN_IN_GROUP(g,3)) == 1) failPin(PIN_IN_GROUP(g,3), 2); if (g == 10 && getPinValue(PIN_IN_GROUP(g,4)) == 0) failPin(PIN_IN_GROUP(g,4), 2); // Set pin C as output low setPinState(PIN_IN_GROUP(g,1), INPUT); setPinState(PIN_IN_GROUP(g,2), OUTPUT); setPinValue (PIN_IN_GROUP(g,2), 0); delay(1000); // Fail if A is high or if B or D is low if (getPinValue(PIN_IN_GROUP(g,0)) == 1) failPin(PIN_IN_GROUP(g,0), 3); if (getPinValue(PIN_IN_GROUP(g,1)) == 0) failPin(PIN_IN_GROUP(g,1), 3); if (getPinValue(PIN_IN_GROUP(g,3)) == 0) failPin(PIN_IN_GROUP(g,3), 3); if (g == 10 && getPinValue(PIN_IN_GROUP(g,4)) == 1) failPin(PIN_IN_GROUP(g,4), 3); // Set pin D as output low setPinState(PIN_IN_GROUP(g,2), INPUT); setPinState(PIN_IN_GROUP(g,3), OUTPUT); setPinValue (PIN_IN_GROUP(g,3), 0); delay(1000); // Fail if B is high or if A or C is low if (getPinValue(PIN_IN_GROUP(g,0)) == 0) failPin(PIN_IN_GROUP(g,0), 4); if (getPinValue(PIN_IN_GROUP(g,1)) == 1) failPin(PIN_IN_GROUP(g,1), 4); if (getPinValue(PIN_IN_GROUP(g,2)) == 0) failPin(PIN_IN_GROUP(g,2), 4); if (g == 10 && getPinValue(PIN_IN_GROUP(g,4)) == 0) failPin(PIN_IN_GROUP(g,4), 4); setPinState(PIN_IN_GROUP(g,3), INPUT); // Test the bonus G10P1 pin if (g == 10) { // Set the bonus G10P1 pin as output low setPinState(PIN_IN_GROUP(g,4), OUTPUT); setPinValue (PIN_IN_GROUP(g,4), 0); delay(1000); // Fail if A or C is high or if B or D is low if (getPinValue(PIN_IN_GROUP(g,0)) == 1) failPin(PIN_IN_GROUP(g,0), 4); if (getPinValue(PIN_IN_GROUP(g,1)) == 0) failPin(PIN_IN_GROUP(g,1), 4); if (getPinValue(PIN_IN_GROUP(g,2)) == 1) failPin(PIN_IN_GROUP(g,2), 4); if (getPinValue(PIN_IN_GROUP(g,3)) == 0) failPin(PIN_IN_GROUP(g,3), 4); setPinState(PIN_IN_GROUP(g,4), INPUT); } } PMD1bits.AD1MD = 0; PMD3bits.AD2MD = 0; }