Page 181 - Programming Microcontrollers in C
P. 181

166    Chapter 4  Small 8-Bit Systems

                          compile individually and examine if they create outlandish code. Once
                          these small functions are all debugged, you can integrate them into
                          your program as either inline code or as function calls. Hence, the
                          fundamental rule of writing good high-level code for a
                          microcontroller: the production of good C code for a microcontroller
                          is a joint effort between the programmer and the compiler writer.
                              Erasure of EEPROM causes component wear, and most EEPROMs
                          will wear out after a large number of erasures. The nature of the deg­
                          radation is that the component refuses to erase after many erasures.
                          There has been no evidence that data retention is affected by repeated
                          erasures. The number of erasures that can cause problems is tempera­
                          ture sensitive. Most of these devices are rated for 10,000 write/erase
                          cycles at the maximum rated temperature for the part. At room tem­
                          perature, the number of write/erase cycles without damage can grow
                          to several hundred thousand. In light of these facts, it is important that
                          programs use care in rewriting the contents of EEPROM.


                          EXERCISES
                          1. The EEPROM in microcontrollers erase to the 1 state. Write a
                            function that checks to determine if an erasure cycle erases the
                            contents of a given location in memory.

                          2. Write a function that compares data to be programmed into
                            EEPROM and determine if it is necessary to erase a byte contain­
                            ing data before it is reprogrammed. This approach will extend the
                            life of the EEPROM.


            Timers

                              The systems of timers placed on microcontrollers are among the
                          most creative engineering efforts most people will ever see. The func­
                          tions of these timers cover literally dozens of different operations.
                          This set of peripheral components mainly relieve the computer of
                          much work associated with execution of the peripheral function. We
                          will start with the simplest timer and outline different timer capabili­
                          ties in increasing complexity. The most basic timer in the M68HC05
                          family is called the 15-bit timer, and probably the most advanced
                          timer system is the 16-bit timer. These different timer systems are
                          literally unrelated in the features they offer. Another timer feature
   176   177   178   179   180   181   182   183   184   185   186