Page 324 - Programming Microcontrollers in C
P. 324
Cosmic MC68HC16 Compiler 309
/* and start over again */
if(new_input>=1 && new_input<=4048)
pwm_count=new_input;
new_input=0;
}
else
new_input=0; /*reject everything else*/
}
}
}
/* The asynchronous service portion of the program */
@port void OC3_Isr( void) /* the PWM isr */
{
TFLG1.OC1F=OFF; /* reset OC1 interrupt flag */
if(OC1D.OC1D3==ON) /* toggle OC1D3 */
OC1D.OC1D3=OFF;
else
OC1D.OC1D3=ON;
TFLG1.OC3F=OFF; /* reset OC3 interrupt flag */
TOC1+=pwm_period;
TOC3=TOC1+pwm_count;
}
Listing 6-3: PWM System With Keyboard Input
The qsm.h header file is included to add all of the register and
defines needed for the operation of the SCI. We are going to place
the operation of the SCI into the applications portion of the pro
gram. Implementation of the SCI requires that a baud rate be selected
and the transmit enable along with the receive enable bits be set in
the serial communications control register number 2. The baud rate
is set to 38400 by placing a properly calculated value into the SCBR
field of SCCR0. With these lines of code, the serial communications
interface is set up and ready to work.
The code inside the application portion of the program is essen
tially identical to that found in Chapter 6. The only difference is that
the variable names are changed to be more compliant with this appli
cation. Here is another interesting case where the code written for
the MC68HC11 will move directly to the MC68HC16 with minimal
change.