Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. Code made by "gorgeous"
  3. http://forum.arduino.cc/index.php?topic=78634.0
  4.  
  5. Most of the i2c commands here presented were copied and then modified
  6.  the original source is the  Arduino I2cMaster Library
  7.  written by William Greiman
  8.  
  9.  the parity check code is by Claas Anders "CaScAdE" Rathje
  10.  
  11.  pins for sda,scl,mrq are connected directly to their correspondant
  12.  on the TID connector, no extra circuitry needed
  13.  
  14.  */
  15.  
  16. // pin numbers
  17. #define sda  7
  18. #define scl  5
  19. #define mrq  6
  20. #define tid_delay 150  //this is a working timing value, if you change this, TID can stop working 180
  21. #define delay_300 150
  22. #define delay_100 100
  23.  
  24.  
  25. void setup () {
  26.  
  27.   pinMode(mrq, OUTPUT);
  28.   pinMode(sda, OUTPUT);
  29.   pinMode(scl, OUTPUT);
  30.   digitalWrite(mrq, HIGH);
  31.   digitalWrite(sda, HIGH);
  32.   digitalWrite(scl, HIGH);
  33. }
  34. void loop () {
  35.   start_tid();
  36.   tid_address(0x9B);
  37.   tid_data(0);  //first symbols byte
  38.   tid_data(0);
  39.   tid_data(0);
  40.   tid_data(0);    //first letter
  41.   tid_data(0);
  42.   tid_data(0);
  43.   tid_data('O');
  44.   tid_data('p');
  45.   tid_data('e');
  46.   tid_data('l');
  47.   tid_data(0);
  48.   tid_data(0);
  49.   tid_data(0);    //10th letter
  50.   stop_tid();  
  51. }
  52.  
  53.  
  54. void tid_byte(byte data) {
  55.   pinMode(scl, OUTPUT);
  56.   for (uint8_t m = 0X80; m != 0; m >>= 1) { //2 lines from
  57.     digitalWrite(sda, m & data);              //William Greiman's I2cMaster Library
  58.     delayMicroseconds(5);
  59.     digitalWrite(scl, HIGH);
  60.     delayMicroseconds(50);
  61.     digitalWrite(scl, LOW);
  62.     delayMicroseconds(50);
  63.   }
  64.   delayMicroseconds(delay_300);
  65.   pinMode(sda,INPUT);     //3
  66.   delayMicroseconds(tid_delay);
  67.   pinMode(scl,INPUT);     //4
  68.   delayMicroseconds(delay_100);
  69.   while(digitalRead(scl)==0);   //6
  70.   delayMicroseconds(delay_300);
  71.   pinMode(scl,OUTPUT);
  72.   digitalWrite(scl, LOW);   //7
  73.   while(digitalRead(sda)==0);   //8
  74.   pinMode(sda,OUTPUT);
  75. }
  76.  
  77. void tid_data(byte data) {      //bytes of data
  78.   byte val=data;            //this parity check code
  79.   byte pari;                //comes from
  80.   val = val ^ (val >> 4);   //Claas Anders "CaScAdE" Rathje http://www.mylifesucks.de/oss/c-tid/
  81.   val = val ^ (val >> 2);   //from a post in the
  82.   val = val ^ (val >> 1);   //mikrocontroller.net forum
  83.   val &= 0x01;              //http://www.mikrocontroller.net/topic/19516
  84.   data = (data<<1)|pari;
  85.   tid_byte(data);
  86. }
  87.  
  88.  
  89. void tid_address(byte address) {  //address completed with the extra 0 for write mode on the right
  90.   tid_byte(address);
  91.   digitalWrite(mrq, LOW);
  92. }
  93.  
  94.  
  95. void start_tid() {
  96.   pinMode(sda,INPUT);
  97.   digitalWrite(mrq, LOW);
  98.   delayMicroseconds(100);
  99.   while(digitalRead(sda)==1);
  100.   digitalWrite(mrq, HIGH);
  101.   delayMicroseconds(100);
  102.   while(digitalRead(sda)==0);
  103.   pinMode(sda,OUTPUT);
  104.   pinMode(scl,OUTPUT);
  105.   digitalWrite(sda, LOW);
  106.   delayMicroseconds(100);
  107.   digitalWrite(scl, LOW);
  108.   delayMicroseconds(100);
  109. }
  110.  
  111. void stop_tid() {
  112.   digitalWrite(sda, LOW);
  113.   delayMicroseconds(100);
  114.   digitalWrite(mrq, HIGH);
  115.   delayMicroseconds(500);
  116.   digitalWrite(scl, HIGH);
  117.   delayMicroseconds(100);
  118.   digitalWrite(sda, HIGH);
  119.   delayMicroseconds(100);
  120. }