Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 1000000UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #include <math.h>
- #include <LCD4B.h>
- long counter = 0;
- int x = 0;
- int prevStep=1;
- int delayStepperY = 1000;
- int isStepperYBusy=0;
- int main(void)
- {
- DDRC = 0xFF;
- PORTC = 0x00;
- moveBackwards(150);
- }
- void moveForward(int steps)
- {
- if(isStepperYBusy==0)
- {isStepperYBusy=1;
- int stepsInLoop=0;
- for (stepsInLoop; stepsInLoop<=steps; stepsInLoop++)
- {
- switch(prevStep){
- case 1:
- {
- PORTC = 1 << PINC0;
- _delay_us(delayStepperY);
- prevStep = 2;
- stepsInLoop++;
- }
- case 2:
- {
- PORTC = 1 << PINC1;
- _delay_us(delayStepperY);
- prevStep = 3;
- stepsInLoop++;
- }
- case 3:
- {
- PORTC = 1 << PINC2;
- _delay_us(delayStepperY);
- prevStep = 4;
- stepsInLoop++;
- }
- case 4:
- {
- PORTC = 1 << PINC3;
- _delay_us(delayStepperY);
- prevStep = 1;
- stepsInLoop++;
- }
- }
- }
- isStepperYBusy=0;
- }
- else{
- }
- }
- void moveBackwards(int steps)
- {
- if(isStepperYBusy==0)
- {
- isStepperYBusy=1;
- int stepsInLoop=0;
- for (stepsInLoop; stepsInLoop<=steps; stepsInLoop++)
- {
- switch(prevStep){
- case 1:
- {
- PORTC = 1 << PINC1;
- _delay_us(delayStepperY);
- prevStep = 2;
- stepsInLoop++;
- }
- case 2:
- {
- PORTC = 1 << PINC0;
- _delay_us(delayStepperY);
- prevStep = 3;
- stepsInLoop++;
- }
- case 3:
- {
- PORTC = 1 << PINC3;
- _delay_us(delayStepperY);
- prevStep = 4;
- stepsInLoop++;
- }
- case 4:
- {
- PORTC = 1 << PINC2;
- _delay_us(delayStepperY);
- prevStep = 1;
- stepsInLoop++;
- }
- }
- }
- isStepperYBusy=0;
- }
- else
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement