Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Programming Microcontrollers in C, 2-nd edit (Ted Van Sickle, 2001).pdf
Скачиваний:
296
Добавлен:
12.08.2013
Размер:
7.2 Mб
Скачать

Summary 285

There are three input/output routines that have been written for this program. These routines, putchar(), dprint(), and do_crlf(), can be used with other systems with a serial input/ output system. The Cosmic compiler does provide the usual I/O routines like printf(), gets(), puts(), etc. It does not provide a basic putchar() and getchar() which is used by all of these library routines. The reason that these routines are not provided by the compiler is the wide variety of what the programmer will want to implement with the built-in SCI ports on the MC68HC11 family. The putchar() shown above will work in most instances. The dprint() routine is a recursive routine that converts an integer into an ASCII string and sends it to the SCI port.

There is one final modification to the program. In the last lines of the PWM timer routine, count1 and tick1 are processed to set tick1 to be TRUE each second. This flag is then used to control the writing of the motor speeds to the terminal screen.

Summary

There has been no attempt to work all of the peripherals on the MC68HC11. The various peripherals are similar to those on the other parts that we have discussed in other chapters or will discuss later. We have seen several timer applications both in the MC68HC11 and in the MC68HC05. We will see other timer applications in the following chapters.

We have seen detailed use of the output compare timer subsystem to make a pulse width modulation digital-to-analog converter system. Depending on the program, the system allowed excellent performance in either short on times or maximum on times, but not both without the addition of a significant amount of code. We will see a system in the next chapter that provides excellent performance for both minimum and maximum on times. This performance is not a limitation of the MC68HC11, merely a limitation of the programs presented so far.

The input capture subsystem has been used to measure motor speed in a simple DC motor controller. This system used a primitive reed switch to measure the rotation of the motor shaft, and the performance of the switch was poor. A debouncing system was developed that prevented input captures to occur for a specified time after the first input was detected. This approach uses an output

286 Chapter 5 Programming Large 8-Bit Systems

compare channel, but it does not tie up the microcontroller to wait out any delay times during the debounce period. This program is not too removed from many of those encountered in the real world.

The organization of the program is similar to how most applications can be programmed, and the way in which the program was developed showed how most problems should be approached. The problem was broken down into a set of small operations that could each be handled easily. These different parts of the program were developed, tested, and debugged separately. This approach keeps the development of the individual parts of the program manageable, and debugging is not too difficult. If the whole program were written and then debugging started, it would have been nearly impossible to separate out the effects of one part of the program on the others. The main interrupt service routines were written first and tested as well as possible by themselves. With these important functions behind us, it was easy to attack the applications portion of the program in which the closed loop system was implemented along with the management of the input/output through the serial port of the device.

The MC68HC11 is a powerful enough computer that it is possible to make an ANSI compliant compiler. Parameters can be passed to functions on the stack, and re-entrant or recursive functions can be written for this part as was demonstrated with the dprint() function. Remember, it is the microcontroller that limited the ANSI compliance with the MC68HC05—not the compiler.