SHARE
TWEET

K617

a guest Mar 19th, 2016 215 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                    // GPIB Pin
  2.                    //     Description
  3. #define EOI  A5    // 05  End-or-Identify
  4. #define DAV  A4    // 06  Data Valid
  5. #define NRFD A3    // 07  Not ready for data
  6. #define NDAC 12    // 08  Not data accepted
  7. #define IFC  11    // 09  Interface clear
  8. #define SRQ  A2    // 10  Service request
  9. #define ATN  A1     // 11  Attention
  10. #define REN  10     // 17  Remote enable
  11.  
  12. #define DIO1 2     // 01  Data IO 1 LSB
  13. #define DIO2 3     // 02  Data IO 2
  14. #define DIO3 4     // 03  Data IO 3
  15. #define DIO4 5     // 04  Data IO 4
  16. #define DIO5 6     // 13  Data IO 5
  17. #define DIO6 7     // 14  Data IO 6
  18. #define DIO7 8     // 15  Data IO 7
  19. #define DIO8 9     // 16  Data IO 8 MSB
  20.  
  21. #define TIMEOUT 300000
  22.  
  23. void setup()
  24. {
  25.     Serial.begin(9600);
  26.  
  27.     pinMode(ATN, OUTPUT);
  28.     digitalWrite(ATN, HIGH);
  29. }
  30.  
  31. // Main program loop
  32. void loop()
  33. {
  34.     Serial.print(readByte());
  35. }
  36.  
  37. char readByte()
  38. {
  39.     pinMode(NRFD, OUTPUT);
  40.     pinMode(NDAC, OUTPUT);
  41.  
  42.     digitalWrite(NRFD, HIGH);
  43.     digitalWrite(NDAC, LOW);
  44.  
  45.     waitUntil(DAV, LOW);
  46.     digitalWrite(NRFD, LOW);
  47.  
  48.     char data = getData();
  49.  
  50.     digitalWrite(NDAC, HIGH);
  51.  
  52.     waitUntil(DAV, HIGH);
  53.     digitalWrite(NDAC, LOW);
  54.  
  55.     return data;
  56. }
  57.  
  58. bool waitUntil(int port, int status)
  59. {
  60.     unsigned long t = millis();
  61.     while (digitalRead(port) != status)
  62.     {
  63.         if (millis() - t > TIMEOUT)
  64.         {
  65.             errorTimeout(port, status);
  66.             return false;
  67.         }
  68.     }
  69.     return true;
  70. }
  71.  
  72. void errorTimeout(int port, int status)
  73. {
  74.     Serial.print("Error timeout: ");
  75.     Serial.print(port);
  76.     Serial.print(" ");
  77.     Serial.println(status);
  78.     Serial.println("Restart microcontroller");
  79.  
  80.     while (true) {}
  81. }
  82.  
  83. char getData()
  84. {
  85.     pinMode(DIO1, INPUT);
  86.     pinMode(DIO2, INPUT);
  87.     pinMode(DIO3, INPUT);
  88.     pinMode(DIO4, INPUT);
  89.     pinMode(DIO5, INPUT);
  90.     pinMode(DIO6, INPUT);
  91.     pinMode(DIO7, INPUT);
  92.     pinMode(DIO8, INPUT);
  93.  
  94.     char dataA = 0;
  95.     char dataB = 0;
  96.  
  97.     dataB = bitWrite(dataA, 0, digitalRead(DIO1));
  98.     dataA = bitWrite(dataB, 1, digitalRead(DIO2));
  99.     dataB = bitWrite(dataA, 2, digitalRead(DIO3));
  100.     dataA = bitWrite(dataB, 3, digitalRead(DIO4));
  101.     dataB = bitWrite(dataA, 4, digitalRead(DIO5));
  102.     dataA = bitWrite(dataB, 5, digitalRead(DIO6));
  103.     dataB = bitWrite(dataA, 6, digitalRead(DIO7));
  104.     dataA = bitWrite(dataB, 7, digitalRead(DIO8));
  105.  
  106.     return ~dataA;
  107. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top