Basic Computer Structure (Microcontrollers)

1.1
What is a microcomputer, and how does it execute the instructions that a programmer writes for it? This question is explored now at a level of abstraction that will be adequate for this text. We do know that many readers will object to one aspect of the following
discussion, and we want to answer that objection a priori, so that those readers will not miss the point. We will introduce a seemingly large number of terms. Don’t miss the objective: We are really introducing concepts. The reader should think about the concepts rather than memorize definitions. Like your physics text, this text has to use terms in a fairly precise way to avoid ambiguity. Your physics text, you may recall, used the word “work” in a very precise way, as the product of force times distance, which is a bit different from the conversational use of the word “work” as used in the expression, “He’s doing a lot of work.” We will use terms such as “read” and “fetch” in a similar way. When defined, they will be written in italics and will be listed in the index. We ask you to learn the term and its meaning even though you do not have to memorize the wording of the definition. But take heart, because although we do have a few concepts that have to be learned, and we have to learn the terms for those concepts, we do not have many formulas or equations to deal with. Accept our challenge to understand these terms; then you will enjoy the latter discussions even more than if you muddle through this section without thinking about the terminology.
You probably know what microcomputers and computers are, to some degree, but let us discuss the term “computer” so that if you get into an argument about whether a hand calculator is a computer, you can respond knowledgeably.
A microcomputer is a kind of computer or, more accurately, a kind of von Neumann computer, named after the scientific giant of our century who invented it. All von Neumann computers have four components: memory, controller, data operator (sometimes called an arithmetic-logic unit), and input-output (I/O), which are connected by an address and data bus. A simplified diagram of a computer is shown in Figure 1.1. Briefly, the memory stores both the data and the program, and the input-output provides the communication with the outside world. In a conventional personal computer system input-output is done through peripherals such as CRTs, keyboards, scanners, printers, modems, and so on. In typical microcontroller applications the input-output system provides the necessary connections, or interfacing, to the device, of which the microcontroller is a component, such as an automobile, kitchen appliance, toy, or laboratory instrument. The data operator performs arithmetic and logical operations on data, such as addition, ANDing, and so on. The controller controls the flow of information between the components by means of control lines (which are not shown in Figure 1.1), directing what computation is to be done. The input/output, controller, and data operator may themselves contain a small amount of memory in registers.
A microcomputer is a computer that is implemented using low-cost integrated circuits (ICs) and is therefore cheap enough to be used in an incredible range of applications where a large computer would be infeasible. For the purposes of this topic, if the data operator and the controller are together on a single IC, but other ICs are needed to complete the computer, that IC is called a microprocessor, the computer that uses a
Simplified Computer Structure
Figure 1.1. Simplified Computer Structure
microprocessor is called a microcomputer; and, if a complete computer is on a single integrated circuit, that integrated circuit is called a single-chip microcontroller.
Some aspects of microcomputers apply to all computers. We will often discuss an aspect of the computer and, of course, that aspect applies to microcontrollers, on which we are concentrating. The microcomputer’s, or microcontroller’s, controller and data operator is abbreviated MPU (microprocessor unit). The abbreviation CPU (central processor unit) is often used to denote the controller and data operator, but that term leads subtly to the idea that the CPU is central and most important; but this is misleading, especially when a computer system has many MPUs, none of which is “central.”
We now look more closely at the memory and the MPU. We can think of the memory as a large number of cells, each able to store a 0 or a 1 — that is, a binary digit or one bit of memory. The bits are grouped together in units called bytes, which consist of 8 bits. Within a particular byte the bits are labeled b7, . . ., bO as shown.
tmpC-2_thumb
The right-hand bits are called lower-order or least significant, and the left-hand bits are called higher-order or most significant. There is nothing sacred about this labeling, and, in fact, many computer manufacturers reverse it. A word in memory is the number of bits that are typically read or written as a whole. In small microcomputers, a word is one byte, so that the terms “word” and “byte” are often used interchangeably. In this text, the 6812 can read an 8-bit or a 16-bit word, which is two bytes. In a 16-bit word, bits are numbered from 15 (on the left) to 0 (on the right). In the memory, each byte has an address between 0 and 2N -1, where N is the total number of address bits. In the 6812, N is essentially 16, so each address between 0 and 65,535 is described by its 16-bit binary representation (see Appendix 1), although some 6812 versions can extend this range.
The MPU controls the memory by means of a clock and a read/write line, and communicates to it by an address bus and a data bus, shown in Figure 1.1. A line or wire carries one bit of information at each instance of time by the level of voltage on it. Each line can carry a true (1) or a false (0) value. A bus is a collection of lines that can move a word or an address in parallel, so that one bit of a word or address is on one line of the bus. The data bus moves an 8-bit or 16-bit word to or from memory and from or to the MPU, and the address bus moves a 16-bit address from the MPU to the memory. A clock is a signal that is alternately a 0 and 1 (a square wave). A clock cycle is the time interval from when the clock just becomes 0 until the next time it just becomes 0, and the clock rate, or clock frequency, is the reciprocal of the clock cycle time. Contemporary 6812 microcontrollers essentially use an 8 MHz clock.
In one clock cycle, the MPU can read a word from the memory by putting an address on the address bus and making the read/write line 1 for the cycle and then picking up the word on the data bus at the end of the cycle. It can also write a word into the memory in one clock cycle by putting the address on the address bus and putting the word on the data bus and making the read/write line 0 for the cycle. A read or a write to memory is also called an access to memory.
We can enlarge our description of how the memory works. Assume that we want to get the contents of a particular word or byte from memory, that is, read a word from memory. The MPU first puts a 1 for read on the read/write line and then puts the address of the desired word or byte on the address bus throughout the duration of a clock cycle. The memory is designed so that, at the end of the clock cycle, the desired word is put on the data bus. The MPU then places a copy of the contents of the word or byte on the data bus into some register inside the MPU as required by the instruction that it is executing. This is done without changing the contents in memory of the word or byte addressed.
To write a word into memory, the address of the word is put on the address bus, the word is put on the data bus, and the read/write line has 0 (to indicate a write) for a full clock cycle. The memory is designed to store the word at that address at the end of the clock cycle. After the word is stored at the given address, the MPU may still retain in one of its registers a copy of the word that has just been written.
The MPU can read or write an 8-bit or a 16-bit word in memory in one clock cycle. Such a memory is usually called random access memory or RAM because each byte is equally accessible or can be selected at random without changing the time of the access. With microcomputer applications, it is not unusual to have part of the memory bytes in ROM (read only memory). A ROM is capable of a read operation but not a write operation; its words are written when it is made at the factory and are retained even when the power is turned off. If the data in a RAM are lost when power is turned off, the RAM is termed volatile; otherwise, it is termed nonvolatile. RAM memories are essentially volatile. The term RAM is also used almost universally to imply memories that you can read and write in, even though ROM memories can be randomly accessed with a read operation. The part of memory that is in ROM is typically used to store a program for a microcomputer that only executes one program. For example, the microcontroller used in an automobile would be running the same program every time it is used, so that the part of the memory that is used for storing the program is in ROM.


Next post:

Previous post: