vencinachev

Logic gates Tester

Jan 13th, 2026
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. const int A_PIN = 13;  // вход A към чипа
  2. const int B_PIN = 12;  // вход B към чипа
  3. const int C_PIN = 11;  // вход A към чипа
  4. const int D_PIN = 10;  // вход B към чипа
  5. const int Y_PIN = 9;  // изход от чипа към Arduino
  6. const int LED_OK = 2;
  7. const int LED_NOK = 3;
  8.  
  9. struct Vec {
  10.   uint8_t a;
  11.   uint8_t b;
  12.   uint8_t c;
  13.   uint8_t d;
  14.   uint8_t expected;
  15. };
  16.  
  17. Vec tests[] = {
  18.   {0, 0, 0, 0, 0},
  19.   {0, 0, 0, 1, 0},
  20.   {0, 0, 1, 0, 0},
  21.   {0, 0, 1, 1, 0},
  22.   {0, 1, 0, 0, 0},
  23.   {0, 1, 0, 1, 0},
  24.   {0, 1, 1, 0, 0},
  25.   {0, 1, 1, 1, 0},
  26.   {1, 0, 0, 0, 0},
  27.   {1, 0, 0, 1, 0},
  28.   {1, 0, 1, 0, 0},
  29.   {1, 0, 1, 1, 0},
  30.   {1, 1, 0, 0, 0},
  31.   {1, 1, 0, 1, 1},
  32.   {1, 1, 1, 0, 1},
  33.   {1, 1, 1, 1, 1},
  34. };
  35.  
  36. void setup() {
  37.   Serial.begin(115200);
  38.  
  39.   pinMode(A_PIN, OUTPUT);
  40.   pinMode(B_PIN, OUTPUT);
  41.   pinMode(C_PIN, OUTPUT);
  42.   pinMode(D_PIN, OUTPUT);
  43.   pinMode(Y_PIN, INPUT);
  44.   pinMode(LED_OK, OUTPUT);
  45.   pinMode(LED_NOK, OUTPUT);
  46.   Serial.println("74HC AND tester start");
  47.   bool pass = true;
  48.  
  49.   for (int i = 0; i < 16; i++) {
  50.     digitalWrite(A_PIN, tests[i].a);
  51.     digitalWrite(B_PIN, tests[i].b);
  52.     digitalWrite(C_PIN, tests[i].c);
  53.     digitalWrite(D_PIN, tests[i].d);
  54.     delayMicroseconds(10); // време за установяване
  55.  
  56.     int y = digitalRead(Y_PIN);
  57.  
  58.     if (y != tests[i].expected) {
  59.       pass = false;
  60.       Serial.print("FAIL: A=");
  61.       Serial.print(tests[i].a);
  62.       Serial.print(" B=");
  63.       Serial.print(tests[i].b);
  64.       Serial.print(" C=");
  65.       Serial.print(tests[i].c);
  66.       Serial.print(" D=");
  67.       Serial.print(tests[i].d);
  68.       Serial.print(" -> Y=");
  69.       Serial.print(y);
  70.       Serial.print(" expected ");
  71.       Serial.println(tests[i].expected);
  72.     }
  73.   }
  74.  
  75.   if (pass){
  76.     Serial.println("PASS: gate OK");
  77.     digitalWrite(LED_OK, HIGH);
  78.   } else {
  79.     Serial.println("Fail: NOK");
  80.     digitalWrite(LED_NOK, HIGH);
  81.   }
  82. }
  83.  
  84. void loop() {
  85. }
Advertisement
Add Comment
Please, Sign In to add comment