Page 129 - Understanding Automotive Electronics
P. 129

2735 | CH 4  Page 116  Tuesday, March 10, 1998  11:06 AM



                4                     MICROCOMPUTER INSTRUMENTATION AND CONTROL




                                          The special memory locations pointed to by the stack pointer are called
                                      stacks; if one considers memory locations as being slots stacked one atop the
                                      other, it makes sense to think of the stack pointer stacking data like plates on a
                                      shelf.
                When the subroutine is    After the program counter has been incremented and saved, the jump
                completed, a return   address is loaded into the program counter (step 9). The jump to the
                instruction retrieves the   subroutine is made, and the CPU starts running the subroutine (step 10).
                saved program counter   The only thing that distinguishes the subroutine from another part of the
                value from the stack   program is the way in which it ends. When a subroutine has run to
                pointer and loads it into   completion, it must allow the CPU to return to the point in the main
                the program counter.   program from which the jump occurred. In this way, the main program can
                Execution of the main   continue without missing a step. The return-from-subroutine (RTS)
                program then resumes   instruction is used to accomplish this. It is decoded by the instruction
                from the point at which   register, and increments the stack pointer as shown in Figure 4.11, step 1. It
                the jump occurred.    uses the stack pointer to address the stack memory to retrieve the old
                                      program counter value from the stack (steps 2 and 4). The old program
                                      counter value is loaded into the program counter register (steps 3 and 5),
                                      and execution resumes in the main program (step 6). The return-from-
                                      subroutine instruction works like the jump-to-subroutine instruction,
                                      except in reverse.

                                      EXAMPLE USE OF A MICROCOMPUTER
                                          Let’s look at an example of how a microcomputer might be used to
                                      replace some digital logic, and along the way learn about some more
                                      microcomputer instructions.
                Microcomputers can be     The digital logic to be replaced in this example is a simple AND gate
                used in place of discrete   circuit. Now, no one would use a microcomputer to replace only an AND gate,
                logic circuits such as   because an AND gate costs a fraction of what a microcomputer costs. However,
                AND gates.            if the system already has a microcomputer in it, the cost of the AND gate could
                                      be eliminated by performing the logical AND function in the computer rather
                                      than with the gate. This is a perfectly legitimate application for a
                                      microcomputer and is something that microcomputers do very well. Moreover,
                                      this example well illustrates the use of a microcomputer.
                                          Suppose there are two signals that must be ANDed together to produce
                                      a third signal. One of the input signals comes from a pressure switch located
                                      under the driver’s seat of an automobile; its purpose is to indicate whether
                                      someone is occupying the seat. This signal will be called A, and it is at logical
                                      high when someone is sitting in the seat. Signal B is developed within a
                                      circuit contained in the seat belt and is at logical high when the driver’s seat
                                      belt is fastened. The output of the AND gate is signal C. It will be at logical
                                      high when someone is sitting in the driver’s seat and has the seat belt
                                      fastened.




                116                   UNDERSTANDING AUTOMOTIVE ELECTRONICS
   124   125   126   127   128   129   130   131   132   133   134