/* * mmtest2.c * * Test two: turn on the motor, let it run for 2 seconds, reverse direction, * flash LED and then turn the motor on again * * NOTE: It is safer to stop the motor before reversing its * direction. If you don't then a potentially large back-EMF current * from the motor could destroy the PIC or the Motor Mind B module * * Motor Mind module is conected to PORTA * FM pin on MM is connected to RA1 pin 18 * LED on RB4 via 1K resistor * * Mark Crosbie 10/31/98 mark@mastincrosbie.com */ #define MOTOR 0x5 #define MMPIN 1 #define LED 4 void main(void) { set_bit(STATUS, RP0); /* select the register bank 1 */ clear_bit(TRISA, MMPIN); /* Port A.1 is output */ clear_bit(TRISB, LED); /* Port RB.4 is output */ clear_bit(STATUS, RP0); while(1) { /* start the motor at half speed */ mm_start(MOTOR, MMPIN, 128); delay_s(2); /* stop the motor */ mm_stop(MOTOR, MMPIN); /* reverse direction */ mm_reverse(MOTOR, MMPIN); /* flash LED */ set_bit(PORTB, LED); delay_s(1); clear_bit(PORTB, LED); delay_s(1); } }