// experi7a.c #include #include #include // defines OC structure #include "outcnt7a.h" // include header with constants #include "const7a.h" // include header with external prototypes #include "extern7a.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); printf("10%%:\n"); UniPwmDuty(MainMotor, PA0, 10.0); Blink(LED1, PA1, .3, .2); Blink(LED2, PA2, .15, .1); SetLast(LASTSLOT); showall(); printf("\npress any key to continue\n"); getch(); printf("\n.01 on, .01 off:\n"); pwm(MainMotor, 0, // array number, type PA0, 0, // forward port, reverse port not used 0,0, // direction and brake not used 0.01, 0.01, // forward on and forward off times 0,0,1); // reverse on and off not used, start forward show(MainMotor); printf("\npress any key to continue\n"); getch(); while(!kbhit()) { for(dc=20.0; dc<=90.0; dc+=10.0) { printf("dutycycle = %f\n",dc); UniPwmDuty(MainMotor, PA0, dc); wait(.1); if(kbhit()) break; } if(dc < 90.0) break; for(dc=80.0; dc>20.0; dc-=10.0) { printf("dutycycle = %f\n",dc); UniPwmDuty(MainMotor, PA0, dc); wait(.1); if(kbhit()) break; } if(dc > 20.0) break; } // don't forget to free memory! FreeOutputControl(); portaoff(); // be sure to restore the timer! restore_old_timer(); } // end experi7a.c