// experi7d.c #include #include #include // defines OC structure #include "outcont.h" // include header with constants #include "constant.h" // include header with external prototypes #include "extern.h" enum { MainMotor, LED1, LED2, LASTSLOT }; void main(void) { int x; double dc,oldfreq,newfreq; oldfreq = 1193180.0/65536.0; get_port(); // get the port number and establish register locations // make everthing an output set_up_ppi(Aout_CUout_Bout_CLout); set_up_new_timer(2000.0); SetLast(LASTSLOT); newfreq = get_frequency(); printf("old frequency = %f new frequency = %f Hz\n" ,oldfreq,newfreq); // set up a channel with a pwm line and a direction line -- no brake // using duty cycle PwmAndDirectionDuty(MainMotor, 0, // set up, but don't start main motor PA0, PA2, // pwm and direction port 75.0, 50.0); // forward 75%, reverse 50% printf("MainMotor on/off settings pwm = PA0, dir = PA2:\n"); show(MainMotor); Blink(LED1, PA1, .3, .2); Blink(LED2, PA4, .15, .1); SetLast(LASTSLOT); while(!kbhit()) { Forward(MainMotor); if(kbhit()) break; wait(1); Stop(MainMotor); if(kbhit()) break; wait(1); Reverse(MainMotor); if(kbhit()) break; wait(1); Stop(MainMotor); if(kbhit()) break; wait(1); } Stop(MainMotor); // don't forget to free memory! FreeOutputControl(); // be sure to restore the timer! restore_old_timer(); } // end experi7d.c