Вы находитесь на странице: 1из 21

Prepared by Tan KL Page 1-1

CHAPTER 1 INTRODUCTION TO MICROPROCESSOR AND MICROCONTROLLER


1.1 NUMBER SYSTEM
THREE number systems those are normally used in digital electronics:
Base 10 (decimal)
Base 2 (binary)
Base 16 (hexadecimal)

1.1.1 BASE 10 (DECIMAL NUMBER)

It is a number system which we use in calculation in our daily life.
It consists of 10 symbols (0,1,2,3, , 9) to represent some counts.
1.1.2 BASE 2 (BINARY NUMBER)
It consists of 2 symbols that is 0 and 1.
Normally we call it as BIT.
The computer can only understand this number. So all information which need to be
processed in computer, they must change into this form of number.
In digital electronics, bit 0 is equal to 0 volt (in between 0 0.8 volt) and bit 1 is
equal to 5 volt (in between 2.0 5 volt) which can lit a LED.







1.1.3 BASE 16 (HEXADECIMAL)
This system is used to represent binary system in most of calculation cases.
It has simplified the usage of a series of binary number into hexadecimal number, such
as, we can represent binary number 1010010110110001
2
into A5B1
16
in hexadecimal
number.
LOGIC 1
LOGIC 0
Unused
5.0 V


2.0 V

0 0
1
V
t
Logic 1 2.0V 5.0V
Logic 0 0V 0.8V
Prepared by Tan KL Page 1-2

It uses 16 symbols to represent a number as shown in the table below:
Decimal Binary Hex
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8

1.1.4 NUMBER CONVERTION
Decimal Binary
Method 1: always divide with 2 and collect the remainder
Example: Convert 25
10
to binary number
Result after
division (rounded) remainder
25/2 = 12 1
12/2 = 6 0
6/2 = 3 0
3/2 = 1 1
1/2 = 0 1
Hence, 25
10
= 11001
2

Method 2: by adding the weight in every bit

2
4
2
3
2
2
2
1
2
0
weight
16 8 4 2 1
1 1 0 0 1
25
10
= 16 + 8 + 1 = 11001
2

Decimal Binary Hex
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

LSB (Least Significant Bit)
MSB (Most Significant Bit)
Prepared by Tan KL Page 1-3

Binary Hexadecimal : collecting 4 bit in one group from the back (LSB)
Example: Convert 100111110101
2
to Hex number.
1001 1111 0101
2

= 9 F 5
= 9F5
16

Hexadecimal Binary : convert every number of Hex to 4 bit binary
Example: Convert 29B
16
to binary number.
2 9 B
16

= 0010 1001 1011
= 001010011011
2
(00 in the front can be neglected 1010011011
2
)

Decimal Hexadecimal : convert the number into binary first, and then into
hexadecimal
Example : Convert 699
10
to Hex
2
9
2
8
2
7
2
6
2
5
2
4
2
3
2
2
2
1
2
0
512 256 128 64 32 16 8 4 2 1
1 0 1 0 1 1 1 0 1 1
2 B B
= 2BB
16
(have to add 00 in the front to make 4 bit in one group)
1.1.5 ADDING 2 HEX NUMBOR
Example: 6 B
16
0110 1011
2

+ A F
16
+ 1010 1111
2

1 1 A
16
1 0001 1010
2



Carry, C = 1
Auxiliary Carry, AC = 1
Numbers of 1 is odd, Parity, P = 1
Prepared by Tan KL Page 1-4

1.2 BASIC LOGIC GATE
1.2.1 AND GATE






1.2.2 OR GATE





1.2.3 NOT GATE









Prepared by Tan KL Page 1-5

1.2.4 EX-OR GATE (Exclusive OR)






1.2.5 NAND GATE







1.2.6 NOR GATE









Prepared by Tan KL Page 1-6

Assignment 1:
a. Convert the following numbers to Hexadecimal number:
i. 11001100
2
ii. 456
10

iii. 001110101110
2
iv. 1011
10

v. 1110001010
2
vi. 1101
10

b. Convert the following numbers to binary number:
i. 5F6A
16
ii. 127
10

iii. 101101
16
iv. 255
10

v. FFFF
16
vi. 256
10

c. Solve the problems below and find out the condition of Carry (C), Auxiliary Carry (AC)
and Parity (P) bit:
i. 5AHex ADD with 36Hex ii. 9DHex ADD with ABHex
iii. 8B
16
AND with 97
16
iv. A6
16
AND with C3
16

v. A7
16
OR with C1
16
vi. 93
16
OR with C7
16

vii. 4C
16
EX-OR with 8A
16
viii. 23
16
EX-OR with EC
16

ix. Data 78
16
is OR-ed with data 5C
16
first and then is AND-ed with data A7
16

x. Data FA
16
is AND-ed with data D8
16
first and then EX-OR-ed with data 67
16


Prepared by Tan KL Page 1-7

1.3 SAIZ AND UNIT OF DATA













`






Bit : is the smallest data in digital electronics. It consists of 0 or 1
Byte : data consists of 8 bit or 2 nibble data
Nibble : data consists of half byte or 4 bit data
Word : data consists of 2 byte or 4 nibble or 16 bit data
Long Word : data consists of 2 Word or 4 byte or 32 bit data

Example :
5 F 9 A Hex 0101 1111 1001 1010
2

16 bit data or 4 nibble data or 2 byte data or 1 Word data or half
Long Word data



Bit or

Nibble

0

1

0

0


Byte

1

0

1

1

0

0

0

1


Word

1

1

0

0

0

0

1

1



1

0

0

0

1

0

0

0

0 1
Prepared by Tan KL Page 1-8

1.3.1 TERMS FOR MEMORY CAPACITY
Kilobyte (K) 2
10
Byte (1024 byte)
Megabyte (M) 2
20
byte (1,048,576 byte)
Gigabyte (G) Gigabyte (G) : 2
30
byte (1,073,741,824 byte)
Terabyte (T) : 2
40
byte (???)

1.4 THREE COMMON TERMS IN DIGITAL ELECTRONICS
Microcomputer
Microprocessor
Microcontroller

1.4.1 BASIC ELEMENTS OF MICROCOMPUTER



















Memor
y
Outp
ut
Inpu
Contr
ol
ALU
Microprocessor
Microcomputer
A complete set of a
computer
Prepared by Tan KL Page 1-9

A microcomputer system consists of the following components:
Peripheral Input
Peripheral Output
Peripheral Storage
Central Processing Unit

1.4.1 Peripheral Input
It is a tool to be used to prepare data or information which will be processed by Central
Processing Unit.
Example: Joystick, Keyboard, Sensor, Scanner

1.4.2 Peripheral Output
It is a tool to be used to display data or information which has been processed by
Central Processing Unit.
Example: Monitor, Printer, Speaker

1.4.3 Peripheral Memory
It is a tool to be used to store data or information which will be processed or has been
processed by Central Processing Unit.
Example: Hard disk, CD-ROM, RAM, ROM, Pen drive

1.4.4 Central Processing Unit (CPU)
It is the most important part in microcomputer system. It acts as a brain of a
microcomputer system. It is also called Microprocessor.
In here the data are gathered, processed and sent out to display.
It can perform operations such as arithmetic (addition, deduction, multiplication and
division) and logic (AND, OR, NOT etc.) operation and make decision after operation.
A general internal architecture of a CPU/Microprocessor is shown in the next page.
Example: 80486, Pentium II, AMD Atron
Prepared by Tan KL Page 1-10














1.4.5 BASIC CONNECTION OF A MICROCOMPUTER SYSTEM
















Prepared by Tan KL Page 1-11

1.5 MICROPROCESSOR (CPU)

It is the most important part in a microcomputer system. It acts as a brain of a
microcomputer system.
In here the data are gathered, processed and put into display through peripheral
output.
It can perform operations such as arithmetic (addition, deduction, multiplication and
division) and logic (AND, OR, NOT etc.) operation and make decision after operation.















1.5.1 FUNCTION OF COMPONENTS IN A MICROPROCESSOR

i. ALU (Arithmetic Logic Unit)
It performs arithmetic task such as addition, deduction, multiplication and
division and logic task such as AND, OR, NOT and etc.



Prepared by Tan KL Page 1-12

ii. ACC (Accumulator)
It is a register which can store data for temporary before sending to process in
ALU and also can store the processed data before sending to store in the
memory or display through peripheral output.
It is just like a entrance for a data to go in and come out from ALU.

iii. Flag register/PSW (Program Status Word ) register
This register contains information regarding the result of a process which has
been carried out by ALU.
It tells the user whether the result has Carry (CY), Auxiliary Carry (AC), Odd or
Even Parity (P) or Overflow (OV) or the other way round.
It also consists information regarding registers from which bank will be working
on (will be discussed further in Chapter 2).

iv. Program Counter (PC)
It controls the sequence in which the instructions in a program are performed.
Normally, it does this by counting in the sequence, that is 0, 1, 2, 3,
At any given time, the count indicates the location in memory from which the
next location of information/instruction is to be taken.

v. Stack Pointer (SP)
This register will store the contains of Program Counter (location of memory)
for a short time when there is subroutine/sub-program occurs in the program.
This register will be taken place when some particular instructions, such as
PUSH, POP, CALL and RET are used in the program.

vi. Data Register
This register is a temporary storage location for data going to or coming from
the data bus.
Prepared by Tan KL Page 1-13

vii. Address Register
This register is another temporary storage location.
It holds the address of the memory location or I/O device that is used in the
operation presently being performed.

viii. Instruction Decoder
After an data is pulled from memory and placed in the data register, the data is
decoded by this circuit.
The decoder checks the code and decides which operation is to be performed.

ix. Controller- sequencer
This unit will produce a variety of control signals to carry out the instruction.
Since each instruction is different, a different combination of control signals is
produced for each instruction.

x. Data Bus
It is a group of wires that is used to channel data (which to be processed or
after processed) from peripherals (memory or I/O devices) to CPU or vice versa.

xi. Address Bus
It is a group of wires that is used to channel locations of data which will be or
has been processed.

xii. Control Bus
It is a group of wires that is used to send control signals (such as MEMW,
MEMR, IOR, IOW, interrupt and DMA) from CPU to peripheral (memory or I/O
devices) or vice versa.


Prepared by Tan KL Page 1-14

1.6 MICROCONTROLLER (MC)
It is also called computer in a single chip.
Inside MC we can find the important components which are needed in microcomputer
system, such as CPU, RAM, ROM and peripheral I/O.












Prepared by Tan KL Page 1-15

1.6.1 THE DIFFERENCES BETWEEN MICROPROCESSOR AND MICROCONTROLLER














1.7 Evolution Of Microprocessor
Name Date Transistors Microns
Clock
speed
Data
width
MIPS
8080 1974 6,000 6 2 MHz 8 bits 0.64
8088 1979 29,000 3 5 MHz
16 bits
8-bit
bus
0.33
80286 1982 134,000 1.5 6 MHz 16 bits 1
80386 1985 275,000 1.5 16 MHz 32 bits 5
80486 1989 1,200,000 1 25 MHz 32 bits 20
Pentium 1993 3,100,000 0.8 60 MHz
32 bits
64-bit
bus
100
Microprocessor
1. CPU, ROM, RAM, timer and I/O devices are
all in seperated unit.
2. System designer can determine the capasity
for RAM, ROM and I/O devices.
3. Capacity of memory and I/O port can be
added (expansived) at any time.
4. Suitable for project which has expanded
space.
5. For general-purposes usages
Microcontroller
1. CPU, ROM, RAM, timer and I/O devices
are all in a chip (Embedded in a chip).
2. Capacity of RAM,ROM and I/O devices
have been determined during fabrication.
3. Capacity of memory and I/O port cannot
be added (expansived) at any time.
4. Suitable for project which has limited
space.
4. For specific-purposes usages
Prepared by Tan KL Page 1-16









The date is the year that the processor was first introduced. Many processors are re-
introduced at higher clock speeds for many years after the original release date.
Transistors is the number of transistors on the chip. You can see that the number of
transistors on a single chip has risen steadily over the years.
Microns is the width, in microns, of the smallest wire on the chip. For comparison, a human
hair is 100 microns thick. As the feature size on the chip goes down, the number of
transistors rises.
Clock speed is the maximum rate that the chip can be clocked at. Clock speed will make
more sense in the next section.
Data Width is the width of the ALU. An 8-bit ALU can add/subtract/multiply/etc. two 8-
bit numbers, while a 32-bit ALU can manipulate 32-bit numbers. An 8-bit ALU would have
to execute four instructions to add two 32-bit numbers, while a 32-bit ALU can do it in
one instruction. In many cases, the external data bus is the same width as the ALU, but
not always. The 8088 had a 16-bit ALU and an 8-bit bus, while the modern Pentiums fetch
data 64 bits at a time for their 32-bit ALUs.
MIPS stands for "millions of instructions per second" and is a rough measure of the
performance of a CPU. Modern CPUs can do so many different things that MIPS ratings
lose a lot of their meaning, but you can get a general sense of the relative power of the
CPUs from this column.
Pentium II 1997 7,500,000 0.35
233
MHz
32 bits
64-bit
bus
~300
Pentium III 1999 9,500,000 0.25
450
MHz
32 bits
64-bit
bus
~510
Pentium 4 2000 42,000,000 0.18 1.5 GHz
32 bits
64-bit
bus
~1,700
Pentium 4
"Prescott"
2004 125,000,000 0.09 3.6 GHz
32 bits
64-bit
bus
~7,000
Prepared by Tan KL Page 1-17

Exercise:

a. List out 4 important components of a microcomputer system and briefly describe their
functions.
b. Describe briefly the functions for the components below:
i. Address Bus
ii. Data Bus
iii. Control Bus
c. Draw a block diagram of a microprocessor and briefly describe function of its component.
d. State the differences between microprocessor and microcontroller.
e. State the function for the components below:
i. ALU iv. Stack Pointer
ii. Accumulator v. Program Status Word Register
iii. Program Counter vi. Controller Sequencer
f. Different microprocessors have different data bus such as 8-bit, 16-bit and 32-bit. State
2 advantages and 2 disadvantages of a smaller size of data bus as compared to a wider size
of data bus of microprocessors.
Prepared by Tan KL Page 1-18

1.7 EXECUTING A PROGRAM
Before a program can be run, it must be placed in memory.
There are 2 phases involving in executing a program, those are the fetch phase and
the executing phase.

















ALU
Control Unit
(Controller
Sequencer)
Instruction
Decoder
ACCUMULATOR
PROGRAM
COUNTER
ADDRESS
REGISTER
CARRY
FLAG
DATA
REGISTER
CLOCK and
CONTROL
LINES
(AR)
(DR)
(PC)
Example:
Program
ADDRESS CODE
00000000 01110100
00000001 00010000
00000010 00100100
00000011 00000111
00000100 11110101
00000101 00110000
00000110 11110100
MEMORY
HEX
00H
01H
02H
03H
04H
05H
06H

MOV A, #10H
ADD A, #07H
MOV 30H, A
MOV A, #10H
Binary code which
represents a program
Prepared by Tan KL Page 1-19

To execute a program, the program needs to store in memory first, that is in
Program/Code Memory (ROM). This means that the program needs to be translated into
the machine language (binary code) and stored in the memory.
The program will be executed step-by-step from the first address which is 00000000B
(00H).
This first address (00H) will be always referred by MP when there is RESET operation
is carring out.
The Fetching Phase
** The phase which CPU fetches the instruction from main memory via the data bus into
the Instruction Register (IR) so that it can be decoded and executed
i. When the Microprocessor (MP) is ON-ed, the contain of Program Counter (PC) is
set to the first address, that is 00H automatically.
ii. Then, this address is passed to the Address Register (AR = 00H).
iii. The contain of PC is incremented by 1 automatically. So the contain of PC is 01H
now.
iv. The contain of AR (00H) is placed on the Address Bus so that the MP will go to the
addressed location to obtain the data in the addressed location, which is 00H.
v. Then, the data which is in the location of 00H is passed through the Data Bus and
send to the Data Register (DR) which is inside the MP.
vi. From the DR, the data is passed to the Instruction Decoder to interpret the data.
vii. In this case, the instruction MOV A (with code = 01110100B) is interpreted, that is,
moving/copying something into Accumulator (A stands for Accumulator).
Prepared by Tan KL Page 1-20

viii. Following this, the Control Unit (Controller Sequencer) produces control signals to
get the data which is in the following location of memory (01H) and place it into
Accumulator, as what has requested by the instruction.
The Execute Phase
In this phase, CPU will carry out the requirement on the instruction. In this case, the
CPU will move/copy data into Accumulator.
i. The contain of PC (01H) is sent to AR (AR = 01H).
ii. The contain of PC, as usual is incremented by 1 and become 02H now.
iii. The contain of AR is placed on the Address Bus. Then, the location of the memory
is identified, which is 02H.
iv. The data in the location of 02H is placed on Data Bus and is sent to the DR in the
MP.
v. From DR, the data straight away sends to Accumulator as what has requested
before (MOV A).
vi. So, now the data 10H is inside the Accumulator. The instruction MOV A, #10H
has been executed.
vii. These program-executional steps will be the same for any other instruction.
1.8 TERMS OF PROCESSING DATA IN MICROPROCESSOR
Instruction Cycle
It is the process by which a computer retrieves a program instruction from its memory,
determine what actions the instruction required, and carry out the actions.
This cycle is repeated continuously by the CPU, from booting up to shutting down of a
computer.
Prepared by Tan KL Page 1-21

Exercise:
a. With the help of a suitable block diagram, explain briefly the steps to execute ADD A,
#74H.

Вам также может понравиться