0% found this document useful (0 votes)
35 views47 pages

Esiot Unit1 Notes

Embedded systems and internet of things unit 1 notes BE-CSE

Uploaded by

priyasrtimmy
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)
35 views47 pages

Esiot Unit1 Notes

Embedded systems and internet of things unit 1 notes BE-CSE

Uploaded by

priyasrtimmy
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
You are on page 1/ 47

CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M.

SUNDHARI AP/CSE

CS3691 EMBEDDED SYSTEMS AND IOT LTPC


3024

COURSE OBJECTIVES:
 To learn the internal architecture and programming of an embedded processor.
 To introduce interfacing, I/O devices to the processor.
 To introduce the evolution of the Internet of Things (IoT).
 To build a small low-cost embedded and IoT system using Arduino/Raspberry Pi/ open
platform.
 To apply the concept of Internet of Things in real world scenario.
UNIT I 8-BIT EMBEDDED PROCESSOR 9
8-Bit Microcontroller – Architecture – Instruction Set and Programming – Programming Parallel Ports– Timers and
Serial Port – Interrupt Handling.

UNIT II EMBEDDED C PROGRAMMING 9


Memory And I/O Devices Interfacing – Programming Embedded Systems in C – Need for RTOS –Multiple Tasks
and Processes – Context Switching – Priority Based Scheduling Policies.

UNIT III IOT AND ARDUINO PROGRAMMING 9

Introduction to the Concept of IoT Devices – IoT Devices Versus Computers – IoT Configurations – Basic
Components – Introduction to Arduino – Types of Arduino – Arduino Toolchain – Arduino Programming
Structure – Sketches – Pins – Input/Output from Pins Using Sketches – Introduction to Arduino Shields –
Integration of Sensors and Actuators with Arduino.

UNIT IV IOT COMMUNICATION AND OPEN PLATFORMS 9


IoT Communication Models and APIs – IoT Communication Protocols – Bluetooth – WiFi – ZigBee

– GPS – GSM modules – Open Platform (like Raspberry Pi) – Architecture – Programming –Interfacing –
Accessing GPIO Pins – Sending and Receiving Signals Using GPIO Pins – Connecting to the Cloud.

UNIT V APPLICATIONS DEVELOPMENT 9

Complete Design of Embedded Systems – Development of IoT Applications – Home Automation –

Smart Agriculture – Smart Cities – Smart Healthcare.

45 PERIODS

1|Page
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

INTRODUCTION
EMBEDDED SYSTEMS
 Embedded System is a system composed of hardware, application software and real time operating
system. It can be small independent system or large combinational system
 An embedded system can be a small independent system or a large combinational system. It is a
microcontroller-based control system used to perform a specific task of operation
An embedded system is a combination of three major components:
 Hardware: Hardware is physically used component that is physically connected with an embedded
system. It comprises of microcontroller based integrated circuit, power supply, LCD display etc.
 Application software: Application software allows the user to perform varieties of application to be
run on an embedded system by changing the code installed in an embedded system.
 Real Time Operating system (RTOS): RTOS supervises the way an embedded system work. It act
as an interface between hardware and application software which supervises the application software
and provide mechanism to let the processor run on the basis of scheduling for controlling the effect of
latencies.

Basic Structure of an Embedded System

Applications Areas of Embedded system :


 Television
 stereo
 remote control
 phone / mobile phone
 refrigerator
 microwave
 washing machine

2|Page
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE
UNIT I : 8-BIT EMBEDDED PROCESSOR
 8-Bit Microcontroller
 Architecture
 Instruction Set and programming
 Programming Parallel Ports
 Timers and Serial Port
 Interrupt Handling.

1.1. 8051 MICROCONTROLLER


 8051 microcontroller is an 8-bit microcontroller created in 1981 by Intel Corporation.
 It has an 8-bit processor that simply means that it operates on 8-bit data at a time.
 It is among the most popular and commonly used microcontroller.
 As it is an 8-bit microcontroller thus has 8-bit data bus, 16-bit address bus. Along with that,
it holds 4 KB ROM with 128 bytes RAM.
1.1.1 What a Microcontroller is?
 A microcontroller is an integrated chip designed under Very Large-Scale Integration
technique
 It consists of a processor with other peripheral units like
* memory
* I/O port
* timer
* decoder
* ADC
 A microcontroller is basically designed in such a way that all the working peripherals are
embedded in a single chip with the processor.
 Any programmable device holds a processor, memory, I/O ports and timer within it. but a
microcontroller contains all these components embedded in a single chip. This single-chip
manages the overall operation of the device.
 A microprocessor simply contains a CPU that processes the operations with the help of other
peripheral units. Microprocessors are used where huge space is present to inbuilt a large
motherboard like in PCs.

3|Page
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE
1.2. ARCHITECTURE OF 8051 MICROCONTROLLER

ARCHITECTURAL BLOCK DIAGRAM:

ARCHITECTURE OF 8051 MICROCONTROLLER:

4|Page
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE
The 8051 architecture consists of these specific features:
 Eight-bit CPU with registers A (the accumulator) and B
 Sixteen-bit program counter (PC) and data pointer (DPTR)
 Eight-bit program status word (PSW)
 Eight-bit stack pointer (SP)
 Internal ROM or EPROM (8751) of 0 (8031) to 4K (8051)
 Internal RAM of 128 bytes:
 Four register banks, each containing eight registers
 Sixteen bytes, which may be addressed at the bit level
 Eighty bytes of general-purpose data memory
 Thirty-two input/output pins arranged as four 8-bit ports: PO-P3
 Two 16-bit timer/counters: TO and Tl
 Full duplex serial data receiver/transmitter: SBUF
 Control registers: TCON, TMOD, SCON, PCON, IP, and IE
 Two external and three internal interrupt sources
 Oscillator and clock circuits
1.2.1. CENTRAL PROCESSING UNIT (CPU):
 8051 uses the 8-bit processor. This unit carries out the operation on 8-bit data.
 A processor is the heart of microcontroller.
 As the execution of the program stored in the memory is performed by the processor.
 The unit performs arithmetic and logical operations on 8-bit data as it has ALU, with internal
registers and program counters.
 Several logical operations are performed by the ALU according to the program stored in the
memory.
 The processor of 8051 microcontrollers possesses a special feature by which it can process
single bit or 8-bit data.
 This simply means that it has the ability to access each single bit data either to clear, set or
move etc. for any logical computation.
1.2.2. Memory:
 Basically 8051 microcontroller consists of on-chip program memory i.e., ROM and on-
chip data memory i.e., RAM.
ROM
 8051 microcontroller has 4 KB ROM with 0000H to 0FFFH as the addressable space.
 It is completely a program or code memory that means used by the programmer to store
the programs that are to be executed by the microcontroller.
 The operations that are executed by the device in which the microcontroller is present
are stored in the ROM of the memory at the time of fabrication. Hence cannot be
changed or modified.
RAM
 8051 holds a 128 bytes RAM. Basically, RAM is used to store data or operands for only
a small time duration. It can be altered anytime according to the need of the user. It is
also known as the data memory as it stores the data temporarily.
 Out of the 128-byte RAM, first, 32 bytes is held by the working registers. Basically, these

5|Page
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

are 4 banks which separately has 8 registers. These registers are accessed either by its
name oraddress. It is to be noted here that at a particular time only a single register bank
can be used.
 As in 8051, the data and program memory i.e., RAM and ROM hold a definite memory
space. However, for some applications there exist the need for external memory to enhance
the memory space, thus external RAM, ROM/EPROM is used by the 8051 microcontrollers.
1.2.3. Input/ Output port:
 8051 consists of 4 parallel ports of 8 bit each thereby providing 32 input-output pins. All the
4 ports function bidirectional i.e., either input or output according to the software control.
1.2.4. Timer and Control Unit:
 Timers are used to create a time gap or delay between 2 events. 8051 microcontroller consists
of 2 timers of 16 bit each by which the system can produce two delays simultaneously in
order to generate the appropriate delay.
1.2.5. 8051 Flag Bits and PSW Register
 The program status word (PSW) register is an 8-bit register, also known as flag register.
 It is of 8-bit wide but only 6-bit of it is used. The two unused bits are user-defined flags.

1.2.6. The Data Pointer (DPTR)


 8051 internal RAM memory is accessed through 8bit registers(R0-R7) or by means of
different addressing modes.

6|Page
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

 In order to access the external memory(usually 64k) data, a 16bit accessing register is
needed for 8051. Here DPTR in 8051 acts as external memory accessing register.

 Usually the address of the data in external memory is loaded or stored in DPTR which points
or directs to that data. And this data can be accessed using indirect addressing (i.e @DPTR).

Ex: MOVX A, @DPTR

1.2.7. Interrupts:
 Interrupts is a sub-routine call that given by the microcontroller when some other program
with high priority is request for acquiring the system buses the n interrupts occur in
current running program.
 Interrupts provide a method to postpone or delay the current process, performs a sub-
routine task and then restart the standard program again.

Types of interrupt in 8051 Microcontroller:

