Файл: Single- and Multi-Chip Microcontroller Interfacing For the Motorola 68HC12 (G.J. Lipovski, 1999).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 15.06.2025
Просмотров: 774
Скачиваний: 2
List of Tables
Table Title |
Page |
Table 1.1. Addressing Modes for the 6812 |
II |
Table 1.2. 6812 Move Instructions |
17 |
Table 1.3. 6812 Arithmetic Instructions |
19 |
Table 1.4. 6812 Logic Instructions |
21 |
Table 1.5. 6812 Edit Instructions |
22 |
Table 1.6. 6812 Control Instructions |
23 |
Table 1.7. Assembly-LanguageDirectives for the 6812 |
29 |
Table 2.1. Conventional C Operators Used in Expressions |
47 |
Table 2.2. Special C Operators |
49 |
Table 2.3. Conditional Expression Operators |
49 |
Table 2.4, ASCII Codes |
60 |
Table 3.1. Address Map for a Microcomputer |
108 |
Table 3.2. Outputs of a Gate |
116 |
Table 3.3. Another Address Map for a Microcomputer |
117 |
Table 4.1. Traffic Light Sequence |
149 |
Table 4.2. LCD Commands |
165 |
Table 5.1. Interrupt Vectors in the 6812 |
228 |
Table 7.1. Characteristics of the CA3140 |
321 |
Table 8.1. PWM Channel Ports |
369 |
Table 8.2. Touch-tone Codes |
370 |
Table 9.1. RS-232 Pin Connections for D25P and D25S Connectors |
404 |
Table 9.2. ACIA Control and Status Bits |
415 |
xxi
Acknowledgments
The author would like to express his deepest gratitude to everyone who contributed to the evelopment of this book. The students of EE 345L at the University of Texas at Austin uring Fall 1998 significantly helped correct this book; special thanks are due to Levent Og, Ed Limbaugh, and Greg McCasKill, who located most of the errors. This text was repared and run off using a Macintosh and LaserWriter, running WriteNow. I am pleased o write this description of the Motorola 6812, which is an incredibly powerful omponent and a vehicle for teaching a considerable range of concepts.
G. J. L.
xxu
1.1 An Introductionto the Microcomputer
Input/output
Figure 1.1. Analogy to the von Neumann Computer
to an organization as a partial name without the suffix, for example, the MC68HC812A4 (without PV8), which we abbreviate as 'A4, or the MC68HC912B32, abbreviated as 'B32 and refer to the architecture as a number 6812. This should clear up any ambiguity, while also being a natural, easy-to-read shorthand.
The architecture of von Neumann computers is disarmingly simple, and the following analogy shows just how simple. (For an illustration of the following terms, see Figure 1.1.) Imagine a person in front of a mailbox, with an adding machine and window to the outside world. The mailbox, with numbered boxes or slots, is analogous to the primary memory; the adding machine, to the data operator (arithmetic-logic unit); the person, to the controller; and the window, to input/output (I/O). The person's hands access the memory. Each slot in the mailbox has a paper that has a string of, say, eight Is and Os (bits) on it. A string of 8 bits is a byte. A string of bits - whether or not it is a byte - in a slot of the memory box is called a word.
The primary memory may be in part a random access memory (RAM) (so-called because the person is free to access words in any order at random, without having to wait any longer for a word because it is in a different location). RAM may be static ram (SRAM) if bits are stored in flip-flops, or dynamic ram (DRAM) if bits are stored as charges in capacitors. Memory that is normally written at the factory, never to be rewritten by the user, is called read-only memory (ROM). A programmable read-only memory (PROM) can be written once by a user, by blowing fuses to store bits in it. An erasable programmable read-only memory (EPROM) can be erased by ultraviolet light and then written electrically by a user. An electrically erasable programmablereadonly memory (EEPROM) can be erased and then written by a user, but erasing and writing words in EEPROM takes several milliseconds. A variation of this memory, called flash, is less expensive but cannot be erased one word at a time.
With the left hand the person takes out a word from slot or box n, reads it as an instruction, and replaces it. Bringing a word from the mailbox (primary memory) to the person (controller) is called fetching. The hand that fetches a word from box n is analogous to the program counter. It is ready to take the word from the next box, box n + 1, when the next instruction is to be fetched.
1.1 An Introduction to the Microcomputer |
5 |
Now that we have some ideas about instructions, we resume the analogy to illustrate some things an instruction might do. For example, an instruction may direct the controller to take a word from a box m in the mailbox with the right hand, copy it into the adding machine (thus destroying the old word) and put the word back in the box. This is an example of an instruction called the load instruction. In the 6812 an instruction to load accumulator A with the word at location 256 in decimal, or $100 in hexadecimal, is fetched as three words
$B6 $01 $00
where the second word is the most significant byte, and the third is the least significant byte, of the address and is represented by mnemonicsas
LDAA $100
in assembly language. The main operation - bringing a word from the mailbox (primary memory) to the adding machine (data operator) - is called recalling data. The right hand is used to get the word; it is analogous to the effective address.
As with instructions, assembly language uses a shorthand to represent locations in memory. A symbolic address, which is actually some address in memory, is a name that means something to the programmer. For example, location $100 might be called ALPHA. Then the assembly-language instruction above can be written as follows
LDAA ALPHA
We will be using the symbolic address ALPHA in most of our examples in this chapter, and it will represent location $100. Other symbolic addresses and other locations can be substituted, of course. It is important to remember that a symbolic address is just a representation of a number, which usually happens to be the numerical address of the word in primary memory to which the symbolic address refers. As a number, it can be added to other numbers, doubled, and so on. In particular, the instruction
LDAA ALPHA+1
will load the word at location $101 (ALHPA + 1 is $100+1) into the accumulator. Generally, after such an instruction has been executed, the left hand (program
counter) is in position to fetch the next instruction in box n + 1. For example, the next instruction may give the controller directions to copy the number in the adding machine into a box in the mailbox, causing the word in that box to be destroyed. This is an example of a store instruction. In the 6812, the instruction to store accumulator A into location $100 can be written like this
STAA ALPHA
The main operation in this store instruction - putting a word from the adding machine (data operator) into a box in the mailbox (primary memory) - is called memorizing data. The right hand (effective address) is used to put the word into the box.
6 |
Chapter 1 Microcomputer Architecture |
Before going on, we point out a feature of the von Neumann computer that is easy to overlook, but is at once von Neumann's greatest contribution to computer architecture and yet a major problem in computing. Because instructions and data both are stored in the primary memory, there is no way to distinguish one from the other except by which hand (program counter or effective address) is used to get the data. We can conveniently use memory not needed to store instructions - if few are to be stored - to store more data, and vice versa. It is possible to modify an instruction as if it were data, just before it is fetched, although a good computer scientist would shudder at the thought. However, through an error (bug) in the program, it is possible to start fetching data words as if they were instructions, which produces strange results fast.
A program sequence is a sequence of instructions fetched from consecutive locations one after another. To increment the word at location $100, we can load it into the accumulator using the LDAA instruction, increment it there using the INCA instruction, and then put it back using the STAA instruction. (A better way will be shown in the next section, but we do it in three instructions here to illustrate a point.) This program sequence is written in consecutive lines as follows
LDAA ALPHA
INCA
STAA ALPHA
Unless something is done to change the left hand (program counter), a sequence of words in contiguously numbered boxes will be fetched and executed as a program sequence. For example, a sequence of load and store instructions can be fetched and executed to copy a collection of words from one place in the mailbox to another place. However, when the controller reads the instruction, it may direct the left hand to move to a new location (load a new number in the program counter). Such an instruction is called a jump, which is an example of a control instruction. Such instructions will be discussed further in §1.2.3, where concrete examples using the 6812 instruction set are described. To facilitate the memory access functions, the effective address can be computed in a number of ways, called addressing modes. The 6812 addressing modes will be explained in §1.2.1.
1.1.2 The Instruction
In this section the concept of an instruction is described from different points of view. The instruction is discussed first with respect to the cycle of fetching, decoding, and sequencing of microinstructions. Then the instruction is discussed in relation to hardware-software trade-offs. Some concepts used in choosing the best instruction set are also discussed.
The controller fetches a word or a couple of words from primary memory and sends commands to all the modules to execute the instruction. An instruction, then, is essentially a complex command carried out under the direction of a single word or a couple of words fetched as an inseparable group from memory.