All pastes #259001 Raw Edit

Unnamed

public text v1 · immutable
#259001 ·published 2006-11-27 00:23 UTC
rendered paste body
#include <avr/io.h>
#include <string.h>


volatile int stepperpos = 0;
//volatile unsigned char steps[] = {0x01, 0x02, 0x04, 0x08};
volatile unsigned char steps[] = {0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x09};
//volatile unsigned char steps[] = {0x03, 0x06, 0x0c, 0x09};


void go(int pos, int delay);
void step(int i);
void wait(int i);

int main() {
	int i;
	int loop;
	int points[] = {10, 21, 19, 3, 21, 16, 10, 31, 10, 27, 0, 12, 22, 5, 15};

	DDRC=0xFF;
	for (loop = 0; loop < 100; loop++) {
		go(48, 10000); 
		go(0, 10000);
//		go(12*sizeof(steps) * 0.2,  10000);
//		go(12*sizeof(steps) * 0,  10000);

	}

	go(0, 1000);

	PORTC=1;
	wait(10000);
	PORTC=0;
	return(0);
}



void go(int pos, int delay) {
	int i;

	if (pos > stepperpos) {
		for (i = stepperpos; i < pos; i++) {
			step(i);
			wait(delay);
		}
	} else if (pos < stepperpos) {
		for (i = stepperpos; i > pos; i--) {
			step(i);
			wait(delay);
		}
	}
	stepperpos = pos;
}



void step(int i) {
	int nbsteps;

	nbsteps = sizeof(steps);
	
	i = i - ((i / nbsteps) * nbsteps);
	
	PORTC=steps[i];
}

void wait(int i) {
  int count;
  for (count = 1; count <= i; count++) { asm("nop; nop; nop; nop; nop;"); }
}