0% found this document useful (0 votes)
8 views12 pages

Microcontroller Basics Overview

Uploaded by

tamagna1510
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

Microcontroller Basics Overview

Uploaded by

tamagna1510
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Name of subject: Microprocessor and Microcontroller

Unit No.:04
Topic heading: Microcontroller Basics
Course: Diploma in Electrical Engineering. Semester: 5th

Prepared by: SOUMEN GHOSH


Designation: Lecturer in Electronics & Instrumentation Engineering
Name of Polytechnic: Haji Md. Serafat Mondal Government Polytechnic
Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------

Introduction to Microcontroller
Microcontroller is an embedded system. An embedded system which is dedicated for particular one
task. A microcontroller has a CPU (a microprocessor) in addition to a fixed amt of RAM, ROM,
I/O ports and a timer are all embedded together on the chip.
Microprocessor and microcontrollers are widely used in embedded system. Printer is example of
embedded system since the processor inside it performs only one task namely getting data and
printing it. A mouse is an embedded system performs the task of finding the mouse position and
sending to the PC.
The fixed amount of on chip accessories make them ideal for many applications in which cost and
space are critical. Example: Intel’s 8051, Zilog’s Z8 and PIC 16X. What is the difference between
Microprocessor & Microcontroller? Microprocessor is meant the general-purpose microprocessor
such as Intel’s 8085,8086, 80286,80386, Pentium or Motorolla’s 68000,68010,68020,68030,68040
etc. These microprocessors contain no RAM, no ROM, no I/O ports on the chip itself. For this
reason, they are commonly known as General purpose microprocessors. A designer using general
purpose microprocessor such as Pentium or 68040 must add RAM, ROM, I/O ports and Timers etc
externally to make them functional. It becomes bulkier and more expensive. As in microcontroller
has inbuilt RAM, ROM, Timers, Ports and having option of adding extra RAM, ROM timers, ports
also it is compact in design and cheap. Example of some embedded products using microcontroller
are printer, mouse, telephones etc.

Comparison between Microcontrollers and Microprocessors

General purpose microprocessor-based system Microcontroller

2|Page Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic


Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------
Microprocessor Microcontroller

CPU is stand-alone, There is no RAM, ROM, CPU, RAM, ROM, I/O and timer are all in a
I/O, timer in Microprocessor single chip

Designer can decide on the amount of ROM, Fixed amount of on-chip ROM, RAM, I/O
RAM and I/O ports. ports and having option of adding extra
RAM,ROM,I/O ports.
General-purpose Dedicated for particular task.

Circuit complexity of microprocessor-based Circuit complexity of microcontroller-based


system is more system is Less
Expensive Comparatively cheap

Evolution of Microcontrollers
Intel corporation introduced 8-bit microcontroller 8051 in the year [Link] microcontroller
had 128 bytes of RAM,4K bytes of on chip ROM, two timers one serial port, and four ports
(each 8 bits wide) all on a single chip. The 8051 is a 8 bit microcontroller. The 8051 has a total
of four I/O ports, each 8 bits wide all on a single chip. At the time it was also referred to as
“system on chip”. The 8051 is 8 bit microcontroller that means CPU can process 8 bit data at
a time. Data larger than 8 bits has to broken into 8 bit pieces to process to be processed by the
CPU.

3|Page Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic


Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------

Block diagram of 8051 microcontroller

Common and Basic Features of 8051 CPU based Microcontroller


8051 Microcontroller is equipped with lots of advanced features: -

• Bidirectional 8 bit data bus to fetch data


• Unidirectional 16 bit address bus to communicate
• On Chip 4 KB bytes Program Read Only Memory.
• Total 128 bytes of Random Access Memory on Chip.
• Four 8051 Memory Register Banks
• General Purpose Registers are 8 bit
• Two 16-bit counter/timers
• Internal and External interrupts
• Four Ports with 8 bit data transfer
• 16 Bit data pointer
• 16 Bit Program counter
• UART (serial port)

Few Variants of 8051


There are two members in the 8051 family of microcontrollers. they are the 8052 and 8031.
The 8052 has all standard features of the 8051 in addition to extra 128 bytes of RAM and an extra
[Link] also has 8K bytes of an on-chip program ROM instead of 4K bytes.

4|Page Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic


Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------
The 8031 chip is referred to as a ROM less 8051. Since it has 0K bytes of on chip ROM. To use
this chip you must add external ROM to it.
A comparative table of the three members is given below:
Feature 8051 8052 8031
ROM (On- chip program space in bytes) 4K 8K 0K
RAM 128 256 128
Timers 2 3 2
I/O Pins 32 32 32
Serial Port 1 1 1
Interrupt sources 6 8 6

Registers in 8051Microcontroller
In the CPU, registers are used to store information temporarily. That information could be a byte
of data to be processed, or an address pointing to the data to be fetched. The vast majority of 8051
registers are 8 bit registers. In 8051 there is only one data type:8 bits.
D7 D6 D5 D4 D3 D2 D1 D0

The most widely used registers of 8051 microcontroller are A(Accumulator), B, R0, R1, R2, R3,
R4, R5, R6, R7, DPTR(Data Pointer), PC(Program Counter). A(Accumulator), B, R0. R1, R2, R3,
R4, R5, R6, R7 are 8 bit, DPTR (Data Pointer), PC(Program Counter) are 16 bits. Th accumulator,
register A is used for all arithmetic and logic instructions.
A

R0

R1

R2

R3

R4

R5

R6

R7

Some 8 bit registers of 8051

5|Page Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic


Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------

Data Pointer (DPTR) –This is a 16 bit register which is used to furnish address information
for internal and external program memory and for external data memory. DPH (Data pointer
higher byte), DPL (Data pointer lower byte).

DPTR DPH DPL

Stack Pointer and Program counter

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.

Program Counter (PC) –PC contains the address of next instruction to be executed. In 8051
Program Counter is 16 bits wide. That means 8051 can access address 0000H to FFFFH, a total
64K byte of code. On reset PC will set to 0000. After fetching every instruction PC will be
incremented by one.

PC Program Counter

PSW (program status word) register


The Program Status Word (PSW) register is an 8-bit register. It is also referred to as Flag Register.
Although the PSW register is 8-bits wide, the two unused bits are user-definable flags. Four of the
flags are conditional flags, meaning that they indicate some conditions that resulted after an
instruction was executed. These four are CY (carry), AC (auxiliary carry), P(parity), and
OV(overflow).

CY AC F0 RS1 RS0 OV -- P

CY PSW.7 Carry flag


AC PSW.6 Auxiliary carry flag
F0 PSW.5 Available to the user for general purpose
RS1 PSW.4 register bank selector bit 1.
RS0 PSW.3 register Bank selector bit o.

6|Page Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic


Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------
OV PSW.2 Overflow Flag
-- PSW.1 User definable bit
P PSW.0 Parity flag. Set /cleared by hardware each instruction cycle to indicate an odd/even
number of 1 bits in the accumulator.

RAM memory space allocation in the 8051


There are 128 bytes of RAM in the [Link] are divided into three groups.
a) 00-1F(32 bytes) are assigned for Register banks and the stack.
b)20H-2F(16bytes) are set aside for Bit addressable read/write memory.
c) 30H-7F(80 bytes) are used for read and write storage or what is normally called Scratch
Pad. These 80 locations of RAM are widely used for the purpose of storing data and
parameters by 8051 programmers.

7|Page Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic


Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------

Register banks in the 8051


A total of 32 bytes of RAM are set aside for the register banks and stack. These 32 bytes are
divided into 4 banks of registers in which each bank has 8 registers, R0-R7. The following shows
how the 32 bytes are allocated into 4 banks:

Bank 0 Bank 1 Bank 2 Bank 3

R7
R7
R7 R7
R6
R6
R6 R6
R5 R5
R5 R5
R4 R4
R4 R4
R3 R3
R3 R3

R2 R2
R2 R2
R1
R1 R1 R1
R0
R0 R0 R0

8|Page Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic


Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------
Pin Description of the 8051 Microcontroller

In 8051 there are four ports for I/O operations. That of the 40 pins, a total of 32 pins are set aside for
the four ports P0, P1,P2 and P3,where each port takes 8 pins. The rest of the pins are designated as
Vcc, GND,XTAL1,XTAL2,RST,EA,PSEN etc.

Vcc
Pin 40 provides supply voltage to the chip. The voltage source is +5V.
GND
Pin 20 is the ground.
XTAL1 and XTAL2
The 8051 has on-chip oscillator but requires an external clock to run it. Most often a quartz
crystal oscillator is connected to inputs XTAL1 (pin19) and XTAL2(pin 18). The oscillator

9|Page Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic


Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------
circuit usually runs around 12 MHz, although the 8051 (depending on which specific model) is
capable of running at a maximum of 40 MHz.
RST
Pin 9 is the RESET pin. It is an input and is active high (normally low). Upon applying a high pulse
to this pin, the microcontroller will reset and terminate all activities. This is often referred to as
power-on reset. Activating a power-on reset will cause all values after power-on reset.

EA stands for “external access”, is pin number 31. It is an input pin and must be connected to Vcc or
GND as it cannot be left unconnected.
The 8051 family members such as the 8751,89C51,or DS5000,all come with on chip-ROM to store
programs. In such cases, the EA pin is connected to Vcc. For family members such as 8031& 8032 in
which there is no on-chip ROM, code is stored on an external ROM and is fetched by the
8031/[Link] for the 8031 the EA pin must be connected to GND to indicate that the code is
stored externally.

Pin 29 is the Program Store Enable Pin (PSEN). Using this pins, external Program Memory can be
read. Program store enable (PSEN) is an output [Link] 8031 based system in which an external ROM
holds the program code; this pin is connected to the OE pin of the ROM.
ALE
ALE (address latch enable) is an output pin and is active high. The ALE pin is used for demultiplexing
the address and data by connecting to the G pin of the 74LS373 chip When connecting an 8031 to the
external memory, port 0 provides both address and the data. In other words, the 8031 multiplexes
address and data through port 0 to save pins.
Port 0
Port 0 occupies a total of 8 pins from pin 32 to [Link] can be used for Input or Output. It can be used
also the multiplexed low order address/data bus during access to external memory.
Port 1
Bi-directional I/O port. Port 1 occupies a total of 8 pins from pin 1 to [Link] can be used for Input or
Output. The pins in this port have no alternate functions.
Port 2
Port 2 occupies a total of 8 pins from pin 21 to [Link] can be used for Input or Output.
Dual function and general bi-directional I/O port, and also serves as the high order address bus.

10 | P a g e Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic


Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------
Port 3
Port 3 occupies a total of 8 pins, pins 10 through 17. Dual function and general purpose bi-
directional I/O port. It also serves the functions of the special features of the 8051 family.

8051 Timers
The 8051 there are two 16-bit timer registers. These registers are known as Timer 0 and Timer 1. The
timer registers can be used in two modes. These modes are Timer mode and the Counter mode.
Basic registers of timer
Both the timer 0 and timer 1 are 16 bits wide. Since 8051 has an 8-bit architecture; each 16-bit timer
is accessed as two separate registers of low byte and high byte.
The 16-bit registers of timer 0 and timer 1is accessed as low and high byte. The low byte register is
called TL0(timer 0 low byte) or TL1(timer 1 low byte) and TH0(timer 0 high byte) or TH1(timer 1
high byte). These registers can be accessed like any other registers, such as A,B,R0,R1,R2,etc.
For example, the instruction “MOV TLo, #4FH” moves the value 4FH into TL0, the low byte of
timer 0.
TH0 or TH1 TL0 or TL1
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

11 | P a g e Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic


Name of subject: Microprocessor and Microcontroller
Unit No.:04, Topic heading: Microcontroller Basics
------------------------------------------------------------------------------------------------------

TMOD (timer mode) Register: This is an 8-bit register which is used by both timers 0 and
1 to set the various timer modes. In this TMOD register, lower 4 bits are set aside for timer0
and the upper 4 bits are set aside for timer1. In each case, the lower 2 bits are used to set the
timer mode and upper 2 bits to specify the operation.

TMOD Register
In upper or lower 4 bits, one bit is a GATE bit. Every timer has a means of starting and stopping.
Some timers do this by software, some by hardware, and some have both software and
hardware controls. For GATE=0 internal control, start and stop are controlled by software. If
GATE=1 external control, hardware way of starting and stopping the timer by software and an
external source.

The C/T bit and is used to decide whether a timer is used as a time delay generator or an event
counter. If this bit is 0 then it is used as a timer and if it is 1 then it is used as a counter.

In upper and lower 4 bits, M1 and M0 are used to select the timer mode.

M0 M1 Mode Operating Mode


0 0 0 13-bit timer mode
0 1 1 16-bit timer/counters
1 0 2 8-bit auto reload timer/counter;
1 1 3 Spilt timer mode

References:

1. The 8051 Microcontroller and Embedded Systems by Muhammad Ali Mazidi & Janice
Gillispie Mazidi. Publisher: Pearson Education.
2. Online resources.

12 | P a g e Prepared by: Soumen Ghosh, Lecturer, H.M.S.M. Govt. Polytechnic

Common questions

Powered by AI

The 8051 microcontroller has four ports (P0 to P3), each with eight pins for I/O operations. Port 0 serves as a multiplexed low-order address/data bus during external memory accesses, Ports 1 and 2 provide general-purpose bidirectional I/O functions, and Port 3 also supports additional control functions like serial communication and external interrupt handling. Combined, these ports enhance the 8051's ability to interface with external components, making it suitable for a wide range of applications .

The integration of features like UART and multiple I/O options significantly enhances the 8051 microcontroller's application potential by facilitating serial communication and flexible interfacing with peripheral devices. UART enables direct interfacing for communication protocols, while diverse I/O ports allow the microcontroller to perform various tasks simultaneously, such as controlling displays, sensors, and other components, making it ideal for complex embedded applications .

In the 8051 microcontroller, the program counter (PC) is a 16-bit register that holds the address of the next instruction to be executed. Upon reset, it is set to 0000H, and after fetching each instruction, the PC is incremented by one. This allows the microcontroller to sequentially execute instructions stored in memory .

Internal and external interrupts in the 8051 microcontroller allow the CPU to respond to specific events by pausing the current execution flow and executing an interrupt service routine. Internal interrupts are triggered by conditions inside the microcontroller, such as a timer overflow, while external interrupts respond to signals from external components, enabling the microcontroller to handle real-time events and multitasking efficiently .

The Program Status Word (PSW) register in the 8051 microcontroller is an 8-bit register that contains flags indicating the status of the CPU after executing instructions. It includes conditional flags like Carry (CY), Auxiliary Carry (AC), Parity (P), and Overflow (OV). The PSW also includes user-definable flags and bits for register bank selection. These flags help manage and determine the flow of program execution by providing insights into the results of operations .

The 8051 microcontroller's RAM is organized into three main areas: 32 bytes allocated for register banks and stack (addresses 00h to 1Fh), 16 bytes for bit addressable memory (addresses 20h to 2Fh), and 80 bytes for general-purpose scratchpad (addresses 30h to 7Fh). This structured allocation facilitates efficient data handling during program execution, allowing programmers to utilize specific areas for temporary data storage, individual bit manipulation, and stack operations, enhancing overall code efficiency and organization .

In an 8051 system that uses external memory, the ALE (Address Latch Enable) pin plays a crucial role in demultiplexing the address and data lines. During memory access, ALE is activated high to latch the lower byte of the address from Port 0 into an external latch, allowing Port 0 to then carry the data byte. This process efficiently uses port lines for both address and data purposes, optimizing the pin count on the microcontroller .

The introduction of Intel's 8051 microcontroller in 1981 significantly advanced embedded system design by providing a complete 'system on chip' solution with 128 bytes of RAM, 4K bytes of ROM, two timers, a serial port, and four 8-bit wide I/O ports. This single-chip integration enabled designers to create compact and efficient devices for specific tasks without the need for multiple external components .

Microcontrollers integrate a CPU with RAM, ROM, I/O ports, and timers on a single chip, making them ideal for dedicated tasks in embedded systems due to their compact design and cost-effectiveness. In contrast, microprocessors are stand-alone CPUs requiring external components like RAM, ROM, and I/O ports, leading to increased bulk and cost, but offering more flexibility for general-purpose computing .

The 8051 microcontroller supports several timer modes via the TMOD register: Mode 0 is a 13-bit timer, Mode 1 offers a 16-bit timer/counter, Mode 2 is an 8-bit auto-reload timer/counter, and Mode 3 provides a split timer for dual 8-bit operation. These modes enable developers to select suitable operation based on the requirement, such as generating precise time delays with the timer or counting external events with the counter .

You might also like