Page 140 - Programming Microcontrollers in C
P. 140

What are Microcontrollers?    125

                          are numerous excellent, fast microcontrollers constructed with the Von
                          Neumann architecture. The Von Neumann architecture has been the
                          mainstay of microcontrollers and will be the only microcontroller
                          configuration available for the foreseeable future.
                              A microcontroller has its program stored internally, and the ALU
                          reads an instruction from memory. This instruction is decoded by the
                          ALU and executed. At the completion of the execution of the
                          instruction, the next instruction is fetched from memory and it is
                          executed. This procedure is repeated until the end of the program is
                          found, or the program gets into a loop where it is instructed to branch
                          back to a beginning point. In this case, the machine will stay in the
                          loop forever or until something happens to release it from the
                          never-ending loop.
                              There are three ways for a machine locked in a loop to be removed
                          from the loop so it can execute code outside of the loop. These
                          operations are called exceptions. The first is to reset the part with a
                          reset signal. A reset signal usually requires connecting the reset pin
                          of the part to a logic low signal. A logic low is usually ground. When
                          this condition is detected, several internal registers are set to
                          predetermined values, and the microcontroller fetches the address of
                          the reset routine from a specific memory location. This address is
                          placed in the program counter, and the program starts to execute.
                          There is a table in memory that contains the addresses of several
                          routines accessed when exceptions occur. These are the addresses of
                          the interrupt service routines, reset routines, etc. This table is called
                          the vector table, and the addresses are called vectors.
                              A second means of forcing the part out of the loop is for the part
                          to detect an external interrupt. An external interrupt occurs when the
                          interrupt request (IRQ) pin on the part is set low. This pin is tested at
                          the beginning of the execution of each instruction. Therefore, if an
                          instruction is being executed when an IRQ is asserted, the instruction
                          will complete before the IRQ signal is processed. Processing for the
                          IRQ consists of first determining if IRQs are enabled. If they are, the
                          status of the machine is saved. All interrupts are disabled by setting
                          the interrupt mask bit in the status register of the microcontroller.
                          Then the address stored in the IRQ vector location is fetched. This
                          address, the address of the interrupt service routine (ISR), is placed
                          in the program counter. The ISR then executes.
   135   136   137   138   139   140   141   142   143   144   145