five sources of interrupts in 8051 Microcontroller:

 Timer 0 overflow interrupt - TF0


 Timer 1 overflow interrupt - TF1
 External hardware interrupt - INT0
 External hardware interrupt - INT1
 Serial communication interrupt - RI/TI

1.2.8. Bus :

 Bus is a group of wires which uses as a communication canal or acts as means of data transfer.
The different bus configuration includes 8, 16 or more cables. Therefore, a bus can bear 8 bits,
16 bits all together.

Types of buses in 8051 Microcontroller:

two types of bus used in 8051 microcontroller:

 Address Bus: 8051 microcontroller is consisting of 16 bit address bus. It is generally be used
for transferring the data from Central Processing Unit to Memory.
 Data bus: 8051 microcontroller is consisting of 8 bits data bus. It is generally be used for
transferring the data from one peripherals position to other peripherals.

1.2.9. Oscillator: As the microcontroller is digital circuit therefore it needs timer for their operation. To
perform timer operation inside microcontroller it required externally connected or on-chip oscillator.
Microcontroller is used inside an embedded system for managing the function of devices. Therefore,
8051 uses the two 16 bit counters and timers. For the operation of this timers and counters the oscillator

7|Page
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

is used inside microcontroller.

1.2.10. Pin diagram of 8051 Microcontroller


 The 8051 microcontroller is a popular 8-bit microcontroller widely used in embedded systems.
 It is a single-chip microcontroller with a Harvard architecture that includes a CPU, RAM, ROM,
and several peripherals.
 The 8051 microcontroller has a 40-pin dual in-line package (DIP) that provides various inputs and
outputs for communication with external devices.
 8051 microcontroller is a 40 pin Dual Inline Package (DIP).
 These 40 pins serve different functions like read, write, I/O operations, interrupts etc.
8051 has four I/O ports wherein each port has 8 pins which can be configured as input or output
depending upon the logic state of the pins. Therefore, 32 out of these 40 pins are dedicated to
I/O ports. The rest of the pins are dedicated to VCC, GND, XTAL1, XTAL2, RST, ALE, EA’
and PSEN’. Pin diagram of 8051

OR

1. VCC: This pin is connected to the power supply and provides a voltage of +5V to the microcontroller.
2. GND: This pin is connected to the ground and serves as the reference voltage for the microcontroller.
8|Page
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

3. XTAL1 and XTAL2: These pins are used for connecting an external crystal oscillator that provides
the clock signal for the microcontroller.
4. Reset: This pin is used for resetting the microcontroller. A high pulse on this pin resets the
microcontroller to its initial state.
5. Port 1: This is an 8-bit bidirectional input/output port that can be used for interfacing with external
devices.
6. Port 2: This is an 8-bit bidirectional input/output port that can be used for interfacing with external
devices.
7. Port 3: This is an 8-bit bidirectional input/output port that can be used for interfacing with external
devices.
8. Port 4: This is an 8-bit bidirectional input/output port that can be used for interfacing with external
devices.
9. INT0: This is an external interrupt 0 input pin.
10. INT1: This is an external interrupt 1 input pin.
11. T0: This is an external timer 0 input pin.
12. T1: This is an external timer 1 input pin.
13. WR: This is the write signal for external memory.
14. RD: This is the read signal for external memory.
15. ALE: This is the address latch enable signal that is used to latch the address for external memory.
16. PSEN: This is the program store enable signal that is used for accessing the program memory.
17. 17-24. Address bus: These pins are used for transmitting the address information to the external
memory.
18. 25-32. Data bus: These pins are used for transmitting the data between the microcontroller and
external memory.
19. RST: This is the output signal that indicates the microcontroller is being reset.
20. EA: This is the external access enable signal that is used for selecting the program memory.
21. VPP: This pin is used for programming the microcontroller.
22. 36-39. XTAL: These pins are used for connecting an external crystal oscillator.
23. P1.0 (AD0) – P1.7 (AD7): These pins are used for interfacing with external analog devices.

DESCRIPTION OF THE PINS:


 Pin 1 to Pin 8 (Port 1) – Pin 1 to Pin 8 are assigned to Port 1 for simple I/O operations. They can be
configured as input or output pins depending on the logic control i.e. if logic zero (0) is applied to the
I/O port it will act as an output pin and if logic one (1) is applied the pin will act as an input pin.
These pins are also referred to as P1.0 to P1.7 (where P1 indicates that it is a pin in port 1 and the
number after ‘.’ tells the pin number i.e. 0 indicates first pin of the port. So, P1.0 means first pin of
port 1, P1.1 means second pin of the port 1 and so on). These pins are bidirectional pins.
 Pin 9 (RST) – Reset pin. It is an active-high, input pin. Therefore if the RST pin is high for a minimum
of 2 machine cycles, the microcontroller will reset i.e. it will close and terminate all activities. It is
often referred as “power-on-reset” pin because it is used to reset the microcontroller to it’s initial
values when power is on (high).
 Pin 10 to Pin 17 (Port 3) – Pin 10 to pin 17 are port 3 pins which are also referred to as P3.0 to P3.7.
These pins are similar to port 1 and can be used as universal input or output pins. These pins are
bidirectional pins. These pins also have some additional functions which are as follows:
 P3.0 (RXD) : 10th pin is RXD (serial data receive pin) which is for serial input. Through this
input signal microcontroller receives data for serial communication.

9|Page
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

 P3.1 (TXD) : 11th pin is TXD (serial data transmit pin) which is serial output pin. Through
this output signal microcontroller transmits data for serial communication.
 P3.2 and P3.3 (INT0′, INT1′ ) : 12th and 13th pins are for External Hardware Interrupt 0
and Interrupt 1 respectively. When this interrupt is activated(i.e. when it is low), 8051 gets
interrupted in whatever it is doing and jumps to the vector value of the interrupt (0003H for
INT0 and 0013H for INT1) and starts performing Interrupt Service Routine (ISR) from that
vector location.
 P3.4 and P3.5 (T0 and T1) : 14th and 15th pin are for Timer 0 and Timer 1 external input.
They can be connected with 16 bit timer/counter.
 P3.6 (WR’) : 16th pin is for external memory write i.e. writing data to the external memory.
 P3.7 (RD’) : 17th pin is for external memory read i.e. reading data from external memory.
 Pin 18 and Pin 19 (XTAL2 And XTAL1) – These pins are connected to an external oscillator which
is generally a quartz crystal oscillator. They are used to provide an external clock frequency of 4MHz
to 30MHz.
 Pin 20 (GND) – This pin is connected to the ground. It has to be provided with 0V power supply.
Hence it is connected to the negative terminal of the power supply.
 Pin 21 to Pin 28 (Port 2) – Pin 21 to pin 28 are port 2 pins also referred to as P2.0 to P2.7. When
additional external memory is interfaced with the 8051 microcontroller, pins of port 2 act as higher-
order address bytes. These pins are bidirectional.
 Pin 29 (PSEN) – PSEN stands for Program Store Enable. It is output, active-low pin. This is used to
read external memory. In 8031 based system where external ROM holds the program code, this pin is
connected to the OE pin of the ROM.
 Pin 30 (ALE/ PROG) – ALE stands for Address Latch Enable. It is input, active-high pin. This pin
is used to distinguish between memory chips when multiple memory chips are used. It is also used to
de-multiplex the multiplexed address and data signals available at port 0. During flash programming
i.e. Programming of EPROM, this pin acts as program pulse input (PROG).
 Pin 31 (EA/ VPP) – EA stands for External Access input. It is used to enable/disable external memory
interfacing. In 8051, EA is connected to Vcc as it comes with on-chip ROM to store programs. For
other family members such as 8031 and 8032 in which there is no on-chip ROM, the EA pin is
connected to the GND.
 Pin 32 to Pin 39 (Port 0) – Pin 32 to pin 39 are port 0 pins also referred to as P0.0 to P0.7. They are
bidirectional input/output pins. They don’t have any internal pull-ups. Hence, 10 K? pull-up registers
are used as external pull-ups. Port 0 is also designated as AD0-AD7 because 8051 multiplexes address
and data through port 0 to save pins.
 Pin 40 (VCC) – This pin provides power supply voltage i.e. +5 Volts to the circuit.
10 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

11 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

1.2.11. Uses of pin diagram of the 8051 microcontroller:

The pin diagram of the 8051 microcontroller is used for various purposes in embedded systems.
Some of the main uses of the pin diagram are:
1. Interfacing with external devices: The 8051 microcontroller has several input/output pins that
can be used for interfacing with external devices such as sensors, actuators, displays, and
communication modules. The pin diagram provides the information about the location of these
pins, their functionalities, and their electrical characteristics.
2. Programming the microcontroller: The 8051 microcontroller can be programmed using various
programming languages such as Assembly, C, and BASIC. The pin diagram provides the
information about the pins that are used for programming the microcontroller, such as thePSEN
pin and the ALE pin.
3. Debugging and testing: The pin diagram provides access to the internal signals of the
microcontroller, such as the address and data buses, which can be used for debugging and testing
the microcontroller. Special hardware tools such as logic analyzers and oscilloscopes can be
connected to the pins to monitor the signals and diagnose any issues in the system.
4. Expansion and customization: The pin diagram provides the flexibility to expand andcustomize
the functionality of the microcontroller by connecting external devices and peripherals. For
example, additional memory can be added by connecting external RAM or ROM chips to the
address and data buses.

1.2.12. Characteristics of 8051 microcontroller:


 An 8-bit processor
 Data memory or RAM of 128 bytes.
 Program memory or ROM of 4 KB.
 2 timers of 16 bit each.
 8-bit data bus.
 16-bit address bus.
 Offers bit addressable format.
 Special function registers and serial port.
 32 input/output lines.

1.3. 8051 INSTRUCTION SET AND PROGRAMMING


 Mnemonics: it is a form of the instruction.
Example: MOV A,B (move to the data in B reg into A reg)
 Instruction-> Add the data in B reg and A reg

12 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

Op-code: The op-code is a single instruction that can be executed by the CPU. Here the op-code is a
MOV instruction.
Operands: The operands are a single piece of data that can be operated by the op-code.
Example, multiplication operation is performed by the operands that are multiplied by the
operand.

8051 has about 111 instructions. These can be grouped into the following categories
 Data Transfer Instructions
 Arithmetic Instructions
 Branch Instructions
 Byte level Logical Instructions
 Bit-level logical Instructions
1.3.1. DATA TRANSFER INSTRUCTIONS:
 Operation: MOV
Syntax: MOV destination, source

Description: MOV copies the value of source into destination. The value of source
is not affected. Both destination and source must be in Internal RAM.
 Operation: MOVC
Function: Move Code Byte to Accumulator
Syntax: MOVC A, @A+register
Description: MOVC moves a byte from Code Memory into the Accumulator.
 Operation: MOVX
Function: Move Data To/From External Memory (XRAM)
Syntax: MOVX operand1, operand2

Description: MOVX moves a byte to or from External Memory into or from the Accumulator.
 Operation: SWAP
Function: Swap Accumulator Nibbles
Syntax: SWAP A
Description: SWAP swaps bits 0-3 of the Accumulator with bits 4-7 of the
Accumulator. This instruction is identical to executing "RR A" or "RL A" four
times.
 Operation: XCH
Function: Exchange Bytes
Syntax: XCH A,register
Description: Exchanges the value of the Accumulator with the value contained in
register.
Example: XCH A, R1
 Operation: PUSH
Function: Push Value onto Stack
Syntax: PUSH
Description: PUSH "pushes" the value of the specified iram addr onto the stack.
PUSH first increments the value of the Stack Pointer by 1, then takes the
value stored in iram addr and stores it in Internal RAM at the location
pointed to by the incremented Stack Pointer.
 Operation: POP
Function: Pop Value from Stack
13 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

Syntax: POP
Description: POP "pops" the last value placed on the stack into the iram addr specified.
In other words, POP will load iram addr with the value of the Internal RAM
address pointed to by the current Stack Pointer. The stack pointer is then
decremented by 1.

1.3.2. ARITHMETIC INSTRUCTIONS


 Operation: ADD, ADDC
Function: Add Accumulator, Add Accumulator with Carry
Description: Description: ADD and ADDC both add the value operand to the value
of the Accumulator, leaving the resulting value in the Accumulator. The
value operand is not affected. ADD and ADDC function identically except
that ADDC adds the value of operand as well as the value of the Carry flag
whereas ADD does not add the Carry flag to the result.
 Operation: SUBB
Function: Subtract from Accumulator with Borrow
Description: SUBB subtract the value of operand from the value of the Accumulator,
leaving the resulting value in the Accumulator. The value operand is
not affected. The Carry Bit (C) is set if a borrow was required for bit
7, otherwise it is cleared. In other words, if the unsigned value being
subtracted is greater than the Accumulator the Carry Flag is set.
 Operation: MUL
Function: Multiply Accumulator by B
Syntax: MUL AB
Description: Multiples the unsigned value of the Accumulator by the unsigned value
of the "B" register. The least significant byte of the result is placed in the
Accumulator and the most-significant-byte is placed in the "B" register. The
Carry Flag (C) is always cleared.
 Operation: DIV
Function: Divide Accumulator by B
Syntax: DIV AB
Description: Divides the unsigned value of the Accumulator by the unsigned value
of the "B" register. The resulting quotient is placed in the Accumulator
and the remainder is placed in the "B" register.
 Operation: INC
Function: Increment Register
Syntax: INC register
Description: INC increments the value of register by 1. If the initial value of register
is 255 (0xFF Hex), incrementing the value will cause it to reset to 0. Note:
The Carry Flag is NOT set when the value "rolls over" from 255 to 0. In the
case of "INC DPTR", the value two-byte unsigned integer value of DPTR
is incremented. If the initial value of DPTR is 65535 (0xFFFF Hex),
incrementing the value will cause it to reset to 0. Again, the Carry Flag is
NOT set when the value of DPTR "rolls over" from 65535 to 0
 Operation: DEC
Function: Decrement Register
Syntax: DEC register
Description: DEC decrements the value of register by 1. If the initial value of register is 0,
decrementing the value will cause it to reset to 255 (0xFF Hex). Note: The Carry
Flag is NOT set when the value "rolls over" from 0 to 255.

14 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

1.3.3. LOGICAL INSTRUCTIONS


 Operation: ORL
Function: Bitwise OR
Syntax: ORL operand1,operand2
Description: ORL does a bitwise "OR" operation between operand1 and operand2, leaving the
resulting value in operand1. The value of operand2 is not affected.
 Operation: ANL
Function: Bitwise AND
Syntax: ANL operand1, operand2
 Operation: XRL
Function: Bitwise Exclusive OR
Syntax: XRL operand1,operand2
 Operation: CPL
Function: Complement Register
Syntax: CPL operand
 Operation: CLR
Function: Clear Register
Syntax: CLR register
Description: CLR clears (sets to 0) all the bit(s) of the indicated register. If the register
is a bit (including the carry bit), only the specified bit is affected. Clearing the
Accumulator sets the Accumulator's value to 0.
 Operation: RL
Function: Rotate Accumulator Left
Syntax: RL A
Description: Shifts the bits of the Accumulator to the left. The left-most bit (bit 7) of
the Accumulator is loaded into bit 0.
 Operation: RR
Function: Rotate Accumulator Right
Syntax: RR A
Description: Shifts the bits of the Accumulator to the right. The right-most bit (bit 0) of
the Accumulator is loaded into bit 7.
 Operation: RLC
Function: Rotate Accumulator Left Through Carry
Syntax: RLC A
Description: Shifts the bits of the Accumulator to the left.
 Operation: RRC
Function: Rotate Accumulator Right Through Carry
Syntax: RRC A
Description: Shifts the bits of the Accumulator to the right

1.3.4. BRANCHING INSTRUCTIONS


 Operation: JMP
Function: Jump to Data Pointer + Accumulator
Syntax: JMP @A+DPTR
Description: JMP jumps unconditionally to the address represented by the sum of the
value of DPTR and the value of the Accumulator.

 Operation: JC
Function: Jump if Carry Set
Syntax: JC reladdr
Description: JC will branch to the address indicated by reladdr if the Carry Bit is set.
15 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

If the Carry Bit is not set program execution continues with the
instruction following the JC instruction.
 Operation: JNC
Function: Jump if Carry Not Set
Syntax: JNC reladdr
Description: JNC branches to the address indicated by reladdr if the carry bit is not
set. If the carry bit is set program execution continues with the instruction following
the JNB instruction.
 Operation: DJNZ
Function: Decrement and Jump if Not Zero
Syntax: DJNZ register,reladdr
Description: DJNZ decrements the value of register by 1. If the initial value of register
is 0, decrementing the value will cause it to reset to 255 (0xFF Hex). If the new
value of register is not 0 the program will branch to the address indicated by relative
addr. If the new value of register is 0 program flow continues with the instruction
following the DJNZ instruction.
 Operation: CJNE
Function: Compare and Jump If Not Equal
Syntax: CJNE operand1,operand2,reladdr
Description: CJNE compares the value of operand1 and operand2 and branches to the
indicated relative address if operand1 and operand2 are not equal. If the two
operands are equal program flow continues with the instruction following the
CJNE instruction.
 Operation: JZ
Function: Jump if Accumulator Zero
Syntax: JNZ reladdr
Description: JZ branches to the address indicated by reladdr if the Accumulator
contains the value 0. If the value of the Accumulator is non-zero program execution
continues with the instruction following the JNZ instruction.
 Operation: JNZ
Function: Jump if Accumulator Not Zero
Syntax: JNZ reladdr
Description: JNZ will branch to the address indicated by reladdr if the Accumulator
contains any value except 0. If the value of the Accumulator is zero program
execution continues with the instruction following the JNZ instruction.
 Operation: SJMP
Function: Short Jump
Syntax: SJMP reladdr
Description: SJMP jumps unconditionally to the address specified reladdr. Reladdr
must be within -128 or +127 bytes of the instruction that follows the SJMP
instruction.
 Operation: LJMP
