/* * stepper.c * A program that turns turns the stepper motor, first clockwise, then * counter-clockwise * * Author: C.Schramm * Date: February 10, 2006 */ #define _IO_BASE 0 #define _ADDR(off) (unsigned char volatile *)(_IO_BASE + off) #define _P(off) *(unsigned char volatile *)(_IO_BASE + off) #define DDRP _P(0x025A) #define PTP _P(0x0258) #define PTT _P(0x0240) #define DDRT _P(0x0242) void delay(int n); void main(void) { int i; // Initialize the ports required for the Stepper motor // DO NOT ALTER DDRT |= 0b01100000; DDRP |= 0b00100000; PTP |= 0b00100000; PTT = 0b01100000; //Spin Stepper Motor in the clockwise direction for(i = 0; i < 5; i++) // for: Repeats whatever follows between {...} { // TIP: You may change the number of times it repeats, // but to begin, let it as '5'. // TO BE COMPLETED: In each statement below, a dummy value has been // sent to Port T. You must supply the correct // sequence of values so that the two stators in our // stepper motor are activated so as to induce clockwise // motion in the rotor. // Remember: Port T Bit 5 is the vertical stator // Port T Bit 6 is the horizontal stator // TIP: You may alter the length of the delay, to make your motor // change at quicker or slower intervals PTT = 0b00000000; delay(5); PTT = 0b00000000; delay(5); PTT = 0b00000000; delay(5); PTT = 0b00000000; delay(5); } //Spin Stepper Motor in the counter-clockwise direction for(i = 0; i < 5; i++) { // TO BE COMPLETED: Repeat as above, but reverse the direction. PTT = 0b00000000; delay(5); PTT = 0b00000000; delay(5); PTT = 0b00000000; delay(5); PTT = 0b00000000; delay(5); } } /* delay * Does idle work for a period of time, keeping the CPU busy * but doing nothing useful */ void delay(int n) { int x; int y; int dummy = 1000; for (;n>0;n--) { for(y=0; y<0x1F; y++) { for(x=0; x<0x1FF; x++) { dummy = dummy + 0; dummy = dummy * 1; dummy = dummy / 1; } } } }