uwezi

labb_7_stepper_demo.c

Dec 2nd, 2020
1,237
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3.  
  4. // quick and dirty: the stepping sequence as 8 constant values
  5. uint8_t steps[8]={0b0001,0b0011,0b0010,0b0110,0b0100,0b1100,0b1000,0b1001};
  6.  
  7. int main(void)
  8. {
  9.   uint8_t i=0;
  10.   DDRD = 0x0F;  // motor driver connected to PD0-PD3
  11.  
  12.   while (1)
  13.   {
  14.     PORTD = steps[i];
  15.     i++;
  16.     i %= 8;
  17.     _delay_ms(1);    // delay between steps
  18.   }
  19. }
  20.  
RAW Paste Data