Module - 1: 1.1 Microprocessors V/S Microcontrollers
Module - 1: 1.1 Microprocessors V/S Microcontrollers
MODULE - 1
1.1 MICROPROCESSORS V/S MICROCONTROLLERS
Microprocessor Microcontroller
It has many instructions to move data between It has few instructions to move data between
memory and CPU memory and CPU
Less number of pins are multifunctional More number of pins are multifunctional
Single memory map for data and code Separate memory map for data and code
(program) (program)
Access time for memory and IO are more Less access time for built in memory and IO.
More flexible in the design point of view Less flexible since the additional circuits which is
residing inside the microcontroller is fixed for a
particular microcontroller
Large number of instructions with flexible Limited number of instructions with few
addressing modes addressing modes
4
8051-Microcontroller-18EC46 4 Sem ECE
RISC CISC
Only load/store instructions are used to access In additions to load and store instructions,
memory memory access is possible with other
instructions also.
5
8051-Microcontroller-18EC46 4 Sem ECE
Data Program
Data
Memory Memory
Address Bus
Address Bus
It uses single memory space for both It has separate program memory and data
instructions and data. memory
It is not possible to fetch instruction code and Instruction code and data can be fetched
data simultaneously
Execution of instruction takes more machine Execution of instruction takes less machine
cycle cycle
Also known as control flow or control driven Also known as data flow or data driven
computers computers
Simplifies the chip design because of single Chip design is complex due to separate memory
memory space space
6
8051-Microcontroller-18EC46 4 Sem ECE
The program stored in the computer memory in the form of binary numbers is called machine
instructions. The machine language program is called object code.
The assembly language program the programmer enters is called source code. The source code
(assembly language) is translated to object code (machine language) using assembler.
Programs can be written in high level languages such as C, C++ etc. High level language will be
converted to machine language using compiler or interpreter. Compiler reads the entire program
and translate into the object code and then it is executed by the processor. Interpreter takes one
statement of the high level language as input and translate it into object code and then executes.
7
8051-Microcontroller-18EC46 4 Sem ECE
General
A B Purpose I/O
RAM Port 1
I/O
A8-
Port 2 A15
ROM
DPTR
PC
DPH I/O
INT
DPL
Port 3 CNTR
SERIAL
RD/WR
E IE
ALE System General IP
Timing purpose PCON
PSEN
area SBUF
XTAL1 System SCON
interrupt
XTAL2 Bit addressible TCON
timers area TMOD
RESET Register Bank 3 TL0
Data
buffers Register Bank 2 TH0
Register Bank 1 TL1
Memory
Register Bank 0 TH1
VCC
GND control SFR and
General Purpose RAM
8051 has 4 K Bytes of internal ROM. The address space is from 0000 to 0FFFh. If the
program size is more than 4 K Bytes 8051 will fetch the code automatically from external
memory.
Accumulator is an 8 bit register widely used for all arithmetic and logical operations.
Accumulator is also used to transfer data between external memory. B register is used along
with Accumulator for multiplication and division. A and B registers together is also called
MATH registers.
8
8051-Microcontroller-18EC46 4 Sem ECE
PSW (Program Status Word). This is an 8 bit register which contains the arithmetic status of
ALU and the bank select bits of register banks.
CY AC F0 RS1 RS0 OV - P
CY - carry flag
AC - auxiliary carry flag
F0 - available to the user for general purpose
RS1,RS0 - register bank select bits
OV - overflow
P - parity
Stack Pointer (SP) – it contains the address of the data item on the top of the stack. Stack
may reside anywhere on the internal RAM. On reset, SP is initialized to 07 so that the default
stack will start from address 08 onwards.
Data Pointer (DPTR) – DPH (Data pointer higher byte), DPL (Data pointer lower byte). This
is a 16 bit register which is used to furnish address information for internal and external
program memory and for external data memory.
Program Counter (PC) – 16 bit PC contains the address of next instruction to be executed.
On reset PC will set to 0000. After fetching every instruction PC will increment by one.
Pinout Description
Pins 1-8 PORT 1. Each of these pins can be configured as an input or an output.
Pin 9 RESET. A logic one on this pin disables the microcontroller and clears the contents of
most registers. In other words, the positive voltage on this pin resets the
microcontroller. By applying logic zero to this pin, the program starts execution from
the beginning.
Pins10-17 PORT 3. Similar to port 1, each of these pins can serve as general input or output.
Besides, all of them have alternative functions
9
8051-Microcontroller-18EC46 4 Sem ECE
10
8051-Microcontroller-18EC46 4 Sem ECE
BANK 3
R4 1C 2F
7F 78 7F
R3 1B
2E
77 70 7E
R2 1A
R1 19 2D
6F 68 .
R0 18 2C
67 60 .
R7 17
2B
5F 58 .
R6 16
R5 15
57 50 .
BANK 2
2A
R4 14 29
4F 48 .
R3 13
28
47 40 .
R2 12
R1 11 27
3F 38 .
R0 10 26
37 30 .
R7 0F 2F 28
R6 0E 25 32
27 20
R5 0D 24 31
BANK 1
R4 0C 1F 18
R3 0B
23 30
17 10
R2 0A 22
R1 09 21 0F 08
R0 08
R7 07
20 07 00 General purpose memory
R6 06
R5 05
BANK 0
Working Registers
Register Banks: 00h to 1Fh. The 8051 uses 8 general-purpose registers R0 through R7 (R0, R1,
R2, R3, R4, R5, R6, and R7). There are four such register banks. Selection of register bank can be
done through RS1,RS0 bits of PSW. On reset, the default Register Bank 0 will be selected.
Bit Addressable RAM: 20h to 2Fh . The 8051 supports a special feature which allows access to bit
variables. This is where individual memory bits in Internal RAM can be set or cleared. In all there
are 128 bits numbered 00h to 7Fh. Being bit variables any one variable can have a value 0 or 1. A bit
variable can be set with a command such as SETB and cleared with a command such as CLR.
Example instructions are:
SETB 25h ; sets the bit 25h (becomes 1)
CLR 25h ; clears bit 25h (becomes 0)
Note, bit 25h is actually bit 5 of Internal RAM location 24h.
The Bit Addressable area of the RAM is just 16 bytes of Internal RAM located between 20h and 2Fh.
General Purpose RAM: 30h to 7Fh. Even if 80 bytes of Internal RAM memory are available for
general-purpose data storage, user should take care while using the memory location from 00 -2Fh
11
8051-Microcontroller-18EC46 4 Sem ECE
since these locations are also the default register space, stack space, and bit addressable space. It is
a good practice to use general purpose memory from 30 – 7Fh. The general purpose RAM can be
accessed using direct or indirect addressing modes.
Number of address lines required for 16 Kbyte memory is 14 lines and that of 32Kbytes of
memory is 15 lines.
PSEN PSEN
A14 A14
A13 A13
A13
A12 A12
A12
… 32 Kbyte
..
A9 .
A8
A8 WE
. RAM
WR 16 Kbyte .
RD OE
A3
AL A7 RAM
LE A2
..
8051 A0-A7 A0-A7 A1
A1
A0
A0
LOWER BYTE
EA ADDRESS
GND [AD0 – AD7] DAT DAT
A A
O/P O/P
AD0
- DATA BUS [AD0 – AD7]
AD7
The lower order address and data bus are multiplexed. De-multiplexing is done by the latch.
Initially the address will appear in the bus and this latched at the output of latch using ALE signal.
The output of the latch is directly connected to the lower byte address lines of the memory. Later
data will be available in this bus. Still the latch output is address it self. The higher byte of address
bus is directly connected to the memory. The number of lines connected depends on the memory
size.
The RD and WR (both active low) signals are connected to RAM for reading and writing the data.
PSEN of microcontroller is connected to the output enable of the ROM to read the data from the
memory.
EA (active low) pin is always grounded if we use only external memory. Otherwise, once the
program size exceeds internal memory the microcontroller will automatically switch to external
memory.
1.8 STACK
A stack is a last in first out memory. In 8051 internal RAM space can be used as stack. The address
of the stack is contained in a register called stack pointer. Instructions PUSH and POP are used for
stack operations. When a data is to be placed on the stack, the stack pointer increments before
storing the data on the stack so that the stack grows up as data is stored (pre-increment). As the
data is retrieved from the stack the byte is read from the stack, and then SP decrements to point the
next available byte of stored data (post decrement). The stack pointer is set to 07 when the 8051
resets. So that default stack memory starts from address location 08 onwards (to avoid overwriting
the default register bank ie., bank 0).
13