/* * 20210313_m32u4_stepper.c * * Created: 2021-03-13 12:45:31 * Author : uwezi */ #define F_CPU 8000000UL #include #include const uint8_t steps[] = {0b0001, 0b0101, 0b0100, 0b0110, 0b0010, 0b1010, 0b1000, 0b1001}; // bipolar stepper motor connected through a SN754410 driver // D0 A1 // D1 A2 // D2 B1 // D3 B2 int main(void) { uint8_t i=0; uint16_t j; DDRD = 0b00001111; PORTD = 0b00000000; while (1) { for (j=0; j<1000; j++) { PORTD = steps[i]; i ++; i %= 8; _delay_ms(1); } for (j=0; j<1000; j++) { PORTD = steps[7-i]; i ++; i %= 8; _delay_ms(1); } } }