/***************************************************************************** * ECE476 Final Lab - Stepper Motor Test Program * * David Shu (dhs25) * * Thientu Ho (th243) * * 4/05 * *****************************************************************************/ /* * Ports * ~~~~~ * PORTA : * PORTB : [output] Output to motor control * PORTC : [output] Debug LED's * PORTD : * */ #include #include #include // ### DEFINITIONS ############################################################ // Time definitions #define t0 10 // Wire definitions /* BLUE 1011 * ORANGE 1110 * RED 1101 * WHITE 0111 */ #define STEP0 0b00000110 #define STEP1 0b00001010 #define STEP2 0b00001001 #define STEP3 0b00000101 void initialize(void); // Timer used for counting 1 ms unsigned int time_step; // Used for counting the number of steps unsigned char step; // ### ISRs ################################################################### interrupt [TIM0_COMP] void isr_onems(void) { if (time_step>0) time_step--; } // end isr_onems // ### INITIALIZE ############################################################# void initialize(void) { // PORTB : [output] Output to motor control DDRB = 0xff; PORTB = 0; // PORTC : [output] Debug LED's DDRC = 0xff; PORTC = 0xff; // Set up Timer0, 1 ms TIMSK = 2; // t0 compare match enable OCR0 = 249; // 250 ticks until clear TCCR0 = 0b00001011; // CTC, clk/64 // Initialize counters // time_step = t0; step = 0; #asm sei #endasm } // end initialize() // ### MAIN ################################################################### void main(void) { initialize(); while(1) { if (time_step == 0) { time_step = t0; if (step < 3) step++; else step = 0; } if (step == 0) { PORTB = STEP0; PORTC = ~STEP0; } // end step 0 if (step == 1) { PORTB = STEP1; PORTC = ~STEP1; } // end step 1 if (step == 2) { PORTB = STEP2; PORTC = ~STEP2; } // end step 2 if (step == 3) { PORTB = STEP3; PORTC = ~STEP3; } // end step 3 } // end while(1) } // end main