SHARE
TWEET

Untitled

a guest Jan 18th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <system.h>
  4. #include <io.h>
  5.  
  6. int halfStepCounterClockwiseValues[9] = {0b0001,0b0011,0b0010,0b0110,0b0100,0b1100,0b1000,0b1001};
  7. int halfStepClockwiseValues[9] = {0b1000,0b1100,0b0100,0b0110,0b0010,0b0011,0b0001,0b1001};
  8. int velocityValues[10] = {0b0000000001,0b0000000011,0b0000000111,0b0000001111,0b0000011111,0b0000111111,0b0001111111,0b0011111111,0b0111111111,0b1111111111};
  9.  
  10. void triggerHalfStepping(unsigned int step, unsigned int direction){
  11.     unsigned int halfStepValue;
  12.    
  13.     switch (direction) {
  14.         case 1:
  15.             IOWR(PIO_GPIO_BASE, 0, halfStepClockwiseValues[step]); break;
  16.         case 2:
  17.             IOWR(PIO_GPIO_BASE, 0, halfStepCounterClockwiseValues[step]); break;
  18.         default:
  19.             IOWR(PIO_GPIO_BASE, 0, halfStepClockwiseValues[step]); break;
  20.     }
  21.     printf("%d", halfStepValue);
  22. }
  23.  
  24. void indicateVelocity(unsigned int velocity){
  25.     IOWR(PIO_LED_BASE, 0, velocityValues[velocity]);
  26. }
  27.  
  28. int main(void)
  29. {
  30.     unsigned int switchValue=0, keySwitchValue=0;
  31.     unsigned int stepValue,velocityValue=1;
  32.     while(1)
  33.     {
  34.        
  35.         switchValue=IORD(PIO_SW_BASE,0x00);
  36.         keySwitchValue=IORD(PIO_KEY_BASE,0x00);
  37.         IOWR(PIO_LED_BASE,0x00,switchValue);
  38.        
  39.         if((keySwitchValue&0x02)!=0 && velocityValue<11) {
  40.             velocityValue++;
  41.         }
  42.         if((keySwitchValue&0x01)!=0 && velocityValue>1) {
  43.             velocityValue--;
  44.         }
  45.         indicateVelocity(velocityValue);
  46.  
  47.         if((switchValue&0x01)!=0)
  48.         {
  49.             for(stepValue=1;stepValue<9;stepValue++)
  50.             {
  51.                 triggerHalfStepping(stepValue,1);
  52.                 usleep(-(5000*velocityValue)+100000);
  53.             }
  54.         }
  55.         else
  56.         {
  57.             for(stepValue=1;stepValue<9;stepValue++)
  58.             {
  59.                 triggerHalfStepping(stepValue,2);
  60.                 usleep(-(5000*velocityValue)+100000);
  61.             }
  62.         }
  63.     }
  64.     return 0;
  65. }
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