Function: Long Jump
Syntax: LJMP code addr
Description: LJMP jumps unconditionally to the specified code addr.
 Operation: AJMP
Function: Absolute Jump Within 2K Block
Syntax: AJMP code address

Description: AJMP unconditionally jumps to the indicated code address.


 Operation: LCALL
16 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

Function: Long Call


Syntax: LCALL code addr
Description: LCALL calls a program subroutine. LCALL increments the program
counter by 3 (to point to the instruction following LCALL) and pushes that value onto
the stack (low byte first, high byte second). The Program Counter is then set to the 16-
bit value which follows the LCALL opcode, causing program execution to continue at
that address.
 Operation: ACALL
Function: Absolute Call Within 2K Block
Syntax: ACALL code address
Description: ACALL unconditionally calls a subroutine at the indicated code address.
ACALL pushes the address of the instruction that follows ACALL onto the stack, least-
significant-byte first, most-significant-byte second.
 Operation: RET
Function: Return From Subroutine
Syntax: RET
Description: RET is used to return from a subroutine previously called by LCALL or
ACALL. Program execution continues at the address that is calculated by popping the
topmost 2 bytes off the stack. The most-significant-byte is popped off the stack first,
followed by the least-significant-byte.
 Operation: RETI
Function: Return From Interrupt
Syntax: RETI
Description: RETI is used to return from an interrupt service routine. RETI first enables
interrupts of equal and lower priorities to the interrupt that is terminating. Program
execution continues at the address that is calculated by popping the topmost 2 bytes off
the stack. The most-significant-byte is popped off the stack first, followed by the least-
significant-byte.RETI functions identically to RET if it is executed outside of an interrupt
service routine.

LOOPING IN THE 8051


* Repeating a sequence of instructions a certain number of times is called a loop.
* The loop is one of most widely used actions that any microprocessor performs.
* In the 8051, the loop action is performed by the instruction “DJNZ reg,label , in this
instruction the register is decremented; if it is not zero, it jumps to the target address referred
to by the label.
* Prior to the start of the loop the register is loaded with the counter for the number of
repetitions. Notice that in this instruction both the register decrement and the decision to
jump are combined into a single instruction

17 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

LOOP INSIDE A LOOP


As shown in Example the maximum count is 256. What happens if we want to repeat an action more
times than 256? To do that, we use a loop inside a loop, which is called a nested loop. In a nested
loop, we use two registers to hold the count
Example
Write a program to (a) load the accumulator with the value 55H, and (b) complement
the ACC700 times.
Solution:
Since 700 is larger than 255 (the maximum capacity of any register), we use two registers to
holdthe count. The following code shows how to use R2 and R3 for the count.

In this program, R2 is used to keep the inner loop count. In the instruction “DJNZ R2 ,
AGAIN”, whenever R2 becomes 0 it falls through and “DJNZ R3 , NEXT” is executed. This
instruction forces the CPU to load R2 with the count 70 and the inner loop starts again. This process
will continue until R3 becomes zero and the outer loop is finished.
In this instruction the content of register A is checked. If it is zero, it jumps to the
targetaddress. For example, look at the following code.

In this program,. if either RO or Rl is zero, it jumps to the label OVER. Notice that the JZ
instruction can be used only for register A. It can only check to see whether the accumulator is
zero, and it does not apply to any other register. More importantly, you don’t have to perform
an arithmetic instruction such as decrement to use the JNZ instruction.

18 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

Example

Example Program for LED blinking using with 8051 microcontroller:


 Number Displaying on 7-segment display using 8051 microcontroller
 Timer/Counter calculations and program using 8051 microcontroller
 Serial Communication calculations and program using 8051 microcontroller

LED PROGRAMS WITH 8051 MICROCONTRLLER

1. WAP to toggle the PORT1 LEDs


ORG 0000H
TOGLE: MOV P1, #01 //move 00000001 to the p1 register
CALL DELAY //execute the delay//
MOV A, P1 //move p1 value to the accumulator//
CPL A //complement A value //
MOV P1, A //move 11111110 to the port1 register//
CALL DELAY //execute the delay//
SJMP TOGLE
DELAY: MOV R5, #10H //load register R5 with 10//

TWO: MOV R6, #200 //load register R6 with 200//


ONE: MOV R7, #200 //load register R7 with 200//
DJNZ R7, $ //decrement R7 till it is zero//
DJNZ R6, ONE //decrement R7 till it is zero//
DJNZ R5, TWO //decrement R7 till it is zero//
RET //go back to the main program //
END

1.4. PROGRAMMING PARALLEL PORT

1.4.1. 8051 MICROCONTROLLER PORT PROGRAMMING

There are four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports. All the ports

upon RESET are configured as output, ready to be used as output ports. To use any of these ports

as an input port, it must be programmed.

1.4.2. PIN CONFIGURATION OF 8051/8031 MICROCONTROLLER.

19 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

8051 family members come in different IC packages, such as DIP (dual in-line package), QFP
(quad flat package), and LLC (leadless chip carrier), they all have 40 pins that are dedicated to
various functions such as I/O, RD, WR, address, data, and interrupts. some companies provide
20-pin versions of the 8051 with a reduced number of I/O ports for less demanding applications.
Majority of developers uses the 40-pin chip,

 A set of 32 pins are set aside for the four ports P0,P1,P2 and P3 where each port takes 8 pins.
 Pin 40 provides supply voltage to the chip.
 The voltage source is +5V. Pin 20 is the ground.
 The rest of the pins are designated as XTAL1,XTAL2,RST,EA,PSEN and ALE. XTAL2/XTALI
are for oscillator input which provides the clock pulse to microcontroller.
 The pins from 32 to 39 form the port0( AD0/AD7). P0.0 to P0.7 are multiplexed pins used for
address and data

 The pins from 1 to 8 are for port 1 (P1.0 to P1.7); and the pins from 21 to 28 are for port 2. (P2.0
to P2.7) is used for sending address to memory.
20 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

 The 9th pin RST is used for Restarting the 8051 microcontroller.
 The pins from 10 to 17 are for port3 which is a special port, and it is multi-functional.
 The 30th pin is ALE(Address latch enable).
 When the pin is set to 1, then address is transferred through the pins AD0 to AD7.
 When the pin is set to 0 then data is transferred through the pins AD0 to AD7.
 The 29th pin is PSEN which is the Program Strobe Enable used for reading the program from
external memory.
Port 0: Port 0 occupies a total of 8 pins (pins 32-39) .It can be used for input or output. To use the
pins of port 0 as both input and output ports, each pin must be connected externally to a 10K ohm
pull-up resistor. This is due to the fact that P0 is an open drain, unlike P1, P2, and P3.Open drain
is a term used for MOS chips in the same way that open collector is used for TTL chips. With
external pull-up resistors connected upon reset, port 0 is configured as an output port. For example,
the following code will continuously send out to port 0 the alternating values 55H and AAH

MOV A, #55H
BACK: MOV P0,A A
CALL DELAY
CPL A
SJMP BACK
Port 0 as Input : With resistors connected to port 0, in order to make it an input, the port must be programmed
by writing 1 to all the bits. In the following code, port 0 is configured first as an input portby writing
1’s to it, and then data is received from the port and sent to P1.

8051 I/O Ports


MOV A,#0FFH ; A = FF hex
MOV P0,A ; make P0 an input port
BACK: MOV A,P0 ;get data from P0
MOV P1,A ;send it to port 1
SJMP BACK
Dual role of port 0: Port 0 is also designated as AD0-AD7, allowing it to be used for both address and data. When
connecting an 8051/31 to an external memory, port 0 provides both address and data. The 8051 multiplexes address
and data through port 0 to save pins. ALE indicates if P0 has address or data. When ALE = 0, it provides data D0-D7,
but when ALE =1 it has address and data with the help of a 74LS373 latch.

Port 1: Port 1 occupies a total of 8 pins (pins 1 through 8). It can be used as input or output. In contrast to port
0, this port does not need any pull-up resistors since it already has pull-up resistors internally. Upon reset, Port
1 is configured as an output port. For example, the following code will continuously send outto port1 the
alternating values 55h & AAh
21 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

MOV A,#55H ; A = 55 hex


BACK: MOV P1,A ;send it to Port 1 A
CALL DELAY ;call delay routine
CPL A ;make A=0
SJMP BACK

Port 1 as input: To make port1 an input port, it must be programmed as such by writing 1 to all its bits. In the
following code port1 is configured first as an input port by writing 1’s to it, then data is received fromthe port
and saved in R7 ,R6 & R5.
MOV A,#0FFH ;A=FF HEX
MOV P1,A ;make P1 an input port by writing all 1’s to it
MOV A,P1 ;get data from P1
MOV R7,A ;save it in register R7A
CALL DELAY ;wait
MOV A,P1 ;get another data from P1
MOV R6,A ;save it in register R6 A
CALL DELAY ;wait
MOV A,P1 ;get another data from P1
MOV R5,A ;save it in register R5
Port 2 : Port 2 occupies a total of 8 pins (pins 21- 28). It can be used as input or output. Just like P1, P2 does
not need any pull-up resistors since it already has pull-up resistors internally. Upon reset,Port 2 is configured as
an output port. For example, the following code will send out continuously to port 2 the alternating values 55h
and AAH. That is all the bits of port 2 toggle continuously.

