// experi7c.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); newfreq = get_frequency(); printf("old frequency = %f new frequency = %f Hz\n" ,oldfreq,newfreq); // set up a dual pwm channel using duty cycle DualPwmDuty(MainMotor, 0, // set up, but don't start main motor PA0, 20.0, // forward uses line PA0 at 20% PA1, 20.0); // reverse uses line PA1 at 20% Blink(LED1, PA2, .3, .2); printf("LED1 on/off settings:\n"); show(LED1); Blink(LED2, PA3, .15, .1); printf("LED2 on/off settings:\n"); show(LED2); SetLast(LASTSLOT); printf("MainMotor on/off settings with 75%% forward and 15%% reverse:\n"); show(MainMotor); printf("LEDs blinking and pwm off -- esc to quit, any other start test\n"); if(getch() != 27) // escape key { while(!kbhit()) { printf("forward 20%% 1 second\n"); Forward(MainMotor); wait(1.0); // wait 1 second printf("brake, wait .5 seconds\n"); BrakeDualPwm(MainMotor); wait(0.5); // wait 1 second printf("reverse 20%% 1 second\n"); Reverse(MainMotor); wait(1.0); // wait 1 second printf("brake, wait .5 seconds\n"); BrakeDualPwm(MainMotor); wait(0.5); // wait 1 second } } portaoff(); portboff(); portboff(); // don't forget to free memory! FreeOutputControl(); // be sure to restore the timer! restore_old_timer(); } // end experi7c.c