B.SC Electronics - 8051 Microcontroller and Its Applications - Course Syllabus & Material - Unit I (Bharathiar University)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

SRI VASAVI COLLEGE, ERODE

(SELF FINANCE WING)

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

8051 MICROCONTROLLER AND ITS APPLICATIONS


UNIT I
MICROCONTROLLER OVERVIEW
Introduction to Microcontroller – Comparison of µP & µC – 8051 Microcontroller Block
Diagram – 8051 Oscillator and Clock – A, B & Register Banks – Stack - Program Counter
& Data Pointer - Flag & PSW – Special Function Registers – Internal Memory – Input /
Output Pins & Ports.
UNIT II
ADDRESSING MODES, ARITHMETIC and LOGICAL INSTRUCTION
Introduction – Addressing Modes: Direct – Indirect – Register - Indexed – Arithmetic
Instructions: Addition, Subtraction, Multiplication, Division, Increment And Decrement
Logic & Compare Instructions: AND, OR, XOR, CPL & Compare – Rotate & Swap
Instruction: RR, RL, RRC, RLC - Simple Programs.

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.

2. Kenneth J. Ayala, “The 8051 Microcontroller Architecture, Programming and


Application” 2nd Edition, Penram International
UNIT - I
MICROCONTROLLER OVERVIEW

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:

 In a microcontroller CPU, RAM, ROM, and other peripherals are embedded on a


single chip.
 At times it is termed a mini computer or a computer on a single chip.
 Some giants in the manufacturing business of microcontrollers are ATMEL,
microchip, TI, Freescale, Philips, Motorola etc.
 Designed to perform specific tasks. ie, the relationship between the input and output
is defined.
 Since the applications are very specific, they need small resources like RAM, ROM,
I/O ports and hence can be embedded on a single chip.
 The clock speed of a microcontroller varies from a few MHz to 30-50 MHz.

Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 3
Difference Between μP and μC

MICROPROCESSORS MICROCONTROLLER

 Contains ALU,GP registers, SP,  In addition, it contains inbuilt


PC, clock timing circuit and ROM, RAM I/O devices,
interrupts Timers/Counters, etc..,
 Many instructions to move data  One or two instructions to move
between Memory and CPU data between memory and CPU
 One or two bit handling  Powerful Boolean processor
instructions are available instruction set is available
 Access time for memory and I/O  Less access time for inbuilt
devices are more memory and I/O devices
 Requires more hardware,  Requires less hardware, reduced
increase in PCB size PCB size and increased reliability
 More flexible from design point  Less Flexible
of view  Separate memory Map for data and
 Single memory map for data and code
code  More pins are multifunctional
 Few pins are multifunctional  Microcontroller based systems are
 Microprocessor based computers normally operated with RTOS like
are normally operated with tiny RTOS, VxWorks, PSOS, RT
general purpose operating Linux, etc..,
systems like Windows, Unix etc.,

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

8051 Microcontroller PIN Diagram:

Mr.S.KUMAR, Asst.Professor, Dept.of Electronics, Sri Vasavi College (SF Wing), Erode. Page 6
8051 Oscillator and Clock:
What is Oscillator?

An oscillator is a circuit which produces a continuous, repeated, alternating waveform


without any input. Oscillators basically convert unidirectional current flow from a DC source
into an alternating waveform which is of the desired frequency, as decided by its circuit
components.

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:

The 8051 has generally two types of memory:

1. Program memory (ROM)

2. Data memory (RAM)

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 Memory: Internal Memory:


Program/Code memory is the memory that holds the actual 8051 program that is to be
run. This memory is limited to 64 KB. The first models of the 8051 microcontroller family (for
example 8031 or 8032) did not have internal program memory, so it was added as an external
separate chip. All later models have a few Kbyte of on-chip ROM. For example 8051 has 4KB
and 8052 has 8KB of on-chip ROM.

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).

If /EA=0: MC will Read Program from External ROM

If /EA=1: MC will Read Program from Internal ROM

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.

Some of the operations where the Accumulator is used are:

 Arithmetic Operations like Addition, Subtraction, Multiplication etc.


 Logical Operations like AND, OR, NOT etc.
 Data Transfer Operations (between 8051 and External Memory)

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.

Register B is located at the address F0H of the SFR Address Space.

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.

 Each register from R0 to R7 is of 1 byte.

 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).

Program Counter & Data Pointer:


Program Counter:
Another important register in the 8051 is the PC (program counter). The program
counter points to the address of the next instruction to be executed. As the CPU fetches the
opcode from the program ROM, the program counter is incremented to point to the next
instruction. The program counter in the 8051 is 16 bits wide. This means that the 8051 can
access program addresses 0000 to FFFFH, a total of 64K bytes of code.

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.

The following table describes the function of each flag.

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.

Peripheral Control Registers


PCON (Power Control)
The PCON or Power Control register, as the name suggests is used to control the 8051
Microcontroller’s Power Modes and is located at 87H of the SFR Memory Space. Using two
bits in the PCON Register, the microcontroller can be set to Idle Mode and Power Down
Mode.

SCON (Serial Control)


The Serial Control or SCON SFR is used to control the 8051 Microcontroller’s Serial
Port. It is located as an address of 98H. Using SCON, you can control the Operation Modes of
the Serial Port, Baud Rate of the Serial Port and Send or Receive Data using Serial Port.
SCON Register also consists of bits that are automatically SET when a byte of data is
transmitted or received.

TCON (Timer Control)


Timer Control or TCON Register is used to start or stop the Timers of 8051
Microcontroller. It also contains bits to indicate if the Timers has overflowed. The TCON SFR
also consists of Interrupt related bits.

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)

The IE or Interrupt Enable Register is used to enable or disable individual interrupts. If


a bit is SET, the corresponding interrupt is enabled and if the bit is cleared, the interrupt is
disabled. The Bit7 of the IE register i.e. EA bit is used to enable or disable all the interrupts.

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.

TL0/TH0 (Timer 0 Low/High)


The Timer 0 consists of two SFRs: TL0 and TH0. The TL0 is the lower byte and the
TH0 is the higher byte and together they form a 16-bit Timer0 Register.

TL1/TH1 (Timer 1 Low/High)


The TL1 and TH1 are the lower and higher bytes of the Timer 0.

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

You might also like