Professional Documents
Culture Documents
B.SC Electronics - 8051 Microcontroller and Its Applications - Course Syllabus & Material - Unit I (Bharathiar University)
B.SC Electronics - 8051 Microcontroller and Its Applications - Course Syllabus & Material - Unit I (Bharathiar University)
B.SC Electronics - 8051 Microcontroller and Its Applications - Course Syllabus & Material - Unit I (Bharathiar University)
DEPARTMENT OF ELECTRONICS
Semester - V
Prepared By
Mr. S. KUMAR M.Sc., M.Phil., PGDCA., (Ph.D.,)
Assistant Professor in Electronics,
Sri Vasavi College (SF Wing),
Erode - 638 316.
SYLLABUS
UNIT III
DATA TRANSFER AND BRANCH OPERATIONS
Introduction – Internal Data Move - External Data Move – Code Memory Read Only Data
Move – Loop and Jump Instructions – Conditional Jump – Unconditional Jump – Call
Instructions: LCALL and ACALL – Push and Pop Instructions – Simple Programs.
UNIT IV
PERIPHERALS
Timer and Counter: Timer Registers – TMOD – TCON - Mode 1 and 2 Programming –
Counter Programming – Serial: MAX232 – Baud Rate – SBUF Register – SCON Register
– Program to Transfer and Receive Data Serially – Interrupts: Enabling & Disabling
Interrupt.
UNIT V
INTERFACING
Interfacing of LCD – LCD Operation – Pin Descriptions – Command and Data to the LCD
– ADC 0804 – LM34 Temperature Sensor – Stepper Motor – Step Angle – Motor Speed –
Interfacing Key Board – Scanning and Identifying the keys
Text Books:
1. Mohamed Ali Maszidi & Janice Gillispie Maszidi, “The 8051 Microcontroller and
Embedded System”, Pearson Publishers.
INTRODUCTION TO MICROCONTROLLER:
What is a Microcontroller?
A microcontroller is an electronic device belonging to the microcomputer family. These
are fabricated using the VLSI technology on a single chip. There are microcontrollers available
in the present market with different word length starting from 4 bit, 8 bit, 64 bit to 128 bit. This
chapter is about microcontrollers, their architecture, and various features.
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 1
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 2
COMPARISON OF µP & µC:
Microprocessor µP:
It has only the CPU inside; i.e the processing powers such as Intel’s Pentium 1,2,3,4
core 2 duos, i3, i5 etc.
Don’t have RAM, ROM and other peripheral on the chip. The system designer has to
add them externally to make them functional.
Application includes desktop PCs, laptops, notepads etc.
Applications are where tasks are unspecific like developing software, games,
websites, photo editing, creating documents etc.
Since microprocessors cannot be used stand alone as it needs RAM, ROM and other
peripherals the system that uses microprocessors is costlier than a microcontroller.
The clock speed of the microprocessor is quite high as compared to the
microcontroller. This can operate above 1 GHz as they perform complex tasks.
Microcontroller µC:
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 3
Difference Between μP and μC
MICROPROCESSORS MICROCONTROLLER
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 4
Applications
Peripheral controller of a PC
Robotics
In bio-medical equipment
In communication system
In automobiles
In fire detection devices
In light and temperature sensing and controlling devices
Process control and industrial automation devices
In measuring devices such as volt and current meters
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 5
8051 MICROCONTROLLER BLOCK DIAGRAM
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 6
8051 Oscillator and Clock:
What is Oscillator?
The 8051 Has On Chip Oscillator Pin XTAL1 And XTAL2 Are Provided For
Connecting A Resonant Network To From An Oscillator Crystal Frequency Ranges From 1
MHZ To 24 MHZ.
The oscillator formed by the crystal, capacitors, and on chip inverter generates pulse
train at the frequency of the crystal as shown in fig.
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 7
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 8
MEMORY:
Program Memory (ROM) is used to permanently save the program being executed,
while Data Memory (RAM) is used for temporarily storing data and intermediate results
created and used during the operation of the microcontroller.
Program that is to be run can be stored in internal as well as in external ROM but from
where microcontroller will read program depends on the logic of EA pin(microcontroller 31
no. pin).
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 9
Data Memory:
Data Memory (RAM) is used for temporarily storing data and intermediate results
created and used during the operation of the microcontroller. It is often associated with
volatile types of memory where its stored information is lost if the power is removed.
Internal RAM is limited to 128 bytes (256 bytes for 8052), the 8051 supports External
RAM up to 64K.
RAM of 8051 is divided in basic three blocks which are presented in the following
memory map:
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 10
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 11
A or Accumulator (ACC) Register:
The Accumulator or Register A is the most important and most used 8051
Microcontroller SFRs. The Register A is located at the address E0H in the SFR memory
space. The Accumulator is used to hold the data for almost all the ALU Operations.
The name “Accumulator” came from the fact this register is used to accumulate (or
store) the result of all Arithmetic and most of the Logical Operations.
B Register:
The B Register is used along with the ACC in Multiplication and Division operations.
These two operations are performed on data that are stored only in Registers A and B. During
Multiplication Operation, one of the operand (multiplier or multiplicand) is stores in B
Register and also the higher byte of the result.
In case of Division Operation, the B Register holds the divisor and also the remainder of
the result. It can also be used as a General Purpose Register for normal operations and is often
used as an Auxiliary Register by Programmers to store temporary results.
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 12
Register Banks:
The first 32 bytes of RAM (from location 00 to 1F hex) are set aside for the register
banks. These 32 bytes are divided into 4 banks each including 8 registers denoted by
R0-R7.
RAM locations from 00 to 07 hex are set aside for bank 0 in which address location 00
hex is denoted by R0, address location 01 hex is denoted by R1 and so on to address
location 07 hex which is denoted by R7.
RAM locations from 08 to 0F hex are set aside for bank 1 in which address location 08
hex is denoted by R0, address location 09 hex is denoted by R1 and so on to address
location 0F hex which is denoted by R7.
Similarly RAM locations from 10 to 17 hex are set aside for register bank 2 and RAM
locations from 18 to 1F hex are set aside for register bank 3.
Question: There are 4 register bank of R0 to R7. Which register bank do we have access to
when the 8051 is powered up?
Answer: When the 8051 is powered up the default register bank we can access is register bank
0. We can also access other register banks by manipulating certain SFRs.
We can switch to other register banks by use of D4 and D3 bits of PSW (program status word)
register. Any register bank can be selected by changing bits in RS1 and RS0 which are D4 and
D3 bits of PSW.
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 13
Stack Pointer (SP):
SP or Stack Pointer points out to the top of the Stack and it indicates the next data to be
accessed. Stack Pointer can be accesses using PUSH, POP, CALL and RET Instructions. The
Stack Pointer is an 8-bit register and upon reset, the Stack Pointer is initialized with 07H.
When writing a new data byte into the stack, the SP (Stack Pointer) is automatically
incremented by 1 and the new data is written at an address SP+1. When reading data from
stack, the data is retrieved from the Address in SP and after that the SP is decremented by 1
(SP-1).
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 14
Data Pointer Registers:
Data Pointer (DPTR – DPL and DPH)
The Data Pointer is a 16-bit Register and is physically the combination of DPL (Data
Pointer Low) and DPH (Data Pointer High) SFRs. The Data Pointer can be used as a single 16-
bit register (as DPTR) or two 8-bit registers (as DPL and DPH).
DPTR doesn’t have a physical Memory Address but the DPL (Lower Byte of DPTR)
and DPH (Higher Byte of DPTR) have separate addresses in the SFR Memory Space. DPL =
82H and DPH = 83H.
The DPTR Register is used by the programmer addressing external memory (Program –
ROM or Data – RAM).
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 15
Flag & PSW:
Program Status Word (PSW):
The PSW or Program Status Word Register is also called as Flag Register and is one of
the important SFRs. The PSW Register consists of Flag Bits, which help the programmer in
checking the condition of the result and also make decisions.
Flags are 1-bit storage elements that store and indicate the nature of the result that is
generated by execution of certain instructions. The following image shows the contents of the
PSW Register.
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 16
Special Function Registers:
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 17
What Are SFRs?
The 8051 is a flexible microcontroller with a relatively large number of modes of
operations. Your program may inspect and/or change the operating mode of the 8051
by manipulating the values of the 8051’s Special Function Registers (SFRs).
SFRs are accessed as if they were normal Internal RAM. The only difference is that
Internal RAM is from address 00h through 7Fh whereas SFR registers exist in the
address range of 80h through FFh.
Each SFR has an address (80h through FFh) and a name. The following chart provides
a graphical presentation of the 8051’s SFRs, their names, and their address.
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 18
TMOD (Timer Mode)
The TMOD or Timer Mode register or SFR is used to set the Operating Modes of the
Timers T0 and T1. The lower four bits are used to configure Timer0 and the higher four bits
are used to configure Timer1.
IE (Interrupt Enable)
IP (Interrupt Priority)
The IP or Interrupt Priority Register is used to set the priority of the interrupt as High or
Low. If a bit is CLEARED, the corresponding interrupt is assigned low priority and if the bit is
SET, the interrupt is assigned high priority.
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 19
Peripheral Data Registers
SBUF (Serial Data Buffer)
The Serial Buffer or SBUF register is used to hold the serial data while transmission or
reception.
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 20
Input / Output Pins & Ports:
I/O Port Registers (P0, P1, P2 and P3)
The 8051 Microcontroller four Ports which can be used as Input and/or Output. These
four ports are P0, P1, P2 and P3. Each Port has a corresponding register with same names (the
Port Registers are also P0, P1, P2 and P3). The addresses of the Port Registers are as follows:
P0 – 80H, P1 – 90H, P2 – A0H and P2 – B0H.
Each bit in these SFRs corresponds to one physical Pin in the 8051 Microcontroller. All
these Port Registers are both Bit Addressable and Byte Addressable. Writing 1 or 0 on a Port
Register Bit will reflect as an appropriate voltage (5V and 0V) on the corresponding Pin.
If a Port Bit is SET (declared as 1), the corresponding Port Pin will be configured as
Input and similarly if a Port Bit is CLEARED (declared as 0), the corresponding Port Pin is
configured as Output. Upon reset, all the Port Bits are SET (1) and hence, all the Port Pins are
configured as Inputs.
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 21
Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 22