Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.10 KB | None | 0 0
  1. int motorPin = 2;
  2. int directionPin = 4;
  3. int stepPin = 5;
  4. int trackZeroPin = 8;
  5. int indexPin = 1;
  6. int driveSelPin = 3;
  7. int writeDataPin = 6;
  8. int writeEnablePin = 7;
  9. int writeProtectPin = 9;
  10. int headSelectPin = 11;
  11. int readDataPin = 10;
  12. int diskReadyPin = 12;
  13. ////////////////////////
  14. int currentTrack = 0;
  15. int trackContor = 0;
  16. int tmpVec[500];
  17. int vecCont = 0;
  18.  
  19. int onThisTrack = 0;
  20.  
  21. int zeros = 0;
  22. int ones = 0;
  23. int onesArray[30];
  24. int zerosArray[30];
  25. ////////////////////////
  26. void setup()
  27. {
  28.     pinMode(motorPin,OUTPUT);
  29.     pinMode(directionPin,OUTPUT);
  30.     pinMode(stepPin,OUTPUT);
  31.     pinMode(driveSelPin,OUTPUT);
  32.     pinMode(writeEnablePin,OUTPUT);
  33.     pinMode(writeDataPin,OUTPUT);
  34.     pinMode(trackZeroPin,INPUT_PULLUP);
  35.     pinMode(indexPin,INPUT_PULLUP);
  36.     pinMode(readDataPin,INPUT_PULLUP);
  37.     pinMode(writeProtectPin,INPUT_PULLUP);
  38.     pinMode(diskReadyPin,INPUT_PULLUP);
  39.    
  40.     Serial.begin(9600);
  41.     driveEnable();
  42.     motorDisable();
  43.     jiggle();
  44.     jumpOutermost();
  45.     motorEnable();
  46.     execute();
  47.    
  48.     writeDisable();
  49. }
  50. int data = 1;
  51. void loop()
  52. {
  53.     Serial.print(readDataRaw());
  54. //    writeDisable();
  55. //    if (currentTrack<30)
  56. //    {
  57. //        if (hasIndexPulsed())
  58. //        {
  59. //            onThisTrack++;
  60. //            if (onThisTrack>=3)
  61. //            {
  62. //                onThisTrack = 0;
  63. //                onesArray[currentTrack]=ones;
  64. //                zerosArray[currentTrack]=zeros;
  65. //                stepIn();
  66. //                ones = 0;
  67. //                zeros = 0;
  68. //            }
  69. //        }
  70. //        else
  71. //        {
  72. //            if (readDataRaw()==HIGH)
  73. //            {
  74. //                ones++;
  75. //            }
  76. //            else
  77. //            {
  78. //                zeros++;
  79. //            }
  80. //        }
  81. //    }
  82. //    else
  83. //    {
  84. //        
  85. //        motorDisable();
  86. //        for (int i=0;i<currentTrack;i++)
  87. //        {
  88. //            Serial.println(String(i)+" "+String(onesArray[i])+" "+String(zerosArray[i])+" "+(onesArray[i] - zerosArray[i]));
  89. //            delay(100);
  90. //        }
  91. //        jumpOutermost();
  92. //        currentTrack = 0;
  93. //        motorEnable();
  94. //    }
  95.  
  96. //    writeEnable();
  97. //    if (currentTrack<30)
  98. //    {
  99. //        if (hasIndexPulsed())
  100. //        {
  101. //            onThisTrack++;
  102. //            if (onThisTrack>=3)
  103. //            {
  104. //                onThisTrack = 0;
  105. //              
  106. //                stepIn();
  107. //            }
  108. //        }
  109. //        else
  110. //        {
  111. //            setWriteData(data);
  112. //            data = 1 - data;
  113. //        }
  114. //    }
  115. //    else
  116. //    {
  117. //        jumpOutermost();
  118. //        currentTrack = 0;
  119. //    }
  120. }
  121. void execute()
  122. {
  123. //    int Data = 1;
  124. //    motorEnable();
  125. //    writeEnable();
  126. //
  127. //    LoopB:
  128. //    if (readIndex()==0) goto LoopB;
  129. //    LoopC:
  130. //    if (readIndex()==1) goto LoopC;
  131. //    LoopD:
  132. //    setWriteData(0);
  133. //    if (readIndex()==0) goto LoopD;
  134. //
  135. //    LoopE:
  136. //    if (readIndex()==1) goto LoopE;
  137. //    stepIn();
  138. //    if (currentTrack<40) goto LoopD;
  139. //
  140. //    writeDisable();
  141. //    for (int i=1;i<=currentTrack;i++)
  142. //    {
  143. //        stepOut();
  144. //    }
  145.  
  146. //    int data = 0;
  147. //    writeDisable();
  148. //    LoopB:
  149. //    if (readIndex()==0) goto LoopB;
  150. //    LoopC:
  151. //    if (readIndex()==1) goto LoopC;
  152. //
  153. //    LoopD:
  154. //    data = readData();
  155. //    if (vecCont<499)
  156. //    {
  157. //        tmpVec[vecCont++] = data;
  158. //    }
  159. //    if (readIndex()==LOW) goto LoopD;
  160. //    LoopE:
  161. //    if (readIndex()==HIGH) goto LoopE;
  162. //
  163. //    stepIn();
  164. //    if (currentTrack<10) goto LoopD;
  165. //
  166. //    for (int i=0;i<vecCont;i++)
  167. //    {
  168. //        Serial.print(tmpVec[vecCont]);
  169. //        delay(20);
  170. //    }
  171. }
  172. ////////////////////////////////////////////////
  173. int jumpToTrack(int track)
  174. {
  175.     if (track<84)
  176.     {
  177.         if (track>currentTrack)
  178.         {
  179.             int steps = track-currentTrack;
  180.             for (int i=1;i<=steps;i++)
  181.             {
  182.                 stepIn();
  183.             }
  184.         }
  185.         else if (track<currentTrack)
  186.         {
  187.             int steps = currentTrack-track;
  188.             for (int i=1;i<=steps;i++)
  189.             {
  190.                 stepOut();
  191.             }
  192.         }
  193.     }
  194. }
  195. int stepOut()
  196. {
  197.     digitalWrite(directionPin,HIGH);
  198.     digitalWrite(stepPin,LOW);
  199.     delayMicroseconds(1);
  200.     digitalWrite(stepPin,HIGH);
  201.     delayMicroseconds(3000);
  202.     currentTrack-=1;
  203. }
  204. int stepIn()
  205. {
  206.     digitalWrite(directionPin,LOW);
  207.     digitalWrite(stepPin,LOW);
  208.     delayMicroseconds(1);
  209.     digitalWrite(stepPin,HIGH);
  210.     delayMicroseconds(3000);
  211.     currentTrack+=1;
  212. }
  213. int readTrackZero()
  214. {
  215.     return digitalRead(trackZeroPin);
  216. }
  217. int readIndex()
  218. {
  219.     return digitalRead(indexPin);
  220. }
  221. int readDataRaw()
  222. {
  223.     return digitalRead(readDataPin);
  224. }
  225.  
  226. int lastData = LOW;
  227.  
  228. int readData()
  229. {
  230.     int curData = readDataRaw();
  231.     if (curData == LOW && lastData == HIGH)
  232.     {
  233.         lastData = curData;
  234.         return 1;
  235.     }
  236.     else
  237.     {
  238.         lastData = curData;
  239.         return 0;
  240.     }
  241. }
  242. int readDiskReady()
  243. {
  244.     return digitalRead(diskReadyPin);
  245. }
  246. int motorEnable()
  247. {
  248.     digitalWrite(motorPin,LOW);
  249. }
  250. int motorDisable()
  251. {
  252.     digitalWrite(motorPin,HIGH);
  253. }
  254. int jumpOutermost()
  255. {
  256.     while (readTrackZero()==HIGH)
  257.     {
  258.         stepOut();
  259.     }
  260. }
  261. int jiggle()
  262. {
  263.     stepIn();
  264.     stepOut();
  265. }
  266. int driveEnable()
  267. {    
  268.     digitalWrite(driveSelPin,LOW);
  269. }
  270. int driveDisable()
  271. {    
  272.     digitalWrite(driveSelPin,HIGH);
  273. }
  274.  
  275. int lastIndex = LOW;
  276.  
  277. int hasIndexPulsed()
  278. {
  279.     int curIndex = readIndex();
  280.     if (curIndex == LOW && lastIndex == HIGH)
  281.     {
  282.         lastIndex = curIndex;
  283.         return 1;
  284.     }
  285.     else
  286.     {
  287.        
  288.         lastIndex = curIndex;
  289.         return 0;
  290.     }
  291. }
  292. int isWriteProtected()
  293. {
  294.     if (digitalRead(writeProtectPin)==LOW)
  295.     {
  296.         return 1;
  297.     }
  298.     else
  299.     {
  300.         return 0;
  301.     }
  302. }
  303. int writeEnable()
  304. {
  305.     digitalWrite(writeEnablePin,HIGH);
  306. }
  307. int writeDisable()
  308. {
  309.     digitalWrite(writeEnablePin,LOW);
  310. }
  311. int setWriteData(int data)
  312. {
  313.     digitalWrite(writeDataPin,data);
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement