Page 167 - Programming Microcontrollers in C
P. 167

152    Chapter 4  Small 8-Bit Systems

                              Another useful directive pair is the #asm and the #endasm.
                          The code enclosed in a block that starts with #asm and ends with
                          #endasm must be in standard assembly language. Variables defined
                          in the C program can be used safely.
                                 C can accomplish almost everything that the assembly lan­
                          guage program can. You will find that the C6805 compiler will create
                          tight, efficient code that is probably as good as can be written by a
                          competent assembly programmer. There are, however, some items that
                          are absolutely foreign and inaccessible to a compiler. A compiler cre­
                          ates code for an abstract machine that does not exist in reality.  The
                          usual registers found in the real machine are nonexistent in the abstract
                          machine. For example, it is not possible to access the status register of
                          the microcontroller with compiled code. Usually, status register con­
                          tents are not directly important to the conduct of the program. But
                          later we’ll see an example where the ability to manipulate the carry bit
                          of the status register can save many bytes of code. Therefore, it is
                          important to be able to use some assembly code as well as C.
                              This chapter will concentrate on small 8-bit microcontrollers.
                          Subsystems such as timers, analog-to-digital converters, computer
                          operating properly (COP) timers, etc., found on the 8-bit systems
                          will be outlined and their programming discussed. While the main
                          details of the central processor in the microcontroller are important
                          to the assembly language programmer, they are of little interest to
                          the C programmer. This observation is true at least at the C level. If it
                          becomes necessary to enter an assembly language program for opti­
                          mization of code size or other considerations, then the programmer
                          is required to have detailed knowledge of the programming model
                          and the internal architecture of the computer.
                              Let’s start by discussing important microcontroller peripheral
                          components that you can expect to find. We’ll begin with what is
                          probably the most important single consideration in the selection of
                          a microcontroller to do a job—the device memory. This discussion
                          will be followed by sections on other important peripherals such as
                          timers, analog-to-digital and digital-to-analog converters, serial com­
                          munications devices, and simple digital input/output lines.
   162   163   164   165   166   167   168   169   170   171   172