MOV A,#55H ; A = 55 hex


BACK: MOV P2,A ;send it to Port 2 A
CALL DELAY ;call delay routine
CPL A ;make A=0
Port 2 as input : To make port 2 an input, it must programme as such by writing 1 to all its bits. In the
following code, port 2 is configured first as an input port by writing 1’s to it. Then data is received from that port
and is sent to P1 continuously.
MOV A,#0FFH ;A=FF hex
MOV P2,A ;make P2 an input port by writing all 1’s to it
BACK: MOV A,P2 ;get data from P2
MOV P1,A ;send it to Port1
SJMP BACK ;keep doing that

Dual role of port 2 : In systems based on the 8751, 8951, and DS5000, P2 is used as simple I/O. However, in
8031-based systems, port 2 must be used along with P0 to provide the 16-bit address for the external memory. As
shown in pin configuration 8051, port 2 is also designed as A8-A15, indicating the dual function. Since an 8031
is capable of accessing 64K bytes of external memory, it needs a path for the 16 bits of the address. While P0
provides the lower 8 bits via A0-A7, it is the job of P2 to provide bits A8-A15 of the address. In other words,
when 8031 is connected to external memory, P2 is used for the upper 8 bits of the 16 bit address, and it cannot be
used for I/O.
Port 3 : Port 3 occupies a total of 8 pins, pins 10 through 17. It can be used as input or output. P3 doesnot
need any pull-up resistors, the same as P1 and P2 did not. Although port 3 is configured as an output port upon
reset. Port 3 has the additional function of providing some extremely important signals such as interrupts. This
information applies both 8051 and 8031 chips.
22 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

Read-modify-write feature : The ports in the 8051 can be accessed by the read-modify-write technique. This
feature saves many lines of code by combining in a single instruction all three action of (1) reading the port, (2)
modifying it, and (3) writing to the port. The following code first places 01010101 (binary) into port 1. Next, the
instruction “XLR P1,#0FFH” performs an XOR logic operation on P1 with 1111 1111 (binary), and then writes
the result back into P1.

MOV P1,#55H ;P1=01010101


AGAIN: XLR P1,#0FFH ;EX-OR P1 with 1111 1111
ACALL DELAY
SJMP AGAIN
1.4.3. Addition of two 8-bit numbers in 8051 Microcontroller Using Ports Introduction:
 To perform addition of two 8-bit numbers using ports in 8051 microcontroller, we need
to connect the two 8-bit numbers to be added to two ports of the microcontroller. We can
use anytwo ports of the microcontroller, for example, P1 and P2.

 The first step is to load the two numbers into two different ports. For example, we can
load the first number into port P1 and the second number into port P2. We can use the
MOV instruction to load the numbers into the ports.

 Once the numbers are loaded into the ports, we can use the ADD instruction to add the
two numbers. The ADD instruction adds the contents of the accumulator and the specified
operand and stores the result in the accumulator. Since the two numbers are already
loaded into the ports, we can simply use the ADD instruction with the accumulator and
the appropriate port.

 After the addition is complete, we can retrieve the result from the accumulator and store
it in another port or memory location for further processing or display. 8051
microcontroller is a microcontroller designed by Intel in 1981. It is an 8-bit
microcontroller with 40 pins DIP (dual inline package), 4kb of ROM storage and 128
bytes of RAM storage, 16-bit timers. It consists of four parallel 8-bit ports, which are
programmable as well as addressable as per the requirement.
Issues in Addition of two 8-bit numbers 8051 Microcontroller Using Ports :
There are several issues that can arise when performing addition of two 8-bit numbers in 8051
microcontroller using ports:
1. Overflow: If the result of the addition exceeds 8 bits, the carry flag (CY) in the program status word
(PSW) will be set. If this flag is not checked before storing the result, the result may be incorrect.
2. Input validation: Before performing the addition, it is important to validate the input toensure
that the numbers are within the range of 0 to 255. If the input is not validated, the result may be
incorrect.
3. Port initialization: The ports used for input and output must be properly initialized beforeuse. If
the ports are not properly initialized, the data may not be transferred correctly.
4. Endianness: The order in which the bytes of the numbers are stored in memory can affect the result
of the addition. It is important to ensure that the bytes are stored in the correct order before performing
the addition.
5. Interrupts: If interrupts are enabled during the addition operation, the result may be affected. It is
important to disable interrupts during critical operations to ensure the correct result.
6. Timing: The timing of the addition operation can affect the result. It is important to ensure that the
23 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

necessary delays are added between instructions to ensure correct operation.


7. Code optimization: The code used to perform the addition should be optimized to ensure that it uses
the least number of instructions and takes the least amount of time. This is important to avoid
potential timing issues and to ensure that the microcontroller can perform other tasks while the
addition is being performed.

Problem: To write an assembly language program to add two 8 bit numbers in 8051
microcontroller using ports.
Example:

Block diagram:

24 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

Algorithm:
 Initialize Ports P0 and P1 as input ports.
 Initialize Ports P2 and P3 as output ports.
 Initialize the R1 register.

 Move the contents from Port 0 to B register .


 Move the contents from Port 1 to A register.
 Add contents in A and B.
 If carry is present increment R1.
 Move contents in R1 to Port 2.
 Move the sum in step 6 to Port 3.
Program:
ORG 00H // Indicates starting address
MOV P0,#0FFH // Initializes P0 as input
portMOV P1,#0FFH // Initializes
P1 as input port MOV P2,#00H // Initializes
P2 as output port MOV P3,#00H // Initializes
P3 as output port
L1:MOV R1, #00H // Initializes Register
R1MOV B,P0 // Moves content of P0 to B
MOV A,P1 // Moves content of
P1 to ACLR C // Clears carry flag
ADD A,B // Add the content of A and B and store result in
AJNC L2 // If carry is not set, jump to label L2
INC R1 // Increment Register R1 if carry present
L2: MOV P2, R1 // Moves the content from Register R1 to Port2

MOV P3,A // Moves the content from A to Port3


SJMP L1 // Jumps to label
L1END

25 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

Sample Programs

1 . A switch is connected to pin P1.7. Write a program to check the status of Switch and
perform the following:

(a) If SW=0, send letter ‘N’ to P2

(b) If SW=1, send letter ‘S’ to P2

SETB P1.7 ;make P1.7 an input


AGAIN:JB P1.7,OVER ;jump if P1.7=1
MOV P2,#’N’ ;SW=0, issue ‘A’ to P2
SJMP AGAIN ;keep monitoring
OVER: MOV P2,#’S’ ;SW=1, issue ‘S’ to P2
SJMP AGAIN ;keep monitoring

Initially the pin P1.7 is set to 1 which indicates that this pin is considered as the input pin. Then the
condition of JB becomes true hence it goes to the loop OVER, the byte ‘S’ is sent to the output port P2.
Then using the SJMP command the AGAIN loop continues. If the switch is pressed it means the pin P1.7
becomes 1, then the condition fails. Hence the byte ‘N’ is sent to the port P2. Likewise the loop is executed
continuously. If the switch is pressed the byte ‘S’ is sent to the output port P2, if it is not pressed then the
byte ‘N’ is sent to the output port P2

2. Write a program to perform the following:


(a) Keep monitoring switch (at) P0.1 until it becomes high
(b) When P0.1 becomes high, Light LEDs connected at port 2
(c) Send a low-to-high (L-to-H) pulse to P1.2 to sound buzzer

26 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

SETB P0.1 ;make P0.1 as input (switch)


MOV A , #FFH ;A=11111111
AGAIN: JNB P0.1, AGAIN ; get out when P0.1=1
MOV P2, A ;Light LEDS by sending 1s to P2
CLR P1.2 ;make P1.2 low
SETB P1.2 ;make 01.2 high – L-to-H to sound buzzer
SJMP AGAIN

Initially the bit P0.1 is set as input port. Then the hexadecimal value FFH is stored in Accumulator.
The jump condition fails and the Accumulator value is sent to port P2. Then the port P1.2 is cleared and
it is set again for giving the low to high pulse to the port P1.2, then the alarm will ring. If the switch is
pressed the LED’s connected to P2 will glow and the alarm will start ringing.

1.5. 8051 Timers


1.5.1. Introduction to 8051 Timers
8051 microcontrollers have two timers and counters which work on the clock
frequency. Timer/counter can be used for time delay generation, counting external events, etc.
8051 Clock
Every Timer needs a clock to work, and 8051 provides it from an external crystal which is the main
clock source for Timer. The internal circuitry in the 8051 microcontrollers provides a clock source to the
timers which is 1/12th of the frequency of crystal attached to the microcontroller, also called Machine
cycle frequency.

8051 Timer Clock


For example, suppose we have a crystal frequency of 11.0592 MHz then the microcontroller will
provide 1/12th i.e.
Timer clock frequency= (Xtal Osc.frequency)/12 = (11.0592 MHz)/12 = 921.6 KHz
period T= 1/(921.6 kHz)=1.085 μS

