Chapter 1
Introduction to Microcontrollers
(I. Scott Mackenzie)

Computers have only been with us for a few decades but their impact (direct or indirect) on our lives is profound.
Usually these are supposed to be just data processors performing exhaustive numeric operations. But there presence is unnoticed at most of the places; like
At supermarkets in Cash Registers, Weighing Scales, etc.
At home in Ovens, Washing Machines, Alarm Clocks, etc.
At play in Toys, VCRs, Stereo Equipment, etc.
At office in Typewriters, Photocopiers, Elevators, etc.
In industry in Industrial Automation, safety systems, etc.
On roads in Cars, Traffic Signals, etc.

Computers can be divided into following two main types depending on their function
General purpose (Not Transparent)
Special purpose (Transparent)
Microcontrollers are more suitable for special purpose devices.
Microcontroller is a device similar to microprocessor but includes more circuitry in the same chip.

A computer is defined by two main qualities
The ability to be programmed to operate on data without human intervention
The ability to store and retrieve data.
Computers also have peripheral devices to communicate with outside world.

Block Diagram of Microcomputer System

Central Processing Unit (CPU)
Brain of the computer system, administers all activity in the system and performs all operations on data.
Continuously performs two operations: fetching and executing instructions.
Understand and execute instructions based on a set of binary codes called the instruction set.

Simplified Block Diagram of CPU

Fetching & Executing An Instruction
Fetching involves the following steps:
Contents of PC are placed on address bus
READ signal is activated
Data (instruction opcode) are read from RAM and placed on data bus
Opcode is latched into the CPU’s internal instruction register
PC is incremented to prepare for the next fetch from memory
Execution involves decoding the opcode and generating control signals to gate internal registers in and out  of the ALU and to signal the ALU to perform the specified operation.

The Buses: Address, Data, & Control
A bus is a collection of wires carrying information with a common purpose.
For each read or write operation, the CPU specifies the location of the data or instruction by placing an address on the address bus, then activates a signal on the control bus indicating whether the operation is read or write.
Read operations retrieve a byte of data from memory at the location specified and place it on the data bus. CPU reads the data and places it in one of its internal registers.
Write operations put data from CPU on the data bus and store it in the location specified.

The Buses (contd.)
Address bus carries the address of a specified location. For n address lines, 2^n locations can be accessed. E.g., A 16-bit address bus can access 2^16 = 65,536 locations or 64K locations (1K = 2^10 = 1024).
Data bus carries information between the CPU and memory or between the CPU and I/O devices. Computers spend up to two-thirds of their time simply moving data, so the number of lines of the data bus is important for overall performance. This limitation by width of data bus is a bottleneck even with a vast amount of memory on the system and a high speed CPU. 16-bit computer means…?
Control bus carries control signals supplied by the CPU to synchronize the movement of information on the address and data bus.

Input/Output Devices
I/O devices or computer peripherals provide the path for communication between the computer system and the real world. Three main types:
Mass Storage Devices (Hard disk, magnetic tape, CD-ROM, etc.)
Human Interface (Keyboard, mouse, joystick, CRT, printer, speaker, etc.)
Control/Monitor devices (Phototransistors, sensors,  thermistors, switches, motors, relays, etc.)
Control devices are outputs, or actuators, that can affect the world around them when supplied with a voltage or current.
Monitoring devices are inputs, or sensors, that are stimulated by temperature, pressure, light, motion, etc. and convert this to voltage or current read by the computer.
The interface circuitry converts the voltage or current to binary data, or vice versa.

Computer Classification
Computers can be classified by their size and power as microcomputers, minicomputers, or mainframe computers.
Microcomputers contain single chip CPU (microprocessor).
Minicomputers contain CPU consists of several chips.
Mainframes contain CPU consists of several circuit boards of chips.
Microcomputers are single-user, single-task systems while minicomputers, and mainframe computers are multi-user and multitasking systems.

Microprocessors Vs. Microcontrollers
Microprocessor is a single chip CPU, microcontroller contains, a CPU and much of the remaining circuitry of a complete microcomputer system in a single chip.
Microcontroller includes RAM, ROM, serial and parallel interface, timer, interrupt schedule circuitry (in addition to CPU) in a single chip.
RAM is smaller than that of even an ordinary microcomputer, but enough for its applications.
Interrupt system is an important feature, as microcontrollers have to respond to control oriented devices in real time. E.g., opening of microwave oven’s door cause an interrupt to stop the operation.
(Most microprocessors can also implement powerful interrupt schemes, but external components are usually needed.)

Microprocessors Vs. Microcontrollers (contd.)
Microprocessors are most commonly used as the CPU in microcomputer systems. Microcontrollers are used in small, minimum  component designs performing control-oriented activities.
Microprocessor instruction sets are “processing intensive”, implying powerful addressing modes with instructions catering to large volumes of data. Their instructions operate on nibbles, bytes, etc. Microcontrollers have instruction sets catering to the control of inputs and outputs. Their instructions operate also on a single bit. E.g., a motor may be turned ON and OFF by a 1-bit output port.

Gains and Losses
Gains: Reduced component count in a circuit, high degree of integration, shorter development time, lower manufacturing cost, lower power consumption, higher reliability, etc.
Losses: Some situations (very few) require extremely fast response to events are poorly handled by the microcontrollers. E.g., Implementation of NAND operation using an 8051 microcontroller.
ANL C, P1.5 ;AND WITH P1.5
ANL C, P1.6 ;AND WITH P1.6

Gains and Losses (contd.)
The propagation delay can be measured by  a voltmeter or by an oscilloscope. It is 3 microsecond (assuming 8051 operation using 12 MHz crystal frequency) while equivalent TTL has delay of 10 nanosecond.