Page 295 - Programming Microcontrollers in C
P. 295
280 Chapter 5 Programming Large 8-Bit Systems
/* external variable definitions */
long measured_period,delpc;
WORD time1,time2,
motor_period,motor_speed=IMPOSSIBLE;
WORD new_speed;
WORD old_motor_speed=TOO_LOW,rpm,mparray[COUNT_8];
long PWM_period=PERIOD, PWM_count=TIME_ON;
int new_character,tick=TRUE,count=0,in_process;
int tick1=TRUE,count1=0;
WORD got_new=TRUE;
main()
{
/* The initialization portion of the program */
TCTL2.EDG1B=ON;/* capture falling edge only */
OC1M.OC1M7=ON; /* sent OC1 out to PA7 */
OC1M.OC1M5=ON; /* couple OC1 to OC3 */
TMSK1.OC3I=ON; /* enable the OC3 interrupt */
TMSK1.IC1I=ON; /* enable the IC1 interrupt */
OC1D.OC1D5=ON; /* turn on OC3 when OC1 occurs */
TCTL1.OL3=ON; /* toggle OC3 when OC3 occurs */
PACTL.DDRA7=ON;/* make OC1 an output to PA7 */
TOC1=TCNT+PWM_period; /* set OC1 to the period*/
TOC3=TOC1+PWM_count; /* set OC3 time on */
BAUD.SCP=3; /* set up the SCI */
BAUD.SCR=0; /* 9600 baud */
SCCR2.TE=ON;
SCCR2.RE=ON;
cli(); /* enable the system interrupts */
/* the applications portion of the program */
FOREVER
{
if(old_motor_speed!=motor_speed)
{ /* All of the numbers used below are
derived in the text */
motor_period=30000000lu/motor_speed;
old_motor_speed=motor_speed;