Esiot Unit1 Notes
Esiot Unit1 Notes
SUNDHARI AP/CSE
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.
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.
– 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.
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.
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.
3|Page
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE
1.2. 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.
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).
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.
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.
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
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.
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
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.
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.
14 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE
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
17 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE
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
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
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.
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
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.
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.
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
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.
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:
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
26 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE
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.
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.
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.
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.
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
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.
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.
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:
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
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.
● 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.
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.
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.
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.
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:
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.
• 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.
38 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE
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.
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
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
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.
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
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
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
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
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
43 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE
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.
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.
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
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
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
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
46 | P a g e
CS3691-EMBEDDED SYSTEMS AND IOT GRTIET-ESIOT NOTES | M. SUNDHARI AP/CSE
1. With neat diagram, explain the architecture of 8051 microcontroller with timer mode operation.
47 | P a g e