Page 273 - Programming Microcontrollers in C
P. 273
258 Chapter 5 Programming Large 8-Bit Systems
A beginning program or framework from which to build this
application is shown in Listing 5-6. All this program contains is the
setup of the interrupts and the interrupt service routines. Input capture
1 will serve as input from the motor shaft encoder. The motor will be
controlled by a PWM signal. This signal will be filtered to provide a
DC signal that can drive the motor. As with the MC68HC05 programs,
this code is broken into three basic parts: 1) the initialization section,
2) the applications section, and 3) the asynchronous service section.
In this case, there is no applications section, so it is designated by a
FOREVER command followed by an empty block.
The program begins with the inclusion of the HC11E9.H header
file. Immediately following this entry are the prototype entries for
all of the interrupt service routines. The declarations of the global
variables follows. The first set of variables are all associated with the
input capture, and the second line of variables controls the output
compare portion of the program.
Notice that the bit set-up instructions are all grouped so that the
bits from each register are set in the same location. It is not necessary
to group these instructions; however, if they are grouped by register
as is done here, the compiler will use a single bit manipulation
instruction to set all of the bits in each register. The first 8-bit
manipulation instructions in the following code will require only six
assembly instructions as they are grouped.
#include “hc11e9.h”
#define MS3_DEBOUNCE 1500
#define PERIOD 0X1000
#define TIME_ON 0x0800
@port void IC1_Isr(void);
@port void OC2_Isr(void);
@port void OC3_Isr(void);
WORD measured_period, time1, delpc;
WORD PWM_period=PERIOD, time_on=TIME_ON;
main()
{
TCTL2.EDG1B=ON;/* capture falling edge only */