1.5.2. 8051 Timer


8051 has two timers Timer0 (T0) and Timer1 (T1), both are 16-bit wide. Since 8051 has 8-bit architecture, each
of these is accessed by two separate 8-bit registers as shown in the figure below. These registers are used to
load timer count

27 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

8051 has a Timer Mode Register and Timer Control Register for selecting a mode of operation and controlling
purpose.

1.5.2.1. TMOD register


TMOD is an 8-bit register used to set timer mode of timer0 and timer1

Its lower 4 bits are used for Timer0 and the upper 4 bits are used for Timer1
Bit 7,3 – GATE:
1 = Enable Timer/Counter only when the INT0/INT1 pin is high and TR0/TR1 is set.
0 = Enable Timer/Counter when TR0/TR1 is set.
Bit 6,2 - C/ (Counter/Timer): Timer or Counter select bit
1 = Use as Counter
0 = Use as Timer
Bit 5:4 & 1:0 - M1:M0: Timer/Counter mode select bit
These are Timer/Counter mode select bit as per the below table
M1 M0 Mode Operation
0 0 0 (13-bit timer mode) 13-bit timer/counter, 8-bit of THx & 5-bit of TLx
0 1 1 (16-bit timer mode) 16-bit timer/counter, THx cascaded with TLx
8-bit timer/counter (auto-reload mode), TLx reload
1 0 2 (8-bit auto-reload mode)
with the value held by THx each time TLx overflow
Split the 16-bit timer into two 8-bit timers i.e. THx
1 1 3 (split timer mode)
and TLx like two 8-bit timer
1.5.2.2. TCON Register

TCON is an 8-bit control register and contains a timer and interrupt flags.

Bit 7 - TF1: Timer1 Overflow Flag


28 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

1 = Timer1 overflow occurred (i.e. Timer1 goes to its max and roll over back to zero).
0 = Timer1 overflow not occurred.
It is cleared through software. In the Timer1 overflow interrupt service routine, this bit will getcleared
automatically while exiting from ISR
Bit 6 - TR1: Timer1 Run Control Bit
1 = Timer1 start.
0 = Timer1 stop.
It is set and cleared by software
Bit 5 – TF0: Timer0 Overflow Flag
1 = Timer0 overflow occurred (i.e. Timer0 goes to its max and roll over back to zero).
0 = Timer0 overflow not occurred.
It is cleared through software. In the Timer0 overflow interrupt service routine, this bit will getcleared
automatically while exiting from ISR
Bit 4 – TR0: Timer0 Run Control Bit
1 = Timer0 start.
0 = Timer0 stop.
It is set and cleared by software.
Bit 3 - IE1: External Interrupt1 Edge Flag
1 = External interrupt1 occurred.
0 = External interrupt1 Processed.
It is set and cleared by hardware.
Bit 2 - IT1: External Interrupt1 Trigger Type Select
Bit 1 = Interrupt occurs on falling edge at
INT1 pin. 0 = Interrupt occur on a low level at
the INT1 pin.
Bit 1 – IE0: External Interrupt0 Edge Flag
1 = External interrupt0 occurred.
0 = External interrupt0 Processed.
It is set and cleared by hardware
Bit 0 – IT0: External Interrupt0 Trigger Type Select
Bit 1 = Interrupt occurs on falling edge at INT0
pin. 0 = Interrupt occur on a low level at INT0
pin.

Let's see the timers modes

1.5.3. 8051 TIMER MODES


Timers have their operation modes which are selected in the TMOD register using M0 & M1 bit
combinations.
MODE 0 (13-BIT TIMER MODE)
The Mode 0 operation is the 8-bit timer or counter with a 5-bit pre-scaler. So it is a 13-bit
timer/counter. It uses 5 bits of TL0 or TL1 and all of the 8-bits of TH0 or TH1.

29 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

In this example the Timer1is selected, in this case, every 32 (25)event for counter operations or 32 machine
cycles for timer operation, the TH1 register will be incremented by 1. When the TH1overflows from FFH
to 00H, then the TF1 of TCON register will be high, and it stops the timer/counter. So for an example, we
can say that if the TH1 is holding F0H, and it is in timer mode, then TF1will be high after 10H * 32 = 512
machine cycles.
MOVTMOD, #00H

MOVTH1, #0F0H

MOVIE, #88H

SETB TR1

In the above program, the Timer1 is configured as timer mode 0. In this case Gate = 0. Then the TH1 will
be loaded with F0H, then enable the Timer1 interrupt. At last set the TR1 of TCON register, and start the
timer.
MODE1 (16-BIT TIMER MODE)
The Mode 1 operation is the 16-bit timer or counter. In the following diagram, we are using Mode
1 for Timer0.

In this case every event for counter operations or machine cycles for timer operation, the TH0– TL0 register-pair
will be incremented by 1. When the register pair overflows from FFFFH to 0000H, then the TF0 of TCON register
will be high, and it stops the timer/counter. So for an example, we can say that if the TH0 – TL0 register pair is
holding FFF0H, and it is in timer mode, then TF0 will be high after 10H = 16 machine cycles. When the clock
frequency is 12MHz, then the following instructions generate an interrupt 16 µs after Timer0 starts running

MOVTMOD, #01H

MOVTL0, #0F0H

MOVTH0, #0FFH

MOVIE, #82H

SETB TR0
In the above program, the Timer0 is configured as timer mode 1. In this case Gate = 0. Then the TL0 will
be loaded with F0H and TH0 is loaded with FFH, then enable the Timer0 interrupt. At last set the TR0 of
TCON register, and start the timer.
MODE2 (8-BIT AUTO-RELOAD TIMER MODE)
The Mode 2 operation is the 8-bit auto reload timer or counter. In the following diagram, we are using
Mode 2 for Timer1.

30 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

In this case every event for counter operations or machine cycles for timer operation, the TL1register will
be incremented by 1. When the register pair overflows from FFH to 00H, then the TF1 of TCON register
will be high, also theTL1 will be reloaded with the content of TH1 and starts the operation again.

So for an example, we can say that if the TH1 and TL1 register both are holding F0H and it is in timer mode,

then TF1 will be high after 10H= 16 machine cycles. When the clock frequency is 12MHz this happens after
16 µs, then the following instructions generate an interrupt once every16 µs after Timer1 starts running

In the above program, the Timer1 is configured as timer mode 2. In this case Gate = 0. Then the TL1 and
TH1 are loaded with F0H. then enable the Timer1 interrupt. At last set the TR1 of TCON register, and start
the timer

MODE 3 OF TIMER/COUNTER
Mode 3 is different for Timer0 and Timer1. When the Timer0 is working in mode 3, the TL0 will be used
as an 8-bit timer/counter. It will be controlled by the standard Timer0 control bits, T0 and INT0 inputs.
The TH0 is used as an 8-bit timer but not the counter. This is controlled by Timer1 Control bit TR1. When
the TH0 overflows from FFH to 00H, then TF1 is set to 1. In the following diagram, we can Timer0 in
Mode 3.

31 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

When the Timer1 is working in Mode 3, it simply holds the count but does not run. When Timer0 is in mode
3, the Timer1 is configured in one of the mode 0, 1 and 2. In this case, the Timer1 cannot interrupt the
microcontroller. When the TF1 is used by TH0 timer, the Timer1 is used as Baud Rate Generator

1.6. SERIAL PORT IN 8051


There is a serial port in 8051 as mentioned in the pin diagram of 8051. 8051 has capability to perform
parallel as well as serial communication.

Parallel communication in 8051:


8051 can do 8-bit parallel communication as it has 8-bit ALU. For parallel communication, any of the
ports ( P0 / P1 / P2 / P3 ) is used as a transmission channel between transmitter and receiver.

Serial communication in 8051:


For serial communication there are two separate pins known as serial port of 8051.

TxD:
 This pin basically acts as a transmitter ( sending data ), but in some other modes it doesn’t do
the job of transmitter.
 As it is serial communication, it sends bit by bit, the processor gives 8-bit at 1 time and those
8-bits are stored in a register named SBUF.
 Processor gives 1 byte of data that is to be transmitted to SBUF and from there bit by bit is
transferred , firstly LSB and then at last MSB of the byte stored in SBUF.
 Once the total byte is transitted, an interrupt is sent to the processor by making some flag 1, so
that the processor can send more data for transmission as soon as the interrupt is received.
After every bit is transmitted, it requires delay for next bit transmission. So SBUF needs
triggering which is provided by
 Timer T1 ( here T1 only needs to trigger, T1 does not require its overflow flag , mode 3in
timers ). Here we can vary the delay, so data transmission delay can be varied(
frequency can be varied ). It has a variable baud rate.
 There is an internal clock in 8051 ( fosc / 12 = 1Mhz ) , where delay cannot be varied, this has

32 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

fixed trigger delay. So frequency cannot be varied.It has a fixed baud rate.
Whenever SBUF transferred 8bit of data , T i flag becomes 1. Whenever processors go to ISR( in other
interrupts the flag is auto cleared whenever processor goes to ISR ) , in this the Ti flag is not auto
cleared.
RxD:
 This pin is basically for data reception . It received data bit by bit ( as the transmitter sends
LSB first, it received LSB first ).
 There is also a register SBUF which stores 8 received bits. Once the 8 bits are received, instead
of sending an interrupt it firstly checks for errors ( errors caused dueto transmission).
 Once there is no error in the received information Ri flag is set and an interrupt is sent to the
processor. Processor goes to ISR ( here also Ri is not cleared automatically ).
How are SBUF in TxD and RxD different from each other?In SBUF of TxD, data is sent from
processor to SBUF
In SBUF of RxD, data is sent from SBUF to the processor. In this way both registers are differentiated
by the processor.

There is a bit named SM2 ;


If SM2 = 1, then after SBUF of RxD is filled there will be error check And if not then there willbe no
error check, directly an interrupt will be sent to the processor once SBUF in RxD is filled.

1.6.1. Modes in serial communication:


Mode 1 ( 8-bit UART communication ):
UART stands for universal asynchronous receiver-transmitter. It means receiver and transmitter are
asynchronous which mean they don’t have a common clock. Normally 8 bits are transmittedthrough the
channel, but in this mode 10 bits are transmitted

Here start and stop bits are system generated

Significance of start and stop bit:


For eg: There is a transmitter and receiver. First C8H ( 1100 1000 ) data is transmitted and then
for 10min there is no transmission and after that again 8EH ( 1000 1110 )is transmitted. If there is no
transmission, last bit transmitted would be remained in the channel

Receiver assumes blue data ( when there was no communication ) also as data
33 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

Here green is the start bit which is zero. And then the yellow colored is stop bit which is 1. Whenever
the first 0 bit comes, the receiver discards the start bit and accepts the next 8 bits and stores in SBUF.
Then the 9th bit is 1 , this bit is stored in RB8 ( will be discussed later ). Then after this whenever the
next zero bit comes ( that zero bit is discarded and accepts the next 8 bits and so on ).

Stop bit is also used for error checking. Whenever SM2=1, It checks for error, If the RB8 = 1 ( which
means stop = 1 received, so the data is received correctly ) and if RB8=0 ( transmitter generated stop as
1, but received as 0 ) so there is an error. If there is an error in received data, no interrupt is sent to the
processor.
This mode is variable baud rate, which means it is triggered by timer 1.

Mode 2 ( 9-bit UART communication ):

The 9th bit is a programmable bit and it is given through TB8. Here 9th bit is 1 and it is used for error
checking and stop bit for triggering the data high ( so start bit gets 0 and so on ).

Why the 9th bit , when the already stop bit exists?
Standard value of 9th bit is 1 and can be made 0.

34 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

Whenever SM2 = 1( receiver accepts only errorless data ) and if 9th bit is 1, then only errorless data
is accepted or else discarded. Discarding data is a purpose.
Eg: For broadcast all the receivers should receive data, in this case 9th bit = 1, so that if the receiver
has SM2 = 1 or 0, it can receive data.
Mode 3 ( 9-bit UART communication ):
This mode is completely similar to mode 2, in mode 2 for triggering timer is used Whereas in this mode
internal clock is used for triggering. It has a fixed baud rate.

Mode 0 :
Totally there were four modes in serial port of 8051, but for better understanding mode 0 is explained
after three modes. In this mode data is transferred and received only through the RxD channel. TxD is
used for clocks. This is synchronous mode of communication.

Such a system is also known as half duplex mode. It has fixed baud rate.

SCON register:

SM0 and SM1:


These are used to select the mode
SM0 SM1 Mode
0 0 0
0 1 1
1 0 2
1 1 3
SM2:
If SM2 = 1, error is checked Or else no error checking is done.
REN:
Receiver enable, If REN=1, receiver will receive the data or else not.
TB8:
This is the 9th bit to be transmitted.
RB8:
This is the 9th bit to be received.
Ti :
When 8-bits are received in SBUF , then Ri = 1, that would send an interrupt to the processor.

Ri :
When 8-bits are sent from SBUF,and SBUF is empty , then Ri = 1, that would send
an interruptto the processor. Before Ri=1, it checks for error based on SM2.
1.7. Interrupt Handling( 8-Bit Interrupts)
An interrupt is the occurrence of a condition–an event — that cause a temporary suspension of a
program while the event is serviced by another program (Interrupt Service Routine ISR or Interrupt
Handler).

35 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

interrupt

program program
program Interrupt service Routine

time t
Figure 1.7.1
Figure 1.7.1 shows ISR. In which first part of the figure shows main program is interrupted. The next
part shows main program is paused and ISR is providing service to interrupt and when it finishes
main program is restored.
1.7.1. INTERRUPT STRUCTURE OF 8051 MICRO CONTROLLER

1.7.2 Interrupt Vs Polling


 Interrupt – is an external or internal event that interrupts the microcontroller to inform it that
a device needs its service.
 Serving a device can be done in two ways-
1) Interrupt
2) Polling
Interrupt: Here, a device needs service, and the device notifies the microcontroller by sending it an
interrupt signal. After receiving an interrupt signal, the microcontroller stops whatever it is doing and
serves the device. Program associated with the interrupt is called the interrupt service routine (ISR) or
interrupt handler.

Polling: In this, the microcontroller continuously monitors the status of the given devices. When the
conditions are met, (that is, if the device needs some service) it performs the service. Next, it
moves on to monitor the next device. It continues in this fashion until everyone is serviced.

Interrupt is preferred over polling for the following reasons:


36 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

● Polling is not efficient, because it wastes much of the microcontroller’s time by checking devices
that do not need service.

● Interrupt can serve many devices; and each device can get the service of microcontroller based on
priority.

● In polling there is no priority, only on round robin basis they can get the attention of the
microcontroller.

● In interrupt, a microcontroller can also ignore a device’s request for service, this is not possible in
the polling method.

1.7.3. Interrupt Service Routine(ISR):

 Each interrupt has an interrupt service routine (ISR), or is called, the microcontroller runs
the interrupt service location in memory that holds the address of the ISR.

interrupt handler. When an interrupt routine. Every interrupt has a fixed

In the above table, 8051 interrupts are listed. When the reset interrupt is given through 9th
pin system is reset. At that time the service starts from 0000 location. The two port pins P3.2 and
P3.3 are external hardware interrupts.

1.7.3.1 Steps followed when interrupt occurs

The group of memory locations that hold the addresses of ISRs is called an interrupt vector table.

1. Microcontroller completes the instruction it is executing and saves the address of the
next instruction (PC) on the stack.

2. Saves the current status of the system internally in stack.


3. System starts executing ISR routine, where as the starting address of that ISR routine is referred
from interrupt vector table

37 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

4. The microcontroller gets the location of the ISR from the interrupt vector table and control is
transferred to that location. It starts to execute the interrupt service subroutine until it reaches the
last instruction of the subroutine which is RETI (return from interrupt).
5. After executing the RETI instruction, the microcontroller returns to the place where it was
interrupted.
6. First, it gets the program counter (PC) address from the stack by popping the top two bytes of the
stack into the PC.
7. Restores the system previous program status.
8. Then it starts to execute from that address.
1.7.3.2 Types of Interrupts in 8051 Microcontroller
The 8051 microcontroller can recognize five different events that cause the main program to
interrupt from the normal execution. These five sources of interrupts in 8051are:

 Timer 0 overflow interrupt- TF0


 Timer 1 overflow interrupt- TF1
 External hardware interrupt- INT0
 External hardware interrupt- INT1
 Serial communication interrupt- RI/TI

Interrupts are allocated as follows

 Reset – power-up reset- It is nothing but restarting the system. When the reset is pressed
the content of the system is stored and again the memory starts from 0000H.
 Two interrupts are set aside for the timers:
One for timer 0 and one for timer 1
 Two interrupts are set aside for hardware external interrupts
P3.2 and P3.3 are for the external hardware interrupts INT0 (or EX1), and INT1
(or EX2). For any application, interrupts are needed from outside so that the service can
be done based on the input given from outside.
 Serial communication has a single interrupt that belongs to both receive and transfer
 Interrupt service is ended by noticing return statement (RETI) in ISR routine.
 There are two returns in instruction set namely RET and RETI. Though it looks similar,
there are some differences in them.

1.7.3.3 Differences between RET and RETI:

• RETI performs an additional task of clearing the interrupt-in-service flag.

• RET instead of RETI as the last instruction of the interrupt service routine, it blocks any
new interrupt on that pin after the first interrupt, since the pin status would indicate that the
interrupt is still being serviced.

• RETI instruction clears TF0, TF1, TCON.1, and TCON.3

38 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

Example code segment for 8051 Interrupts

The first line of code indicates that the program starts from the origin 0000H. Then LJMP MAIN
means Long jump to main program. Next the Interrupt Service Routine starts from 30H memory
location.

1.7.4. Enabling and Disabling an Interrupt

 Upon reset, all interrupts are disabled (masked)

 None will be responded to by the microcontroller if they are activated.

 The interrupts must be enabled by software in order for the microcontroller to respond to them
 There is a register called IE (interrupt enable) that is responsible for enabling (unmasking) and
disabling (masking) the interrupts. In IE register, there are 8 bits. Based on those 8 bits, an interrupt
can be enabled/disabled

1.7.4.1 Steps in Enabling an interrupt:

 Bit D7 of the IE register (EA) must be set to high to allow the rest of register to take effect.

 The value of EA

 If EA = 1, interrupts are enabled and will be responded to if their corresponding bits in IE are high

 If EA = 0, no interrupt will be responded to, even if the associated bit in the IE register is high EA=1
enable all interrupts, EA=0 disable all interrupts

39 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

 Both the EA pin and the corresponding interrupt pin must be 1 for enabling the particular
interrupt.
Different methods for enabling interrupts is listed below

Method-1
MOV IE,#10011001 ;enable serial, ;timer 1, EX0

Method-2 to perform the same task is


SETB IE.7 ;EA=1, global enable
SETB IE.4 ;enable serial interrupt
SETB IE.3 ;enable Timer 1 interrupt
SETB IE.0 ;enable EX0

To disable the interrupts Clear command can be used as shown below

CLR IE.3 ;mask (disable) timer 1 ;interrupt only


CLR IE.7 ;disable all interrupts
1.7.4.2 Timer Interrupt

 For any application which needs timer for a specific purpose and runs for a particular
period of time, timer interrupt can be used. The timer interrupt starts and stops the
application automatically. The timer flag (TF) is raised when the timer rolls over. Interrupt
handles Timer control flag effectively. In polling, System is held up till TF is raised but
in Timer Interrupt, System is not locked.

In Timer Interrupts,

 If the timer interrupt in the IE register is enabled, whenever the timer rolls over, TF is
raised.

 The microcontroller is interrupted in whatever it is doing, and jumps to the interrupt vector
table to service the ISR.

 In this way, the microcontroller can do other work until it is notified that the timer has
rolled over.

 Initial count starts from TH and TL register. When the TH and TL register gets FF overflow
occurs, then TF0 is set to 1 and the interrupt is automatically enabled.

 if the timer interrupt is enabled, whenever TF=1, the microcontroller is interrupted in


whatever it is doing, and jumps to the interrupt vector table to service the ISR

 In this way, the microcontroller can do other things until it is notified that the timer has
rolled over.

40 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

1.7.4.2.1 Timer Interrupt Programming

 Write a program that continuously gets 8-bit data from P0 and sends it to P1 while
simultaneously creating a square wave of 200 ms period on pin P2.1. Use Timer 0 to create
the square wave. Assume that XTAL = 11.0592 MHz.

 The first line of code indicates that the program is started from 0000H. LJMP indicates that the

program has to go for long jump to reach the main loop.

 The next line indicates that the ISR Routine starts from 000BH.This ISR routine generates a

square. The main program is written at position 0030H. In order to set the timer mode, timer 0

mode 2 is set. P0 is used as the input port.

 Here the square wave generation is for 200 ms, hence 100 ms is for on state and 100 ms for off

state. For generating the delay of 100 ms, 92 is used as the count.

 when the port P0 reaches 0FFH overflow occurs, it means the delay of 92 count is over and the

timer is set again. Once the data is stored in P0, it is moved to accumulator and then again the

data is moved to port P1. Hence the data is continuously transferred from the Port P0 to P1 .

41 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

1.7.4. Interrupt Priority Register (IP)

 Using IP register it is possible to change the priority levels of an interrupts by clearing or


setting the individual bit in the Interrupt priority (IP) register as shown in figure.
 It allows the low priority interrupt can interrupt the high-priority interrupt, but it prohibits
the interruption by using another low-priority interrupt.
 If the priorities of interrupt are not programmed, then microcontroller executes the instruction
in a predefined manner and its order are INT0, TF0, INT1, TF1, and SI.

Unit-1
IMPORTANT 2 MARK QUESTIONS

1.What is microcontroller?
 A single IC which contains the microprocessor with integrated peripherals like memory,
serial ports, parallel ports, timer/counter, interrupt controller, data acquisition interfaces like
ADC, DAC is called Microcontroller.
2. What is the significance of EA pin?
EA stands for External Access. By applying LOW to this pin, makes 8051 toomit internal 4KB on-chip
ROM and use only external memory for programstorage. By applying HIGH to this pin, makes 8051 to
use internal 4KB on-chip ROM along with external memory for program storage

42 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

3. Compare Microprocessor and Microcontroller.

4. List the features of 8051

 Data size is 8-bit


 Address lines is 16-bit (∴Memory capacity = 216= 64 KB)
 Memory capacity of On-chip RAM is 128 Bytes
 Memory capacity of On-chip ROM is 4 KB

 Total program memory space is 64KB

 Total data memory space is 64KB

 On-chip Timers - 2 x 16-bit each

 4 x 8-bit I/O Ports

 One full duplex Serial port (TxD & RxD)

 Six Interrupt sources (inclusive of two H/w interrupts – INT0, INT1)

5. Draw the Pin diagram of 8051

43 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

6. List the alternate functions of Port3 in 8051

7. Draw the program memory organization in 8051

8. What is Program Status Word?

PSW is another name for Flag register. It holds various flags, which are useful for the
programmer to test the condition of the result and make decisions. The format of PSW of 8051
microcontroller is shown in fig below

The PSW consists of four math flags and two register bank select bits. The math flags are Carry,
Auxiliary Carry, and Overflow and Parity flags. The register bank select bits RS1 and RS0 are used to
select any one of the four register banks of the internal RAM. At any instant, the microcontroller can
44 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

work with (or access) only one register bank, which is selected by these bits.

9. What is the function of RS1 and RS0 bits in the flag register of Intel 8051 microcontroller?
The function of RS1 and RS0 bits in the flag register is to select the register bank.

RS1 RS0 BANK SELECTION ADDRESS


0 0 Bank 0 00h–07h
0 1 Bank 1 08h–0Fh
1 0 Bank 2 10h–17h
1 1 Bank 3 18h–1Fh

10. List out the applications of 8051 microcontroller


 Control applications: Office automation, home automation and industrial automation.
 Embedded applications: Since, it is single chip controller, 8051 microcontrollers are much
useful in all embedded applications like real time, wireless modes.

 Network applications: In the area of wireless networking, including LAN, MAN, and WAN.
 Common applications: Used in the measurement of frequency, reactance, voltage, current,
resistance, temperature, strain management, etc. It is also used in delay subroutine, LED
display, relays, and for interfacing with other electronic components.

11. What is the size of internal RAM and ROM of 8051?


The size of internal RAM and ROM of 8051 microcontroller are:
Internal ROM–4 Kbytes
Internal RAM–128 bytes
12. List out the flags available in 8051 microcontroller.
Four mathematical flags,
1. Carry (CY),
2. Auxiliary Carry (AC),
3. Overflow Flag (OF)
4. Parity flag (P) specified in PSW register.
Two general purpose flags GF0 and GF1 in the PCON register.

13. What is the significance of DPTR?

DPTR is a 16-bit register which is used as Data Pointer for external data memory. It holds the
16-bit address of the data stored in the external data memory. This can also be used as two numbers of 8-
bit data pointers namely DPH and DPL. The 8-bit data pointers are used for accessing internal RAM and
SFR. The contents of data pointer are programmable using instructions

14. What is meant by Power On Reset in 8051?

Power On Reset in 8051 will reset the microcontroller and terminate all activities. It also causes all
values in the register to be lost. The reset pin in 8051 is pin 9. It is normally low. Upon applying high
pulse to this pin, power on reset is activated.

45 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

15. Draw the structure of a pin in port 1

16. Why all pins of a port is loaded with value “FF” before using it?
All ports of 8051 are configured by default as Output port. Hence, to make it configured as Input Port,
all pins of a port are loaded with value “FF” i.e., 1111 1111

17. Draw the format of TMOD register of 8051

18. List the modes of Timer in 8051

The modes of timer in 8051 are chosen with the help of two bits,viz., M0 & M1 in TMOD register.
The different modes of timer are as follows

M1 M0 Mode Description of Timer


mode
0 0 0 13 bit timer
0 1 1 16-bit timer
1 0 2 8-bit timer with auto
reload
1 1 3 Split time

46 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE

19. What is the significance of TRx bit in TCON register of 8051?


TRx bit in the TCON register is used to Start / Stop the timer register forboth timer and counter
operation, by setting that bit with value ‘1’ or ‘0
20. List the Interrupt sources in 8051
The Six Interrupt sources in 8051 are
 RESET
 INT0, INT1
 TF0, TF1
 SPI (TI/RI)

Part B and C Questions

UNIT I 8-BIT EMBEDDED PROCESSOR

1. With neat diagram, explain the architecture of 8051 microcontroller with timer mode operation.

2. Explain in details about Instruction Set and Programming

3. Explain in details about Programming Parallel Ports

4. Explain in details about Timers and Serial Port

5. Explain the various interrupt handling methods with neat sketch.

47 | P a g e

You might also like