Skip to content

Instantly share code, notes, and snippets.

@Osomo3000
Created October 24, 2018 08:12
Show Gist options
  • Save Osomo3000/7f0418c9e6edebf7195bb4c6b0251134 to your computer and use it in GitHub Desktop.
Save Osomo3000/7f0418c9e6edebf7195bb4c6b0251134 to your computer and use it in GitHub Desktop.
#include <avr/io.h>
#include <util/delay.h>
#define stepPin PD7 //Define Step pin
#define dirPin PD6 //Define Direction pin
#define Enable PD5 //Define Enable pin
int main(void)
{
int x,y;
DDRD |= (1<<5)|(1<<6)|(1<<7); // Configure PORTD5, PORTD6, PORTD7 as output
PORTD &= ~(1<<5); // Enable driver
DDRD &= ~(1<<PD2) | (1<<PD3);
PORTD |= (1<<PD2) | (1<<PD3);
while (1)
{
//Make PORTD6 high to rotate motor in clockwise direction
for(x=0; x<4; x++) //Give 50 pulses to rotate stepper motor by 90 degree's in full step mode
{
for(y=0; y<50; y++)
{
/*
PORTD |=(1<<7);
_delay_ms(0.7);
PORTD &=~(1<<7);
_delay_ms(0.7);
*/
}
}
if ( !(PIND & (1<<PD2)) ) {
PORTD |= (1<<6);
PORTD |=(1<<7);
_delay_ms(5);
PORTD &=~(1<<7);
_delay_ms(5);
} else if( !(PIND & (1<<PD3)) ){
PORTD &= ~(1<<6);
PORTD |=(1<<7);
_delay_ms(5);
PORTD &=~(1<<7);
_delay_ms(5);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment