microprocessor systems handouts 2013

Upload: yunus-memon

Post on 08-Jan-2016

226 views

Category:

Documents


0 download

DESCRIPTION

Microprocessor Systems Handouts 2013

TRANSCRIPT

HIGHER COLLEGE OF TECHNOLOGYDEPARTMENT OF ENGINEERINGELECTRICAL POWER, BIOMEDICAL, COMPUTER AND TELECOMMUNICATION ENGINEERING

HANDOUTS FOR THE COURSE:

MICROPROCESSORS SYSTEMS AND INTERFACING (EECP3171)

Prepared by: FALAH H. JAWAD

Chapter OneIntroduction to Microprocessors, Microprocessor-Based Systems, Microcomputers, and Microcontrollers

1.1 THE MICROPROCESSOR: [1]

The microprocessor is a semiconductor digital integrated circuit. It has the same structure of a Central Processing Unit (CPU) for a computer. It consists of a number of digital computing circuits (which constitute the Arithmetic Logic Unit ALU), a number of control and timing circuits (which constitute the Control Unit) as well as a number of storage elements (called the registers). This structure enables the microprocessor to perform the same computing and control functions of a CPU. The microprocessor can execute programs and can control most of the parts of a computer. Any program consists of a number of microprocessor instructions which are stored as binary codes (called machine language). These instructions enable the microprocessor to do different arithmetic, logical, data-processing, compute and control operations. Also, the microprocessor can interact with and control external devices that are connected with it.Usually the microprocessor is connected to a main external memory, external I/O interfaces (ports) and devices, a clock generator circuit and a dc supply to form a microprocessor-based system.

1.2 THE MICROPROCESSOR-BASED SYSTEM: [2]

A microprocessor-based system is a system in which a microprocessor is used as the main part that does most operations of the system through the programs that it is executing. Most old systems were hardware-based systems in which hardware parts and circuits are designed and used to perform the functions of the system. Any changes or additions to these functions require changing or adding more hardware to the system. So, hardware-based systems are complex and less flexible systems.On the contrast, a microprocessor-based system is a much more flexible system, where one hardware is used to perform a large number of functions just by executing different software. Also microprocessor-based systems are less expensive, much reliable, easily maintained, consume low power and usually have small sizes.Now, microprocessor-based systems are used everywhere for many applications in all areas. Some areas and applications of these systems are:a. Computers: All CPUs of current computers (desktops, servers and embedded computers) are microprocessors. Also, computer hardware parts like printers, scanners, network switches ..etc are controlled by microprocessors or microcontrollers.b. Telecommunications: Mobiles, digital telephones and exchanges, networks devices, satellites .etc.c. Medical Equipment: ECG, EEG, Patient Monitoring Systems, Sonar Systems, Medical Lab Systems.etc.d. Electrical Power Systems: Power stations control, machine drives, power protection and control systems, UPSs (Uninterruptable Power Supplies) etc.e. Military and Defense Systems: Guided missiles, radars, .etc. f. Control: From simple systems like microwaves, TVs, washing machines to complex systems like robots and factory control.g. Consumer and Entertainment: Toys, Play stations .etc.h. Office Automation, Publications and Media: Photocopy machines, printers, publication and media equipment ..etc.i. Instrumentation: Function generators, Spectrum Analyzers, Logic Analyzers, .etc.

1.3 THE FEATURES OF DIFFERENT MICROPROCESSORS: [2]

Since Intel introduced its first 4-bit microprocessor (Intel 4004) in 1970, there have been great advances in microprocessors. Now, hundreds types of microprocessors are manufactured by different manufacturers with different capabilities and features. Some of the features that differentiate types of microprocessors are:a. The Instruction Set Architecture (ISA) of the microprocessor. It is the actual programmer visible instruction set, addressing modes, size of operands, I/O mechanism and types of operations performed by the microprocessor.b. The class of the ISA. Microprocessors are now designed under two classes of ISAs. These are CISC (Complex Instruction Set Computer) and RISC (Reduced Instruction Set Computer) architectures. c. The microprocessor organization (Microarchitecture). It is how the hardware implements the ISA. This includes the logic design of the microprocessor, how many cores (CPUs) the microprocessor chip contains, its functional units, the size and design of cache memory and physical registers inside the microprocessor, as well as the number and design of pipelines inside the microprocessors.d. The processor word length. It is the maximum length of data word that internally the microprocessor can process at the same time (8-bit, 16-bit, 32-bit or 64-bit). It is usually reflected by the design of its ALUs and by the size of its internal registers.e. The size of the external main memory that can be connected with the microprocessor (1Mbyte, 100Mbyte, 1Gbyte, 4Gbyte, 64Gbyte). Also, the number of I/O ports (interfaces) that can be connected with the microprocessor.f. The maximum frequency of the clock that drives the microprocessor (10MHz, 20MHz, 500MHz, 4GHz).g. The dc voltage needed to operate the microprocessor and its consumed power.

Some of manufactures of microprocessors with some types are:a. Intel. Like Pentium 4, Core i3, Core i5, Core i7, Xeon, Itanium 2.b. AMD. Like Phenom, Opteron.c. Motorola. Like MC6800, MC68020.d. IBM. Like PowerPC, POWER 5.e. Hitachi. Like SuperH.f. ARM. Like SC100, Cortex-A.

1.4 CASE STUDY OF A MICROPROCESSOR-BASED SYSTEM: THE MICROCOMPUTER: [2]

The microcomputer is a computer which its CPU is a microprocessor. The basic parts of any microcomputer are shown by the block diagram in figure 1.1.

Figure 1.1 The Basic Architecture of a Microcomputer.

As well as the microprocessor, the microcomputer has a dc supply, a clock generator circuit, a main external memory, a number of input/output devices with their interfaces. These parts are connected together by a system of three busses: The address, data and control busses. We will explain the specifications and functions of these parts.1.4.1 The CPU (The Microprocessor): [2]The microprocessor is considered as the CPU of the microcomputer which performs the following main functions:a. Fetching program instructions one after another from memory then executing them and doing the arithmetic, logical, data-processing and other operations as specified by these instructions.b. Controlling almost all the parts of the microcomputer system.

As we have mentioned, the internal structure of any microprocessor includes the following basic parts:a. A number of control and timing circuits which constitute the Control Unit. This unit decodes the binary codes of instructions and gives the control signals needed to execute these instructions by the microprocessor internal parts. This unit also gives control signals to external parts. b. A number of digital computing circuits which constitute the Arithmetic Logic Unit ALU. In ALU the microprocessor performs arithmetic, logical and other data processing operations.c. A number of storage elements (called the registers). Registers represent the working space (temporary storage) in the microprocessor. The number and functions of registers vary between different microprocessor designs.

The external lines of any microprocessor are classified to: DC supply input lines, Ground lines, a clock input line (or direct crystal connection lines), an address bus (output), a data bus (input/output) and a control bus (input/output) as shown in figure 1.2.

Figure 1.2 The Classification of the Microprocessor External Lines.1.4.2 The DC Supply: [2]

It is used to supply DC voltages to the microprocessor and other parts of the microcomputer like +5v, -5V, +12v & -12v depending on their specifications.

1.4.3 The Clock Generator Circuit: [2]

It supplies the microprocessor with the clock which synchronizes all its internal and external operations. Without a clock, the microprocessor will remain at halt. Also, the clock determines the speed of the microprocessor operations. A crystal is connected with the clock generator circuit and it determines its frequency. In some microprocessors the clock generator circuit is inside the microprocessor, so, the crystal is directly connected with the microprocessor.

1.4.4 The Main Memory: [2]

It is an external memory used to store the binary codes of program instructions and data and results of operations. It consists of a number of semiconductor ICs, each IC has a certain storage size (1 Kbyte, 2 Kbyte..1 Megabyte). The main memory consists of two parts:RAM- (Random Access Memory): It is a read/write memory used by the system to store temporary programs, data and results.ROM- (Read Only Memory): It used to store the permanent programs of the microcomputer by the manufacturer of the system like monitor programs, Power-On Self-Test (POST) programs and BIOS.

1.4.5 The Input / Output Devices and I/O Interfaces: [2]

A number of I/O devices can be connected in a microcomputer like displays, printers, keyboards These devices are connected with the microprocessor through interfaces.An interface is a circuit which connects an I/O device with the microprocessor and makes it easier for the microprocessor to read or write data from/to the I/O device. These interfaces are usually called I/O ports.Interfaces can also perform some other functions like:

a. Providing the status of I/O device to the microprocessor (on, off, ready, ..).b. Providing a buffered storage for data sent from an input device to the microprocessor.c. Providing a latched storage for data sent from the microprocessor to an output device.d. Changing transferred data from serial-to-parallel or from parallel-to-serial.1.4.6 The System External Bus: [2]

The microprocessor is connected with memory and I/O ports through the system bus. A bus consists of a number of lines of the same function over which data or information is transferred from a source to a destination.The system bus consists of 3 buses: the address, data & control buses. Through these buses the microprocessor sends and receives data, instructions and control signals.

1.4.6.1 The Address Bus: [2]

It is a one-directional (unidirectional) bus, always output from the microprocessor and input to memory and I/O ports. This bus carries the address produced by the microprocessor in order to access memory locations or I/O ports for read/write operations. Each memory location or I/O port has one address. The number of lines in the address bus is different from one microprocessor to another.Ex: Intel 8086/8088 microprocessors have an address bus of 20 lines (A0- A19). So, the maximum size of memory that can be connected with these microprocessors is 220 =1 Megabyte). The address range of these locations is from 00000H to FFFFFH.

Problem: Intel Pentium 4 microprocessor has an address bus of 36 lines. Name these lines and calculate the maximum memory size that can be connected with this microprocessor.

1.4.6.2 The Data Bus: [2]

It is a two-directional (bidirectional) bus, input/output, to/from the microprocessor. It carries data to/from the microprocessor and memory and I/O ports.The number of lines in data bus is different from one microprocessor to another.Ex: Intel 8086 microprocessor has a data bus of 16 lines (D0- D15).Ex: Intel 8088 microprocessor has a data bus of 8 lines (D0- D7).Ex: Intel Pentium 4 microprocessor has a data bus of 64 lines (D0- D63).

1.4.6.3 The Control Bus: [2]

It is a two-directional (bidirectional) bus, input/output, to/from the microprocessor. Output control lines carry control signals from the microprocessor to external parts. These signals indicate the types of operations done by the microprocessor and synchronize the operations of the microprocessor with the external parts. Ex: RD, WR, IO/MInput control lines carry request signals from external parts to the microprocessor to do some operations them.Ex: INTR, RESET, BUS REQEST.

1.5 MAIN OPERATIONS PERFORMED BY MICROPROCESSORS IN SYSTEMS: [3]

In a microprocessor-based system, the microprocessor performs the following main types of operations.a. Program-Initiated Operations. These are the operations done by the microprocessor due to the program instructions that it is executing. From the moment when a DC supply and a clock are connected to the microprocessor, it will enter a continuous state of fetching instructions from memory then executing them. According to instructions, most microprocessors can do the following types of operations:

- Internal data operations like arithmetic, logical, test for conditions, data-processing and control operations.- Memory read- both for instructions and data.- Memory write- for data only.- I/O read- from an input port.- I/O write- to an output port.

For memory or I/O read or write operations, the microprocessor performs each operation in the following sequence of steps:i. First it puts the address of memory location or the I/O port on the address bus. This address will enable that location.ii. Then, it gives a control signal that specify the type of operation it is doing, read or write, with memory or an I/O port. This signal makes the memory or I/O port responds correctly and the operation will be synchronized properly.iii. Then data will transfer to or from the microprocessor through the data bus.

b. Peripheral (Externally) -Initiated Operations. These are the operations done by the microprocessor as a respond to external requests coming to the microprocessor through some of its input control lines from external devices (peripherals) connected with the microprocessor. The microprocessor will respond to some of these requests directly and unconditionally. For other requests, the microprocessor will not respond to them unless certain conditions are satisfied. If these conditions are not satisfied, the microprocessor will neglect these requests. So, in the microprocessor there is an output acknowledge line corresponding to each input conditional request line. Through this line the microprocessor indicates if it has accepted the request or not.Some of the important peripheral-initiated operations are: Reset, Interrupts, Bus Request and Wait.

RESET:When Reset request is activated, the microprocessor will stop all its operations and return back to the state when it is first turned on. It will return to the start of the permanent program in the ROM memory (usually the Monitor or POST program).Ex: When Intel 8086/8088 RESET line is activated, the microprocessor will restart its program execution from the address FFFF0H.

INTURRUPTS: External devices can interrupt the microprocessor. The microprocessor will suspend the execution of the current program and transfer to execute another program called Interrupt Service Routine. After completing this routine, the microprocessor will return to complete the original program. Some interrupts are Non-Maskable interrupts. The microprocessor will respond unconditionally to them. Other interrupts are Maskable interrupts. The microprocessor will respond to them when certain conditions are satisfied.

BUS REQUEST: Some external devices can request from the microprocessor to suspend for some time its control on external buses( address, data and part of control bus), so these devices can take control of these buses and use them to transfer data in a large quantity between memory and some I/O interfaces( like hard disk drives). This process is called Direct Memory Access (DMA) and devices that request bus control are called DMA Controllers. The microprocessor will respond unconditionally to this request. After DMA process complete, the DMA controller will inform the microprocessor to return to its control of the buses.

WAIT: This request causes the microprocessor to delay its operations not stopping them. This request used by slow I/O devices and memory in order to synchronize their operations with the microprocessor.

1.6 THE MICROCONTOLLER: [4]

Many manufacturers are now designing and implementing microcontrollers. Microcontrollers are now finding large number of applications with a growing market.A microcontroller is also a digital semiconductor integrated circuit that has a structure that enables it to perform computing and control functions. But, microcontrollers differ from microprocessors in many aspects:a. Microcontrollers are also actually processors that are designed to be used for dedicated applications (mainly control applications) like mobiles, automotive applications, home appliances, security systems, video games, printers, photocopiers, network switches, military and medical equipmentetc. On the other hand, microprocessors are considered as general purpose processors. b. RAM, ROM, I/O ports, and timers must be added externally to a microprocessor to enable it to perform its functions. On the other hand, a microcontroller is designed to be all of that in one. As well as the CPU (the processing module of the microcontroller), internally a microcontroller has a fixed amount of ROM and RAM, I/O parallel ports, a serial port, a timer (to allow the microcontroller to perform tasks for certain time periods), an Analog-to-Digital Converter (ADC) and may be other parts. Figure 1.3 shows the internal parts of a single chip microcontroller.

Figure 1.3 The internal parts of a single chip microcontroller.

c. The system in which a microcontroller is used is usually called an Embedded System, because in this system the microcontroller executes special application software that is typically burned into the internal microcontroller ROM. On contrast, microprocessors are usually used in Personal Computers that run a variety of software for many applications. The operating system loads a variety of applications into the external RAM and lets the microprocessor run them.d. But, microprocessors have the advantage of versatility on the amount of RAM, ROM, and I/O ports. For microcontrollers, the fixed amount of on-chip ROM, RAM, and number of I/O ports makes them ideal for applications in which cost and space are critical. In many applications, the space it takes, the power it consumes, and the price per unit are much more critical considerations than the computing power.

For microcontrollers, the CPU core are now ranging from simple 4-bit processors to sophisticated 32/64-bit processors. The following is a list of some available microcontrollers according to their manufacturer:

Atmel AT89 series (Intel 8051 architecture) AT90, ATtiny, ATmega, ATxmega series (AVR architecture) AT91SAM (ARM architecture) AVR32 (32-bit AVR architecture) MARC4 Intel 8-bit MCS-51 (8051 family) 16-bit MCS-96 (8096 family) Microchip TechnologyMicrochip produces microcontrollers with 3 very different architectures:a. 8-bit (8-bit data bus) PIC microcontrollers: PIC10 and PIC12 series: 12-bit instruction words. PIC16 series: 14-bit instruction words. PIC18 series: 16-bit instruction words.

b. 16-bit (16-bit data bus) microcontrollers: PIC24: 24-bit instruction words.

c. 32-bit (32-bit data bus) microcontrollers: PIC32MX series. Uses the MIPS architecture NXP Semiconductors 8-bit 80C51 16-bit XA 32-bit ARM9 ARM Cortex-M4 Texas Instruments TMS370 (8-bit) MSP430 Ultra-low-power 16-bit microcontroller TMS320F28xx (32-bit)

Chapter TwoAssembly Language Programming of Intel 8086/8088 Microprocessors

2.1 THE PROGRAMMING MODEL OF INTEL 8086/8088 MICROPROCESSORS: [1]

The programming module of a microprocessor consists of the microprocessor registers that are used and affected directly by its instructions. They are considered as the program visible registers. Both Intel 8086/8088 microprocessors has the programming model shown in figure 2.1.The word length of these microprocessors is 16-bit and their internal structure is approximately the same. The difference between them is in their external buses. Intel 8086 has a data bus 16-bit while 8088 has an 8-bit data bus. AX (16-bit)Accumulator RegisterGeneral Purpose Registers

AH (8-bit)AL (8-bit)

BX (16-bit)Base Index Register

BH (8-bit)BL (8-bit)

CX (16-bit)Count Register

CH (8-bit)CL (8-bit)

DX (16-bit)Data Register

DH (8-bit)DL (8-bit)

SP (16-bit)Stack Pointer Register

BP (16-bit)Base Pointer Register

SI (16-bit)Source Index Register

DI (16-bit)Destination Index Register

IP (16-bit)Instruction Pointer RegisterSpecial Purpose Registers

FLAGS (16-bit)Flags Register

CS (16-bit)Code Segment Register

DS (16-bit)Data Segment Register

SS (16-bit)Stack Segment Register

ES (16-bit)Extra Segment Register

Figure 2.1The Programming Model of Intel 8086/8088 Microprocessors2.1.1 The General Purpose (Multipurpose) Registers: [1]

These are eight registers: AX (Accumulator Register), BX (Base Index Register), CX (Count Register), DX (Data Register), SP (Stack Pointer Register), BP (Base Pointer Register), SI (Source Index Register) and DI (Destination Index Register). Each register has a size 16-bit. Registers AX, BX, CX, & DX can be used as 8-bit registers (AL, AH, BL, BH, CL, CH, DL & DH). Mainly, these registers are used in programs to hold data on which the instructions are performed as well as the results of these instructions. Some of them are used for addressing and others have special uses in programs as we will see later.

2.1.2 The Special Purpose Registers: [1]

These are six registers: IP (Instruction Pointer), FLAGS (Flags Register), CS (Code Segment Register), DS (Data Segment Register), SS (Stack Segment Register) and ES (Extra Segment Register). Each register has a size 16-bit. Each of these registers has a special use in programs and it cannot be used other than that.

a. IP (Instruction Pointer): This register gives the offset address of the next instruction in the program memory to be executed by the Execution Unit inside the microprocessor. When the Execution Unit receives an instruction for execution, IP will automatically change to point to the next instruction in the program. When the microprocessor is first powered ON or in case of its Reset, IP will hold the address 0000H. This register can only be modified using Jump or Call instructions.

b. FLAGS (Flags Register): Each flip-flop in this register will be Set or Reset to indicate a certain case that may happen after the microprocessor executes some instructions like arithmetic and logical instructions. These flags can be tested by other instructions in the program in order that the microprocessor takes some decisions according to the states of Flags. Some of these flags that we will use in our programs are:

CF (Carry Flag). It sets (CF=1) when a carry out of the MSB (Most Significant Bit) results from addition instruction or borrow from subtraction. Otherwise it will reset (CF=0).

Ex: 10111101 + 11101001 Carry (CF=1) 1 10100110 ZF (Zero Flag). It sets (ZF=1) if the result from an instruction is equal to zero, otherwise it will reset (ZF=0). SF (Sign Flag). It sets (SF=1) if the result is a negative number (Its MSB=1). It will reset (SF=0) if the result is a positive number (Its MSB=0). IF (Interrupt Flag). Used to control microprocessor maskable interrupt requests.

c. Segment Registers (CS, DS, SS & ES). Used by the microprocessor to get the segment addresses of program memory and data memory. The microprocessor combines segment addresses from these registers with the offset addresses to get the actual (physical) addresses of different memory segments.

2.2 MEMORY SEGMENTATION IN INTEL 8086/8088 MICROPROCESSORS: [1]

Intel 8086/8088 microprocessors have an address bus of 20 lines (A0- A19), so they address a total memory of 1MByte with the address range 00000H-FFFFFH. This memory is segmented by these microprocessors to 4 types of segments. One segment will be used store programs instructions (it represents the program memory) while the other segments are used to store data (they represent the data memory).Each segment has a segment address. Also, each memory byte in each segment has an offset address. So, in programs each storage location (byte) in the memory is specified by a segment address (16-bit) and an offset address (16-bit) usually written in programs in the form segment:offset for example 5000H:2BA0H. The microprocessor uses these two addresses to get an actual (physical) address of 20-bit, which will be put on the address bus to access the memory storage location. For each segment, the segment address is taken by the microprocessor from a specified segment register, and the offset address is taken from other registers or written directly in the program. The 4 memory segments are listed in table 2.1:

Memory SegmentDefault UseSegment addressOffset Address

a. Code Segment.(Program memory)To store program instructions.In CS register.In IP register.

b. Data Segment.(A data memory)To store data (variables) used by the program.In DS register.A direct 16-bit address or an address in BX or SI or DI registers.

c. Stack Segment(A data memory)Used as a stack. Stack is a data memory in which data is stored in the form of Last-In-First-Out. When the microprocessor transfers to execute some subroutines it stores some data temporarily in the stack.In SS register.In SP or BP registers.

d. Extra Segment(A data memory)As additional data segment for some string instructions.In ES register.In DI register.

Table 2.1The four Memory Segments of Intel 8086/8088 Microprocessors.2.3 ASSEMBLY LANGUAGE, MACHINE LANGUAGE, ASSEMBLER AND ASSEMBLER DIRECTIVES: [1]

Each microprocessor executes a number of instructions. Each instruction is given a name called "mnemonic". For example, for Intel8086/8088 MOV instruction is used to transfer (copy) data and ADD instruction is used for addition.The language used to write these instructions is called assembly language. The general format for instructions in assembly language is: LABEL OPCODE OPERANDS COMMENTS EX: Next: MOV AX , BX ; Copy BX to AX Destination Operand Source Operand Both the LABEL and COMMENTS are optional, used in some cases, but each instruction must have its opcode which specify the type of operation. The OPERANDS are register names, memory addresses or values of data on which the instruction will operate. Some 8086/8088 instructions have no operand, others have one or two operands.Programs written in assembly language must be translated to machine language before executing them by the microprocessor. Instructions in machine language are binary codes that can be executed by the microprocessor. For each instruction in assembly language there is a corresponding instruction in machine language, usually given by the microprocessor manufacturer as a hexadecimal code. In most microcomputers, a translator program called "The Assembler" is used to automatically perform the translation operation and store the machine language program in memory then run it. For example the Line Assembler used with the microcomputer trainer MC8088/EV system. Some of the statements written in assembly language programs are called Assembler Directives. They arent instructions to the microprocessor, but they represent directives to the assembler to do some operations while it assembles the program to machine language. Two examples of the directives used with the Line Assembler of the microcomputer trainer MC8088/EV system are:

a. DB (Define Byte): Used to book a number of locations in the data memory, each location is one byte and put data in each location. Ex:

0090:20 DB 23, 6C, EB, A , B , C b. DW (Define Word): Used to book a number of locations in the data memory, each location is a word (two bytes0 and put data in each location. Ex: 0090:50 DW 18B0, AAFF

Note: All the numbers written in the programs for the Line Assembler of the microcomputer trainer MC8088/EV must be hexadecimal values. 2.4 ADDRESSING MODES USED WITH INTEL 8086/8088 INSTRUCTIONS: [1]

The addressing mode is the method used in the instruction to specify the location of data (the operands) on which the instruction will operate. The followings are some of the addressing modes used with 8086/8088 instructions.

2.4.1 Register Addressing Mode. [1]

In this mode, the operands are one or two of the microprocessor registers. Ex: MOV SI , BX MUL CX MOV AH , BLSource operand and destination operand registers must be of the same size.

2.4.2 Immediate Addressing Mode. [1]

Source operand only is an immediate data byte or data word. Ex: MOV AX, 34BC ; Store the number 34BCH in AX MOV DL, 68 ; Store the number 68H in DL

2.4.3 Direct Data Memory Addressing Mode. [1]

One of the operands is a memory location which contains the data that will be used by the instruction. The offset address of this memory location is written directly in the instruction. By default data is stored in data segment memory. Ex:MOV AX, [0070] ;Copy one data word from memory to register AX. The ;offset address of the memory is 0070H. MOV [002B], CL ;Copy one data byte from register CL to memory. The ;offset address of the memory is 002BH.

Note: the brackets [ ] represent a directive to the assembler that the number represent an offset address of a data memory.

2.4.4 Register Indirect Data Memory Addressing Mode. [1]

One of the operands is a memory location which contains the data that will be used by the instruction. The offset address of this memory location will be in a register. The registersthat will be used to hold the offset address are BX, SI or DI only. By default data is stored in data segment memory. Ex:

MOV BX, 0070 ; First the offset address of memory must be stored in a register.MOV AX, [BX] ;Copy one data word from memory to register AX. The ;offset address of the memory is taken from register BX.

MOV DI, 002B ; First the offset address of memory must be stored in a register.MOV [DI], CL ;Copy one data byte from register CL to memory. The ;offset address of the memory is taken from register DI.

Note: Register indirect addressing is very useful in case the program deals with a large quantity of data.

2.4.5 Register Relative Data Memory Addressing Mode. [1]

One of the operands is a memory location which contains the data that will be used by the instruction. The offset address of this memory location will be in a register. Also, a displacement will be added to or subtracted from the offset address. The registersthat will be used to hold the offset address are BX, SI or DI only. By default data is stored in data segment memory. Ex:

MOV BX, 0070 ; First the offset address of memory must be stored in a register.MOV AX, [BX-20] ;Copy one data word from memory to register AX. Offset ; address of the memory is in register BX displaced by -20H.

MOV DI, 002B ; First the offset address of memory must be stored in a register.MOV [DI+3C0], CL ;Copy one data byte from register CL to memory. Offset ;address of the memory is in register DI displaced by +3C0H.

Note: The original address in registers BX or SI or DI will not change because the displacement will be added temporarily. This enables the program to get data from different areas in memory starting from a fixed address.

2.4.6 Direct Program Memory Addressing Mode. [1]

This mode is used with instructions JMP, LOOP and CALL which cause the jump in the program from one part to another in the Code Segment. The offset jump address is written directly in the instruction. This address will replace the current address of IP to cause the jump. Ex: JMP 0020 ; Jump in the program memory to the offset address 0020H.

2.4.7 Indirect Program Memory Addressing Mode. [1]

This mode is used with JMP instruction which cause the jump in the program from one part to another in the Code Segment. The offset jump address will be in any 16-bit register (AX, BX, CX, DX, SP, BP, SI, DI). When the microprocessor executes JMP instruction it replaces the current address of IP by the address specified by the register and jump. Ex: MOV CX, 0020 ;First store the offset jump address in CX register. JMP CX ; Jump in the program memory to the offset address which is ;the number stored in register CX.

2.4.8 Fixed-Port Addressing Mode. [1]

This mode is used with instructions IN and OUT which are used to transfer data between the microprocessor and Input / Output ports. The port address is written directly in the instruction and it must be 8-bit only. Ex:IN AL,50 ; Input one byte from the input port to AL. The port address is 50H.OUT 70,AX ; Output one word (two bytes) from AX to the output port. The ; port address is 70H.

2.4.9 Variable-Port Addressing Mode. [1]

This mode is used with instructions IN and OUT which are used to transfer data between the microprocessor and Input / Output ports. The port address will be 16-bt in register DX only. Ex:MOV DX, 1F00 ;First store the port address in DX register.IN AX, DX ; Input one word (two bytes) from input port to register AX. ;The port address is in register DX.OUT DX,AL ; Output one byte from AL to the output port. The port address ;is in register DX.

2.5 INTEL 8086/8088 MICROPROCESSORS GROUPS OF INSTRUCTIONS: [1]

All the instructions of Intel 8086/8088 microprocessors can be classified to the following Groups:1. Data Transfer Group.2. Arithmetic Group.3. Logical Group.4. Control Transfer Group.5. String Manipulation Group.6. Processor Control Group.

2.5.1 Data Transfer Group: [1]

Data transfer instructions are used in the program to move (copy) data from one location to another. The data may be in groups of 8-bits or 16-bits. All these instructions do not affect the FLAGS. We will study some instructions in this group.2.5.1.1 MOV Instruction: [1]

It is used to copy a byte or a word of data from a source to a destination. a. From a register to a register: MOV SP, SI MOV CL, BH MOV DS, BX b. From a data memory to a register and from a register to a data memory: MOV AX,[0400] MOV [SI], CH MOV [BX+60], SIc. Immediate data to a register or a data memory: MOV BX,1C00 MOV DH,56 MOV [1000], FFCC

Note: Immediate data cannot be moved to a segment register. Move the data to a general purpose register then to the segment register. MOV CX, 0090 MOV DS, CX

2.5.1.2 PUSH Instruction: [1]

It is used to save a word only from a register or data segment memory into the top of the stack segment memory.PUSH DXPUSH [2000] ; Store a data word from the data segment memory with offset ;address 2000H in the top of the stack segment memory.

2.5.1.3 POP Instruction: [1]

It is used to return a word only from the top of the stack segment memory to a register or a data segment memory.POP [SI] ; Return a data word from the top of stack segment memory to the data ; segment memory. Offset address of data memory is in register SI.POP BX

Note: In any program usually the sequence of POP instructions is opposite to that of PUSH instructions, because data is stored in stack in the form of Last-In-First-Out. PUSH AXPUSH BP.POP BPPOP AX2.5.1.4 IN Instruction: [1]

It is used to input a byte or a word from an input port (input interface) to registers AL or AX only.IN AL,50 IN AX,F0

MOV DX,5000IN AL,DX IN AX,DX

2.5.1.5 OUT Instruction: [1]

It is used to output a byte or a word from registers AL or AX only to an output port (output interface).OUT B0, AL OUT 70, AX

MOV DX,B000OUT DX, AL IN DX, AX

2.5.2 Arithmetic Group: [1]

2.5.2.1 ADD, ADC, SUB, SBB and CMP Instructions: [1]

Byte or word addition, subtraction and comparison instructions can be executed on signed or unsigned binary numbers. After the microprocessor executes any of these instructions the Flags CF, ZF, OF, AF, PF and SF will change according to the result.a. ADD (add):ADD destination, source ; destination + source Result destination ADD BX, CX; BX + CX Result BX

b. ADC (add with carry):ADC destination, source ; destination + source + CF Result destination ADC DL, AL; DL + AL + CF Result DL

c. SUB (subtract)SUB destination, source ; destination - source Result destinationSUB CH, BL ; CH - BL Result CH

d. SBB (subtract with borrow):SBB destination, source ; destination - source - CF Result destinationSBB SP, DI ; SP - DI - CF Result SPe. CMP (compare)CMP destination, source ; destination - source CMP AX, SI ; AX - SIComparison is a subtraction operation without a result, i.e. both the source and destination operands will remain the same. Only the FLAGS will change.

In all these instructions the source and destination operands are:1. Register, RegisterADD CX,AXCMP SI,DI2. Register, Data in Memory or Data in Memory, RegisterADC CL, [0030]SUB [SI], AX3. Register, Immediate Data or Data in Memory, Immediate Data SBB AL,45ADD [0900], F000

2.5.2.2 INC and DEC Instructions: [1]

A byte or a word, a signed or an unsigned number can be incremented by 1 using INC instruction or decremented by 1 using DEC instruction. Flags ZF, OF, AF, PF and SF will change. INC and DEC instructions has one operand, either a register or a memory location.INC BX ; BX + 1 BX DEC CL ; CL - 1 CL INC BYTE PTR [DI] ; Increment by 1 a byte of data in data segment memory. ;The offset address of that memory is in register DI.DEC WORD PTR [2000] ; Decrement by 1 a word of data in data segment ;memory. The offset address of that memory is 2000H.

Note: BYTE PTR and WORD PTR are directives to the assembler used to clarify if the operation is on a byte or a word.

Programming Example 1: The data words F0C0H, CAB6H, 2D50H and FF56H are stored in data memory starting with address 0090:0H. Write a program that adds all these numbers and stores the result in data memory starting with 0090:10H.Solution:The sum of these words will be a word. The carry must be taken and it will be a byte.MOV DX,0090MOV DS,DXMOV AX,0 ; AX will be used to store the sum.MOV CL,0 ; CL will be used to store the carry.ADD AX,[0] ; add the first word.ADD AX,[2] ; add the second word.ADC CL,0 ; take the first carry.ADD AX,[4] ; add the third word.ADC CL,0 ; take the second carry.ADD AX,[6] ; add the fourth word.ADC CL,0 ; take the third carry.MOV [10],AX ; store the sum in data memory 0010H. MOV [12],CL ; store the total carry in data memory 0012H.INT 70090:0DW F0C0, CAB6, 2D50, FF56

2.5.2.3 MUL, IMUL, DIV and IDIV Instructions: [1]

Unsigned bytes and words can be multiplied and divided using MUL and DIV instructions. The results will be unsigned values. Signed bytes and words can be multiplied and divided using IMUL and IDIV instructions. The results will be signed values in this case.a. Byte Multiplication:The multiplicand must be a byte in AL register only. The multiplier is a byte either in an 8-bit register or in memory (the multiplier cannot be an immediate byte). The result will be a word in AX (The high byte in AH and the low byte in AL).

ALAHBLBHCLCHDLDHmemory Byte in Byte in Result (Word) in AX

AHHigh ByteALALLow Byte*

MUL BL ; AL * BL AXMUL AL ; AL * AL AXMUL BYTE PTR [0020] ; AL* [0020] AX

b. Word Multiplication:The multiplicand must be a word in AX only. The multiplier is a word either in a 16-bit register or in memory (the multiplier cannot be an immediate word). The result will be a double word in DX and AX (The high word in DX and low word in AX).

AXBXCXDXSIDISPBPmemory Word in Word in Result (Double Word) in DX AX

DXHigh WordAXAXLow Word *

MUL SI ; AX *SI DX(The high word) AX(The low word)MUL WORD PTR [BX] ;AX * [BX] DX(The high word) AX(The low word)

c. Byte Division:The dividend must be a word in register AX only. The divider is a byte either in an 8-bit register or in a memory. The result (the quotient) will be a byte in AL and the remainder will be a byte in AH.

ALAHBLBHCLCHDLDHmemory Word in Byte in Remainder Result (quotient)

AHALAX

DIV BH ; AX BH AL (The quotient) AH (The remainder). DIV BYTE PTR [DI] ; AX [DI] AL (The quotient) AH (The remainder)

d. Word Division:The dividend must be a double word in registers DX (The high word) and AX (The low word) only. The divider is a word either in a 16-bit register or in a memory (the divider cannot be an immediate word). The result (the quotient) will be a word in AX and the remainder will be a word in DX registers.

AXBXCXDXSIDISPBPmemory Double Word in Word in Remainder Result (quotient)

DXAXDXHigh WordAXLow Word

DIV CX ; DX AX CX AX (The quotient) DX (The remainder).DIV WORD PTR[30] ; DX AX[0030] AX(The quotient) DX(The remainder)

Programming Example 2: Assume that the variables A, B, and C are unsigned byte valued numbers stored in data memory starting with address 0090:10. The assigned values for these variables are:A= 7AH , B=3DH, C=4EHWrite a program that calculates the value of the variable X from the following equation: X= (B2 -2FC0 + AC)/ (C+ 65)Assume that no carry will result from the addition operation and no borrow will result from the subtraction operations. The program stores the result and the remainder in the data memory starting with address 0090:20. Solution:MOV DX,0090MOV DS,DXMOV AL, [0011]MUL AL ; Calculate B2MOV DX, AXSUB DX, 2FC0 ; Calculate B2-2FC0MOV AL,[0010]MUL BYTE PTR [0012] ; Calculate ACADD DX, AX ;Calculate B2-2FC0+ACMOV BL,[0012]ADD BL,65 ; Calculate C+65MOV AX,DXDIV BL ; Calculate XMOV [0020], AX ; Store result and remaiderINT 70090:10DB 7A ;A0090:11DB 3D ;B0090:12DB 4E ;C2.5.3 Logical Group: [1]

Logical instructions regard their operands as strings of bits. They operate on bytes and words. The Flags CF, OF, PF, SF and ZF change after the microprocessor executes most of logical instructions.

2.5.3.1 AND, OR and XOR Instructions: [1]

a. AND (logical AND): AND DH, CL; DH . CL Result DH

b. OR (Logical OR): OR DX, AX; DX + AX Result DX

c. XOR (Logical Exclusive OR)XOR CH, BL ; CH + BL Result CH

In all these instructions the source and destination operands are:1. Register, RegisterXOR CX,AXOR DL,AH

2. Register, Data in Memory or Data in Memory, RegisterAND CL, [0030]XOR [SI], AX

3. Register, Immediate Data or Data in Memory, Immediate Data OR AL,45AND [0900], F000

2.5.3.2 NOT Instruction: [1]

It is used to get the ones complement of its operand which is a byte or word in a register or memory.NOT BX ; BX BXNOT DH ; DH DHNOT BYTE PTR [DI] ; [DI] [DI]NOT WORD PTR [0050] ; [0050] [0050]

Programming Example 3: The number N1=CF8DH and the number N2= DCA7H are stored in data memory starting with location 0090:0. Write a program the finds the value of the number N which is specified by the following Boolean expression and stores it in data memory 0090:10 where:

N= N1+ N2 + N1 . N2 Solution:MOV DX,0090MOV DS,DXMOV AX, [0000] ; move N1 to AXMOV BX, [0002] ; move N2 to BXNOT BX ; N2OR AX,BX ; N1+N2MOV CX,[0000] ; move N1 to CXMOV DX,[0002] ; move N2 to DXAND CX, DX ; N1.N2NOT CX ; N1.N2XOR AX, CX ; N1+N2 + N1.N2NOT AX ; Find NMOV [0010],AX ; Store NINT 70090:0DW CF8D, DCA72.5.4 Control Transfer Group: [1]

This group of instructions is used to jump (branch) in the program from one part to another. In this case the sequential execution of instructions will be changed. These instructions will change the address in IP register (or addresses of both IP and CS registers), so, they will cause the jump in the program.The Control Transfer Instructions include: the unconditional jump, the conditional jump, loop instructions, CALL, RET, INT, INTO and IRET instructions.

2.5.4.1 The Unconditional Jump using JMP Instruction: [1]

It is without any condition. The jump will occur always when the microprocessor executes JMP instruction. JMP instruction is used with two addressing modes:a. Direct Program Memory Addressing Mode: The offset jump address is writtendirectly with instruction. Ex:001B MOV BX,FFFF 001E DEC BX 0020 JMP 001E

Note: In modern assemblers, the programmer will label the destination of the jump and use this label with JMP instruction. The assembler will determine the value of the direct address and substitute it in JMP instruction. Ex: MOV BX,FFFF Next:DEC BX JMP Nextb. Indirect Program Memory Addressing Mode: The jump address will be put in a 16-bit register (AX, BX, CX, DX, SP, BP, SI, DI). When the microprocessor executes such instruction it replaces the address in IP by the address stored in the register and jump. Ex: JMP AX

2.5.4.2 The Conditional Jump: [1]

Each conditional jump instruction has a condition to jump. The microprocessor jumps only if the condition specified in the instruction is met during program execution. Otherwise, the microprocessor will not jump and it will continue to the next instruction in the same program sequence.All the conditions are dependent on the status of the flags.

Note: All conditional jump instructions are direct jump, so we must use labels or write the value of the jump address. Conditional jump instructions of Intel 8086/8088 microprocessors are listed in table 2.2.Conditional JumpJump if:Remark

JZZeroJump if ZF=1

JNZNot ZeroJump if ZF=0

JCCarryJump if CF=1

JNCNo CarryJump if CF=0

JOOverflowJump if OF=1

JNONo OverflowJump if OF=0

JSSign is Set ( sign negative)Jump if SF=1

JNSSign is Reset ( sign positive)Jump if SF=0

JP/JPEParity/ Parity EvenJump if PF=1

JNP/JPONo Parity / Parity OddJump if PF=0

JAAboveUsed when operations are performed on unsigned numbers.

JAEAbove or Equal

JBBelow

JBEBelow or Equal

JEEqual

JNENot Equal

JGGreaterUsed when operations are performed on signed numbers.

JGEGreater or Equal

JLLess

JLELess or Equal

JEEqual

Table 2.2The conditional jump instructions of Intel 8086/8088 microprocessors.Programming Example 4: The unsigned data words 34FDH and C694H are stored in data memory starting with address 0090:0. Write a program that displays the maximum number on the LCD display. Solution: MOV CX,0090 MOV DS,CX MOV AX,[0000] CMP AX,[0002] JA DISP MOV AX,[0002] DISP: INT 10 INT 7 0090:0 DW 34FD, C694

2.5.4.3 LOOP Instruction: [1]

LOOP is an unconditional instruction used to repeat part of the program a number of times. By default, LOOP uses register CX as a counter. So, the number of required repetitions must be put in CX. Ex: MOV AX,0 MOV BX,4 MOV CX,200 SUM: ADD AX,BX LOOP SUM

LOOP will decrement CX by 1 each time it repeats the loop. If CX 0, it will jump again to the specified label. If CX=0, it will not jump and the program continues from the next instruction. The above part of the program can be written as shown without using LOOP: MOV AX,0 MOV BX,4 MOV CX,200 SUM: ADD AX,BX DEC CX JNZ SUMNote: All loop instructions require direct address, so we must use labels or write the value of the address in practical exercises.

Programming Example 5: The data words 45FDH, CD08H, 7FF0H, 6CB8H, AA22H, 9945H, E0FAH, 9034H, 0F10H, ADBCH, 2189H, CF94H, BD5FH, 8832H and 7A1BH are stored in data memory starting with address 0090:0. Write a program that calculates the sum of these words and stores the result in data memory starting with 0090:40. Solution: The sum of all these words will be a word, but the total carry will be a byte.MOV DX,0090MOV DS,DXMOV SI,0000 ; starting offset address of data. MOV CX, 0F ; Counter to the number of additions. MOV AX,0 ; AX will be used to store the sum.MOV BL,0 ; BL will be used to store the carry. SUM: ADD AX,[SI] ; add a word.ADC BL,0;take the carry INC SI INC SI ; get the address of next word.LOOP SUM ; add second word.MOV [0040], AX MOV [0042], BL INT 70090:0 DW 45FD, CD08, 7FF0, 6CB8, AA22, 9945, E0FA0090:E DW 9034, 0F10, ADBC, 2189, CF94, BD5F, 8832, 7A1B

Programming Example 6: The numbers 56H, 77H, 33H,5FH, 78H, CBH, 99H, 12H, 0H, 6EH, 76H, 90H, ACH, BEH are unsigned bytes stored in data memory starting with address 0090:30. Write a program that displays the minimum number on the LCD display.Solution: MOV DX,0090 MOV DS,DX MOV SI,0030 ; Starting offset address of data. MOV AL, [SI] ; First number to AL and consider it as the minimum. INC SI ; Get address of second number. MOV CX, 0D ; Loop Counter to the remaining numbers. AGAIN : CMP AL,[SI] ; Compare next number in memory with AL. JB NEXT ; Continue if AL is Less. MOV AL,[SI] ; If the number in memory is Less, store it in AL. NEXT: INC SI ; Get address of next number in memory. LOOP AGAIN ; Compare again. INT E INT 70090:30 DB 56, 77, 33,5F, 78, CB, 99, 12, 0, 6E, 76, 90, AC, BE

Programming Example 7: The data memory starting with address 0090:00 holds an array A of 20 unsigned words. The data memory starting with address 0090:40 holds an array B of 20 unsigned bytes. Write a program that divides each word from array A by the corresponding byte from array B. The program stores the results and remainders OF divisions in data memory starting with address 0090:80.Solution: MOV DX,0090MOV DS,DXMOV SI,0000 MOV DI,0040MOV BX,0080MOV CX, 14 AGAIN: MOV AX,[SI] DIV BYTE PTR [DI] MOV [BX], AXADD SI, 2 INC DIADD BX, 2LOOP SUM INT 70090:0 DW 45FD, CD08, .0090:40 DB 90, 34,

2.5.4.4 CALL and RET Instructions: [1]

CALL instruction is used to transfer the flow of the program to a subroutine. CALL differs from JMP instruction because it saves the return address (the current address of IP) in the stack. Ex: MAIN: MOV DX,1500 MOV BX, 2800 CALL FUNCTION MOV AX,DX INT 7

FUNCTION: ADD DX, BX RET

Instruction RET is used at end of the subroutine in order to return to the main program. Actually RET will pop the return address from the top of the stack to IP.

2.5.4.5 INT and IRET Instructions: [1]

There are two types of interrupts in all Intel microprocessors: Internal Interrupts and External Interrupts (Hardware Interrupts).

1. Internal Interrupts:They are sometimes called Exceptions. Also they are of two types: Software Interrupts and Special Cases Interrupts.a. Software Interrupts:They are invoked when either INT or INTO instructions are used in the program.

Syntax: INT Vector-NumberEx: INT E

INT is an unconditional interrupt instruction. When the microprocessor executes thisinstruction it will directly leave the current program and transfer to execute the Interrupt Service Routine(ISR). But before the microprocessor transfers to execute the ISR, it pushes the current addresses of CS and IP to the stack memory, so they will be the return addresses to the original program.The Vector-Number (also called Interrupt Type) is a number of one byte (from 00 to FF). The microprocessor uses this number to get the segment address and offset address of the memory in which the ISR is stored. The microprocessor will put these addresses in CS and IP respectively, so it will transfer to execute the ISR.At the end of the ISR, the instruction IRET (Interrupt Return) is used to return to the original program. IRET will return addresses from the stack to IP and CS registers.

b. Special Cases Interrupts Each of these interrupts will be automatically executed by the microprocessor when a special internal microprocessor case occurs. Each of these interrupts has a default type. An example of these interrupts is the Divide-by-Zero Error interrupt. It vector type is 0 by default.

2. External Interrupts (Hardware Interrupts)[3]:These interrupts are requested by external devices connected with the microprocessor. The external device request each interrupt by activating one of the microprocessor input control interrupt lines. Intel 8086/8088 microprocessor has two hardware interrupt lines:

a. INTR: It is the maskable interrupt line. The Microprocessor will respond to this interrupt only if the interrupt flag is set (IF=1). If IF=1, the microprocessor will acknowledge the external device that it is accepting the interrupt by activating INTA line (Active-Low output control line). The external device supplies the microprocessor with the interrupt vector-number through data bus and the microprocessor will use this number to transfer to the ISR as mentioned before. This process is shown in figure 2.2.

Intel PINTRINTA7D-0DExternalDevice

Figure 2.2 The Maskable Interrupt of Intel 8086/8088 Microprocessors.

b. NMI: It is the non-maskable interrupt line. The Microprocessor will respond to this interrupt without any condition. The interrupt vector-number is 2 by default.Note: Since the interrupt vector number is one byte in all Intel microprocessors, the total number of ISRs dedicated for internal and external interrupts is 256 .Chapter ThreeConnecting Memories and Interfacing I/O Devices with Intel 8088 Microprocessor

3.1 CONNECTING ROM AND STATIC RAM MEMORIERS WITH INTEL 8088 MICROPROCESSOR: [3]

The general pins-out for ROMs and SRAMs is shown in figure 3.1 below:

Figure 3.1 The General Pins-Out for ROMs and SRAMs Memories.

Notes:1. Memory storage capacity (the number of storage locations in the memory) C= 2n where n is the number of address lines.Ex: a 1 K memory has 10 address lines (A0-A9) because: 1K=1024=210 .

2. Each memory has a number of data lines equal to the size of each storage location which can be 1, 2, 4, 8 or 16-bit.Ex: A memory with each storage location is 4 bits has 4 data lines (D0-D3).

Usually the total memory size is written like: 1Kx4, 1Kx8, 2Kx8, 16Kx1 .. etc.Ex: A memory 4Kx8 has:4K= 4x1024=4096= 212 12 address lines A0- A11. It has 8 data lines: D0-D7.

3. A SRAM and a ROM has at least one CS (Chip Select) or CE ( Chip Enable ) input. It enables all the memory chip and it is usually connected to one of the address decoder outputs.

4. A ROM has one control input OE , usually connected with MEMR line of the system bus.

5. A SRAM has two control inputs OE (connected to MEMR) and WE (connected to MEMW) lines of the system bus.3.1.1 Memory Map and the Address Decoder: [3]

We know that Intel 8088 microprocessors can address 1Mbyte of memory with a total address range 00000H-FFFFFH. So, each memory that will be connected with the microprocessor must be assigned and address range according to its size. For examples:A 1K memory can take an address range 00000 - 003FFH or FF000 - FF3FFH.A 2K memory can take an address range 00000 - 007FFH or 50000 - 507FFH. A 4K memory can take an address range 00000 00FFFH or C4000 C4fFFH.An 8K memory can take an address range 00000 01FFFH or FE000 - FFFFFH.

The assignment of addresses to memory chips (ICs) in a system is called the memory map.

The following points must be considered when we assign addresses to memories connected with Intel 8088 microprocessor:1. For ROM memories, one of the connected ROMs must be given an address range ending with FFFFFH (Ex: FFF00H-FFFFFH for a 4K ROM) because at startup or after resetting Intel 8088 microprocessor its registers IP=0000 and CS=FFFFH, so, the microprocessor will restart running the system startup program from the address FFFF0H. So, this address should be assigned for a ROM memory, because it usually holds the startup system program as stored by the system manufacturer.

2. Also, one of the connected SRAM memories must be given an address range starting with 00000H because the interrupt vectors for Intel 8088 microprocessor are stored in the lower part of RAM memory starting with address 00000H.

Note:For other types of microprocessors the given starting addresses for ROM and RAM memories may be different.

3. The rest of ROM chips and the SRAM chips can be given any other address range.

4. After selecting the address range for each memory piece, an address decoder circuit must be designed and connected. The address decoder circuit will provide chip select signals to all memory chips in order to enable each one according to its address range. Simple gates can be used as address decoders. Also, some decoder ICs can be used like 74LS139 (Dual 2 line-to- 4 line decode), 74LS138 (a 3 line-to-8 line decoder) or 74LS154 (a 4 line-to-16 line decoder).

Memory Connection Example 1: It is required to connect with Intel 8088 microprocessor a SRAM memory with a total storage capacity of 8 Kbyte. If the available SRAM is of type 6116 (2Kx8), select the required number of SRAM chips and select an address range for each chip, then design the address decoder circuit. Draw the complete connection.Solution:4 pieces of 6116 SRAM are required. Each SRAM is 2Kx8, so each SRAM has 8 data lines D0-D7.2K=2x1024=2048=211. So, each SRAM has 11 address lines A0-A10.

The selected address ranges for the 4 SRAMs are:SRAM0(00000-007FFH)SRAM1(00800-00FFFH)SRAM2(01000-017FFH)SRAM3(01800-01FFFH)The complete connection including the address decoder circuit is shown in figure 3.2 below:

Figure 3.2 The Circuit Connection for Example 1.

Memory Connection Example 2: It is required to connect with Intel 8088 microprocessor a ROM memory with a total storage capacity of 32 Kbyte. If the available ROM is an EPROM of type 2732 (4Kx8), select the required number of EPROM chips and select an address range for each chip, then design the address decoder circuit. Draw the complete connection.Solution:8 pieces of 2732 EPROM are required. Each EPROM is 4Kx8, so each EPROM has 8 data line D0-D7.4K=4x1024=4096=212. So, each EPROM has 12 address lines A0-A11.The selected address ranges for the 8 EPROMs are:EPROM7(FF000-FFFFFH)EPROM6(FE000-FEFFFH)EPROM5(FD000-FDFFFH)The complete connection including the address decoder circuit is shown in figure 3.3 below:

Figure 3.3 The Circuit Connection of Example 2.

Problem1: It is required to connect with Intel 8088 microprocessor a SRAM memory with a total storage capacity of 128Kbyte. If the available SRAM is of type 61128 (16Kx8), select the required number of SRAM chips and select an address range for each chip, then design the address decoder circuit. Draw the complete connection.

Problem2: It is required to connect with Intel 8088 microprocessor a ROM memory with a total storage capacity of 128Kbyte. If the available ROM is an EPROM of type 27256 (32Kx8), select the required number of EPROM chips and select an address range for each chip, then design the address decoder circuit. Draw the complete connection.3.2 INTERFACING PERIPHERAL (I/O) DEVICES WITH INTEL 8088 MICROPROCESSOR: [3]

A large number of I/O devices (Peripherals) can be connected with the microprocessor like keyboards, LEDs, 7-segment displays, ADC and DAC converters, screens, printers .. These devices are connected with the microprocessor through interfaces and through these interfaces the microprocessor transfers data with peripheral devices. The simplest types of interfaces are called I/O ports.

When I/O ports are connected with the microprocessor, each port must be given one address called Port Address. Intel 8088 microprocessor can give isolated addresses for 64Kbytes of input ports and 64kbytes of output ports other than the addresses given to memory. That is using only address lines A0-A15. So, the total isolated address range of I/O ports is 0000-FFFFH.Each port can be given one 8-bit or 16-bit address and a separate address decoder circuit must be designed and connected to give enable (chip select) signals to these ports according to their addresses. Data is transferred between I/O ports and I/O devices in two modes:

1. The Parallel Mode:The data is exchanged between I/O devices and I/O ports one byte at a time through 8 data lines. Examples of parallel I/O devices are keyboards, displays, ADC and DAC converters.2. The Serial Mode:Data is transferred serially one bit at a time through one data line. Since the microprocessor is a parallel device, the output port must have the ability to change data from parallel-to-serial and give it to the serial output device. Also, the input port must have the ability to change data from serial-to-parallel and give it to the microprocessor. Examples of serial I/O devices are modems, tape recorders, and USB devices.

3.2.1 Connecting Simple (Non-Programmable) Parallel I/O Ports With Intel 8088 Microprocessor: [3]

Tri-state buffers ICs are usually used as simple non-programmable input ports to connect simple input devices like switches, keyboards and ADC converters. For Examples:1. IC 74LS244. It contains 8-bit (Octal) Tri-State Buffers. It has two active-low enable lines G1 and G2. 2. IC 74LS126. It contains 4 tri-state buffers. Each buffer has a separate active-high enable line E.Latches ICs are usually used as simple non-programmable output ports to connect simple output devices like LEDs, 7-segment displays and DAC converters. For examples:

1. IC 74LS75. It contains 4-bit latches. It has two active-high enable lines G1 and G2.2. IC 74LS100. It contains 8-bit latches with one common active-high enable line G.Note:IC 74LS373 has 8-bit (Octal) Latches with Tri-State Buffered outputs. The latches have a common active-high enable line G, and the tri-state buffers have a common active-low enable line OE. This IC can be used as an 8-bit input port or an 8-bit output port.

I/O Ports Connection Example 1: It is required to connect with Intel 8088 microprocessor the following devices:1. One simple parallel 8-bit input port.2. One simple parallel 4-bit output port.3. One simple parallel 8-bit output port.

The available parts are: 1. IC 74LS244 (Octal tri-state buffers with two enable lines G1 and G2).2. IC 74LS75 (4-bit latches with two enable lines G1 and G2).Assign an isolated address for each port then design the address decoder circuit. Select the required ports from the ICs given. Draw the complete circuit connection with the microprocessor.

Solution:a. Address selection:Address 1000H for the 8-bit input port.Address 2000H for the 4-bit output port.Address 3000H for the 8-bit output port.

b. I/O ports selection:For the 8-bit input port we select one chip 74LS244.For the 4-bit output port we select one chip 74LS75.For the 8-bit output port we select two chips 74LS75.

c. The complete circuit design:As shown in figure 3.4.

Figure 3.3 I/O Ports Circuit Connection of Example 1.

Problem3:It is required to connect with Intel 8088 microprocessor the following devices:1. Two simple parallel 8-bit input ports.2. Two simple parallel 8-bit output ports.The available part is IC 74LS373 (8-bit Latches with Tri-State Buffers. It has two enable lines G for the latches and OE for the tri-state buffers).Assign an isolated address for each port then design the address decoder circuit. Select the required ports using the given IC. Draw the complete circuit connection with the microprocessor.

3.2.2 Connecting Programmable Parallel I/O Ports With Intel 8088 Microprocessor: [3]

There are a large number of programmable devices that can be connected with the microprocessor. These devices can perform a large number of functions that help the microprocessor to control the different parts of the microcomputer or the microprocessor-based system and free it to execute programs more quickly. These devices are programmed by the microprocessor to do the required operations. Examples of such devices are Programmable Interrupt Controllers, Direct Memory Access Controllers, Keyboards Controllers, Cathode Ray Tube (CRT) controllers, Programmable Parallel I/O ports and Programmable Serial I/O ports.

Programmable Parallel I/O ports (also called Programmable Parallel Interface Devices) are integrated circuits, each one contains a number (2 , 3 or more) of I/O ports that can be programmed to be either input or output ports and in different data transfer conditions ( unconditional I/O, interrupt-driven I/O, I/O with handshaking). Internally each Programmable Parallel I/O ports IC consists of:1. A number of latches and tri-state buffers used as I/O ports.2. A control register used by the microprocessor to program the ports, which one is input and which one is output and the data transfer conditions. 3. A status register that can be read by the microprocessor to know the status of I/O ports.An example of these ICs is Intel 8255A Programmable Peripheral Interface (PPI).The external lines of this IC are shown in figure 3.5.Microprocessor SidePeripherals Side

D0 D7RESET PA0 PA7A0 PC0 PC3 A1 PC4 PC7 WRRD PB0 PB7 Intel 8255A PPI CS

Figure 3.5 The external lines of Intel 8255A PPI.Externally the microprocessor side contains the data, address and control lines that will be connected with the microprocessor. The peripheral side contains the lines of three 8-bit I/O ports A, B and C. Port A can be programmed as an 8-bit input or output or a bidirectional port. Port B can be programmed as an 8-bit input or output port. Port C is divided into two 4-bit sections, each section can be programmed as a 4-bit input or output port. Internally each port consists of some latches and tri-state buffers. But, when PPI is connected with the microprocessor, the microprocessor will consider it as an IC with four 8-bit registers: Three registers are the ports A, B and C and they are read/write registers. The fourth register is the control register which is a write only register.

Each register will have a separate address when connected with the microprocessor. The address is determined by the logic level of address lines A0 and A1 as shown in table 3.1:A1A0The Register

00Port A

01Port B

10Port C

11Control Register

Table 3.1 Addressing of Intel 8255A PPI Registers.

If, for example, PPI is connected with Intel 8088 microprocessor, and it is given an isolated address 2000H, then port A address will be 2000H, port B address will be 2001H, port C address will be 2002H and the control register will be 2003H and PPI will have a total address range 2000H-2003H.

I/O Ports Connection Example 2: It is required to connect with Intel 8088 microprocessor the following devices:1. Three parallel programmable 8-bit ports.2. One simple parallel 8-bit input port.The available parts are:1. Intel 8255A PPI.2. IC 74LS373 (8-bit Latches with Tri-State Buffers. It has two enable lines G for the latches and OE for the tri-state buffers).Select the required ports. Assign isolated I/O addresses to these ports. Design the address decoder circuit. Draw the complete circuit connection with the microprocessor.Solution:a. I/O ports selection:For the three programmable 8-bit ports one chip of 8255A PPI will be enough.For the 8-bit parallel simple input port one chip 74LS373 will be used.b. Address Selection:PPI can be given the address range 1000H-1003H.The simple input port can be given the address 2000H.c. The complete circuit design:As shown in figure 3.6.

Figure 3.6 I/O Ports Circuit Connection of Example 2.

Problem 4: A number of I/O ports have to be added to a microprocessor-based systemwhich uses Intel 8088 microprocessor. These ports are:i. Three programmable parallel 8-bit ports. ii. One simple parallel 8-bit output port.iii. One simple parallel 8-bit input port.

The available parts are: IC 74LS244 (Octal Tri-state buffers with two enable lines G1 and G2). IC 74LS100 (8-bit Latches with one enable line G). Intel 8255A PPI.

Design the required interfaces by selecting the I/O ports. Assign isolated I/O addresses to these ports. Design the address decoder circuit. Draw the complete circuit connection with the microprocessor system bus.

3.2.3 Connection of Some Parallel I/O Devices With Intel 8088 Microprocessor: [3]

3.2.3.1 Connection of LED 7-Segment Displays: [3]

Both common-anode and common-cathode LED 7-segment displays can be connected with the microprocessor through output ports which have enough current driving ability like 74LS100, 74LS75 and 743LS73. Intel 8255A PPI can be used and the needed ports must be programmed as output ports.

I/O Devices Connection Example 1: Connecting two LED common-anode displays using two 8-bit output ports which are two ICs of type 74LS373 (8-bit Latches with Tri-State Buffers). The complete connection is shown in figure 3.7.

Figure 3.7 Connection of two LED common-anode displays using two 8-bit output ports.

I/O Devices Connection Example 2: Connecting eight LED common-cathode 7-segment displays using two 8-bit output ports which are two ICs of type 74LS373 (8-bit Latches with Tri-State Buffers). The connection method is called Multiplexed Scanned Displays and it shown in figure 3.8.

Figure 3.8 Multiplexed Scanned Displays Connection.

3.2.3.2 Connection of Keyboards and Switches: [3]

I/O Devices Connection Example 3: Connection of an array of 8 switches or keys through an 8-bit input port which is IC 74LS244 as shown in figure 3.9 below:

Figure 3.9 Connection of an array of 8 switches or keys through an 8-bit input port.

I/O Devices Connection Example 4: Connection of a matrix of 4x4 keys using a 4-bit input port and a 4-bit output port. In this connection the microprocessor uses a method called "Matrix Scan" to detect which keys are pressed. The rows are connected through the input port and the columns through the output port. In this examples lines PC0-PC3 of port C of Intel 8255A are programmed as inputs, while PC4-PC7 line are programmed as output shown in figure 3.10.

Figure 3.10 Connection of a matrix of 4x4 keys through PPI.

3.2.3.3 Connection of Digital-to-Analog Converters (DACs): [3]

A DAC is connected with the microprocessor using an output port.I/O Devices Connection Example 5: Connection of an 8-bit DAC using IC 74LS100 ( 8-bit latches) as shown in figure 3.11 below:

Figure 3.11 Connection of an 8-bit DAC using an 8-bit output port.

3.2.3.4 Connection of Analog-to-Digital Converters (ADCs): [3]

An ADC is connected with the microprocessor using an input port. I/O Devices Connection Example 6: Connection of an 8-bit ADC using port A and some lines of port C of Intel 8255A PPI. The circuit connection is shown in figure 3.12.

Figure 3.12 Connection of an 8-bit ADC through PPI.Problem 5: Through only one piece of IC type Intel 8255A PPI, connect of the following I/O devices with Intel 8088 microprocessor:1. Two Common Cathode LED 7-Segment Display.2. One 8-bit ADC converter.3. An array of 3 keys.Assign an isolated I/O address to PPI and draw complete connection of this IC with the microprocessor.

3.3 SERIAL COMMUNICATION INTERFACES: [3]

A serial communications interface (SCI) is a device that enables the serial (one bit at a time) exchange of data between a microprocessor and peripherals such as printers, external drives, scanners, or mice. The SCI contains a parallel-to-serial converter that serves as a data transmitter, and a serial-to-parallel converter that serves as a data receiver. The most significant advantage of a SCI is simpler wiring. In addition, serial interface cables can be longer than parallel interface cables, because there is much less interaction (crosstalk) among the conductors in the cable.

3.3.1 What is a UART Device? [3]

UART is a Universal Asynchronous Receiver/Transmitter device which is the key component of the serial communications interface of a computer. The UART is usually a programmable IC that has the internal structure which enables it to provide the serial communication between the microprocessor and serial peripheral devices. The UART takes parallel bytes of data and transmits the individual bits in a sequential fashion. At the destination, a second UART re-assembles the serial bits into complete parallel bytes. One example of such devices is Intel 8250 UART.

Chapter FourIntroduction to PIC Microcontrollers

4.1 THE PIC MICROCONTROLLER FAMILY: [4]

The PIC microcontroller family of microcontrollers is manufactured by Microchip TechnologyInc. Currently they are one of the most popular microcontrollers used in many commercial and industrial applications. The PIC microcontroller architecture is based on a modified Harvard RISC (Reduced Instruction Set Computer) instruction set from only 6 pins to 80 pins, and from 384 bytes to 128 Kbytes of program memory.PIC microcontrollers are available with many different specifications depending on:

Memory Type Flash OTP (One-time-programmable) ROM (Read-only-memory) ROMless InputOutput (I/O) Pin Count 418 pins 2028 pins 3244 pins 45 and above pins Memory Size 0.51K 24K 816K 2432K 4864K 96128K Special Features CAN USB LCD Motor Control Radio Frequency

The models of PIC microcontrollers are upward compatible with each other and a program developed for one model can very easily, and in many cases with no modifications, be run on other models of the family. This is because the basic assembler instruction set of PIC microcontrollers consists of only 33 instructions and most of the family members (except the newly developed devices) use the same instruction set. All PIC microcontrollers offer the following features: RISC instruction set. Digital I/O ports On-chip timer with 8-bit prescaler Power-on reset Watchdog timer Power saving SLEEP mode High source and sink current Direct, indirect, and relative addressing modes External clock interface RAM data memory EPROM or Flash program memory

Some devices offer the following additional features: Analogue input channels Analogue comparators Additional timer circuits EEPROM data memory External and internal interrupts Internal oscillator Pulse-width modulated (PWM) output USART serial interface

Some even more complex devices in the family offer the following additional features: CAN bus interface I2C bus interface SPI bus interface Direct LCD interface USB interface Motor control

Although there are several hundred models of PIC microcontrollers, choosing a microcontroller for an application is not a difficult task and requires taking into account these factors: Number of I/O pins required Required peripherals (e.g. USART, USB)The minimum size of program memory The minimum size of RAM Whether or not EEPROM non-volatile data memory is required Speed Physical size Cost.You should always try to find the model which satisfies your minimum requirements and the one which does not offer more than you may need. For example, if you require a microcontroller with only 8 I/O pins and if there are two identical microcontrollers, one with 8 and the other one with 16 I/O pins, you should select the one with 8 I/O pins.

Although there are several hundred models of PIC microcontrollers, the family can be brokendown into three main groups, which are: 12-bit instruction word (e.g. 12C5XX, 16C5X)Table 4.1 lists some of the devices in this group. Figure 4.1 shows the pin configuration of the PIC16C56 microcontroller.

Table 4.1 Some PIC Microcontrollers of 12-bit instruction word group.

Figure 4.1 Pin configuration of the PIC16C56 microcontroller.

14-bit instruction word (e.g. 16F8X, 16F87X)Table 4.2 lists some of the devices in this group. Figure 4.2 shows the pin configuration of the PIC16F877 microcontroller.

Table 4.2 Some PIC Microcontrollers of 14-bit instruction word group.

Figure 4.2 Pin configuration of the PIC16F877 microcontroller.

16-bit instruction word (e.g. 17C7XX, 18C2XX)16-bit microcontrollers are at the high-end of the PIC microcontroller family. Table 4.3 lists some of the devices in this group.

Table 4.3 Some PIC Microcontrollers of 16-bit instruction word group.

Instructions occupy only one word in memory, thus increasing the code efficiency and reducing the required program memory. Instructions and data are transferred on separate buses, thus the overall system performance is increased. All memory for the PIC microcontroller family is internal and it is usually not very easy to extend this memory externally. The program memory is usually sufficient for small to medium size projects. But the data memory is generally small and may not be enough for medium to large projects unless a bigger and more expensive member of the family is chosen. For some large projects even this may not be enough and the designer may have to sacrifice the I/O ports to interfacean external data memory, or to choose a microcontroller from a different manufacturer.

4.2 INSIDE A PIC MICROCONTROLLER: [4]

4.2.1 Program Memory (Flash): [4]

The program memory is where your PicBasic or MikroBasic Pro or MikroC Pro program resides. PIC microcontrollers are based on the flash technology where the memory chip can be erased or re-programmed using a programmer device. Most PIC microcontrollers can also be programmed without removing them from their circuits. This process (called in-circuit serial programming or ISP). Although the program memory is mainly used to store a program, there is no reason why it cannot be used to store constant data used in programs. PIC microcontrollers can have program memories from 0.5 to over 16 K.It is interesting to note that PICs are known as 8-bit microcontrollers. This is actually true as far as the width of the data memory is concerned, which is 8-bits wide. When power is applied to the microcontroller or when the MCLR input is lowered to logic 0, execution start from the Reset Vector, which is the first word located at address 0 the program memory. 4.2.2 Data Memory (RAM): [4]

The data memory is used to store all of the program variables. All data will be lost when power is removed. The width of the data memory is 8-bits wide. The data memory in a PIC microcontroller consists of banks where some models may have only 2 banks, some models 4 banks, and so on.4.2.3 Register File Map and Special Function Registers: [4]

Register File Map (RFM) is a layout of all the registers available in a microcontroller and this is extremely useful when programming the device, especially when using an assembly language.The RFM is divided into two parts: the Special Function Registers (SFR), and the General Purpose Registers (GPR). For example, on a PIC16F84 microcontroller there are 68 GPR registers used to store temporary data. SFR is a collection of registers used by the microcontroller to control the internal operations of the device. Depending upon the complexity of the devices the number of registers in the SFR varies. It is important that the programmer understands the functions of the SFR registers fully since they are used both in assembly language and in high-level languages.Depending on the model of PIC microcontroller used there could be other registers. You need not know the operation of some of the registers since MikroBasic Pro or MikroC Pro compiler loads these registers automatically. For example, writing and reading from the EEPROM are controlled by SFR registers EECON1, EECON2, EEADR, and EEDATA. But fortunately, MikroBasic or MikroC Pro compilers provide simple high-level instructions for writing to and reading from the EEPROM and thus you do not need to know how to load these registers.Some of the important SFR registers that you may need to configure while programming using a high-level language are OPTION register I/O registers Timer registers INTCON register A/D converter registersThe functions and the bit definitions of these registers are described in detail in the following sections. 4.2.3.1 OPTION register: [4]

This register is used to setup various internal features of the microcontroller and is named as OPTION_REG. This is a readable and writable register which contains various control bits to configure the on-chip timer and the watchdog timer. This register is at address 81 (hexadecimal). The OPTION REG register is also used to control the external interrupt pin RB0. 4.2.3.2 I/O registers: [4]

These registers are used for the I/O control. Every I/O port in the PIC microcontroller has two registers: port data register and port direction control register.Port data register has the same name as the port it controls. For example, PIC16F84 microcontroller has two port data registers PORTA and PORTB. A PIC16F877 microcontroller has 5 port data registers PORTA, PORTB, PORTC, PORTD, and PORTE. An 8-bit data can be sent to any port, or an 8-bit data can be read from the ports. It is also possible to read or write to individual port pins. For example, any bit of a given port can be set or cleared, or data can be read from one or more port pins at the same time.Ports in a PIC microcontroller are bi-directional. Thus, each pin of a port can be used as an input or an output pin. Port direction control register configures the port pins as either inputs or outputs. This register is called the TRIS register and every port has a TRIS register named after its port name. For example, TRISA is the direction control register for PORTA. Similarly, TRISB is the direction control register for PORTB and so on.Setting a bit in the TRIS register makes the corresponding port register pin an input. Clearing a bit in the TRIS register makes the corresponding port pin an output. For example, to make bits 0 and 1 of PORTB input and the other bits output, we have to load the TRISB register with the bit pattern:00000011Figure 4.3 shows the TRISB register and the direction of PORTB pins.

Figure 4.3 TRISB register and the direction of PORTB pins.

Port data register and port direction control registers can be accessed directly using the MikroBasic Pro or MikroC Pro compiler as we shall see in a later chapter.

4.2.3.3 Timer registers: [4]

Depending on the model used, some PIC microcontrollers have only one timer, and some may have up to 3 timers. For example PIC16F84 microcontroller which has only one timer which is an 8-bit register (called TMR0) which can be used as a timer or a counter. When used as a counter, the register increments each time a clock pulse is applied to pin T0CK1 of the microcontroller. When used as a timer, the register increments at a rate determined by the system clock frequency and a prescaler selected by register OPTION_REG. A timer interrupt is generated when the timer overflows from 255 to 0. This interrupt can be enabled or disabled by our program.Most microcontrollers have at least one watchdog facility. The watchdog is basically a timer which is refreshed by the user program and a reset occurs if the program fails to refresh the watchdog. A watchdog is a safety feature that prevents runaway software and stops the microcontroller from executing meaningless and unwanted code. Watchdog facilities are commonly used in real-time systems where it is required to regularly check the successful termination of one or more activities. The watchdog timers oscillator is independent from the CPU clock and the time-out is 18 ms. Some PIC Microcontrollers have additional timers like TMR1 and TMR2.

4.2.3.4 INTCON register: [4]

This is the interrupt control register. This register is at address 0 and 8BH of the microcontroller RAM. It is used to enable the interrupts like the external interrupts from pin INT (RB0) and timer interrupts.

4.2.3.5 A/D Converter registers: [4]

The A/D converter is used to interface analog signals to the microcontroller. The A/D converts analog signals (e.g. voltage) into digital form so that they can be processed. A/D converter registers are used to control the A/D converter ports. On most PIC microcontrollers equipped with A/D, PORTA pins are used for analog input and these port pins are shared between digital and analogue functions. For example PIC16F877 includes 8 A/D converters. There is actually only one A/D converter and the inputs are multiplexed and they share the same converter. The width of the A/D converter can be 8-bits or 10-bits. PIC16F877 has a 10-bit converter. An A/D converter requires a reference voltage to operate. This reference voltage is chosen by programming the A/D converter registers and is typically +5V. Thus, if it is a 10-bit converter, then analog voltages with a resolution of 4.88mV can be measured. For example, if the measured analog input voltage is 4.88mV we get the 10-bit digital number 0000000001.

In PIC16F877 the A/D converter is controlled by registers ADCON0 and ADCON1. The bits of ADCON0 are used to select the conversion clock (internal RC oscillator or external clock) and to select which input pin is routed to the A/D converter and to turn on the A/D converter circuitry.ADRESH and ADRESL are the A/D converter result registers. ADCON1 is the second A/D control register. This register controls the format of converted data and mode of the PORTA inputs. The format of converted data can be either left justified or right justified. The mode of the PORTA inputs can be programmed to be a digital pin or an analogue pin. For example, if we set Bits 0-3 of ADCON1 to 0110 then all PORTA pins will be digital I/O pins. Bits 0-3 bits of ADCON1 can also be used to define the reference voltage for the A/D converter.

4.2.4 Oscillator Circuits: [4]

An Oscillator circuit is used to provide a microcontroller with a clock. A clock is needed so that the microcontroller can execute a program. PIC microcontrollers have built-in oscillator circuits and this oscillator can be operated in one of five modes. LP Low-power crystal XT Crystal/resonator HS High-speed crystal/resonator RC resistor capacitor Internal Oscillator (No external components, only in some PIC microcontrollers)

In LP, XT, or HS modes, an external oscillator ca