CS3691 Embedded Systems and IoT
CS3691 Embedded Systems and IoT
and IoT
UNIT I 8-BIT EMBEDDED PROCESSOR
8-Bit Microcontroller – Architecture – Instruction Set
and Programming – Programming Parallel
Ports – Timers and Serial Port – Interrupt Handling.
Program Counter(PC):
• A program counter is a 16-bit register .
• The basic function of program counter is to fetch the next instruction to be
executed. The PC increments automatically, holding the address of the next
instruction.
• The I/O ports of the 8051 microcontroller are used to interface with the
outside world. The 8051 microcontroller has four ports, each of which can
be configured as either input or output. The ports are named Port 0, Port 1,
Port 2, and Port 3.
• Port 0 is an 8-bit bidirectional port that can be used to interface with
external devices.
• Port 1 is also an 8-bit bidirectional port that can be used to interface with
external devices.
• Port 2 is an 8-bit port that is used to interface with external memory devices.
• Port 3 is an 8-bit port that is used to interface with external interrupt
sources.
• In addition to the four I/O ports, the 8051 microcontroller also has several
other I/O pins, including the Reset pin, the XTAL1 and XTAL2 pins, and
the ALE (Address Latch Enable) pin. These pins are used for various
purposes, such as system reset, clock input, and address bus control.
Data Memory:
• The data memory of the 8051 microcontroller is used to store data that is
used by the microcontroller during operation. The data memory can be
either internal RAM or external RAM.
• The size of the data memory varies from 128 bytes to 256 bytes for
internal RAM, and up to 64K bytes for external RAM.
• The data memory is divided into two sections: the general-purpose
registers and the SFRs (special function registers).
• The general-purpose registers are used to store data during program
execution, while the SFRs are used to control the operation of the
microcontroller and to interface with external devices.
Program Memory:
The program memory of the 8051 microcontroller is used to store the
program code that the microcontroller executes. The program memory
can be either ROM or Flash memory.
The size of the program memory varies from 2K to 64K bytes,
depending on the specific model of the microcontroller.
SCON (Serial Control) Register:
• The Serial Control or SCON SFR is used to control the 8051
Microcontroller’s Serial Port. It is located as an address of
98H. SCON, control the Operation Modes of the Serial Port.
• SCON Register also consists of bits that are automatically
SET when a byte of data is transmitted or received.
SCON (Serial Control) Register:
• The Serial Control or SCON SFR is used to control the 8051
Microcontroller’s Serial Port. It is located as an address of
98H. SCON, control the Operation Modes of the Serial Port.
• SCON Register also consists of bits that are automatically
SET when a byte of data is transmitted or received.
SCON (Serial Control) Register:
• The Serial Control or SCON SFR is used to control the 8051
Microcontroller’s Serial Port. It is located as an address of
98H. SCON, control the Operation Modes of the Serial Port.
• SCON Register also consists of bits that are automatically
SET when a byte of data is transmitted or received.
Power Control (PCON) Register:
The PCON register is used for power control and baud rate selection.It also
consists of general purpose user flags.
IDLE MODE:
In this mode the clock is cut from the processor only, other parts of the
microcontroller such as timers. In this mode 80% of power is saved. The 20%
power is used to get the microcontroller from idle mode to normal mode.
• 8-bit register used to select timer mode. There are 4 modes in which timer can be
loaded.
1. Mode 0 : 13-bit timer C/T – 0 TIMER
2. Mode 1: 16-bit timer - 1 Counter
3. Mode 2 : 8-bit auto reload
4. Mode 3 : Split timer mode
• TH0/TL0->Timer 0 :16 bit register (byte addressable only) 8 bits can be send at a
time.
• TH1/TL1-> Timer 1: 16 bit register (byte addressable only) 8 bits can be send at a
time.
IE (Interrupt Enable) Register:
• This register is responsible for enabling and disabling the
interrupt. EA register is set to one for enabling interrupts
and set to 0 for disabling the interrupts. Its bit sequence
and their meanings are shown in the following figure.
IP (Interrupt Priority) Register:
• We can change the priority levels of the interrupts by changing
the corresponding bit in the Interrupt Priority (IP) register as
shown in the following figure.
• A low priority interrupt can only be interrupted by the high
priority interrupt, but not interrupted by another low priority
interrupt.
• If two interrupts of different priority levels are received
simultaneously, the request of higher priority level is served.
• If the requests of the same priority levels are received
simultaneously, then the internal polling sequence determines
which request is to be serviced.
Timer and Control Unit:
• The main function of a timer is to make a delay otherwise
time gap among two events.
• This microcontroller includes two timers where each
timer is 16-bit where the system can generate two delays
concurrently to produce the suitable delay.
• The delay can be generated through the timer based on
the requirement of the processor & transmits the signal to
the processor whenever the particular delay gets
generated.
Types of interrupt 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
8051 microcontroller Pin Diagram :
8051 microcontroller is a 40
pin Dual Inline Package (DIP).
These 40 pins serve different
functions like read, write, I/O
operations, interrupts etc.,
• Pin 40 (VCC) – This pin provides power supply voltage i.e. +5 Volts to
the circuit.
Addressing modes of 8051
MOV A, #0AFH;
MOV R3, #45H;
MOV DPTR, #FE00H
• MOVC A, @A+PC;
Implied Addressing Mode:
• In the implied addressing mode, there will be a single operand.
These types of instruction can work on specific registers only.
These types of instructions are also known as register specific
instruction. Here are some examples of Implied Addressing
Mode.
RLA;
SWAP A;
Types of instructions:-
Depending on operation they perform, all instructions are
divided in several groups:
• Data Transfer Instructions
• Arithmetic Instructions
• Logic Instructions
• Data exchange
• Push and Pop Instructions
• Rotate and Swap Instructions
• Bit-oriented Instructions
• Branch Instructions
Data Transfer Instructions:-
• Data transfer instructions move the content of one
register to another.
• The register the content of which is moved remains
unchanged.
• Data can be transferred within the internal Memory/to
and from external RAM.
• If they have the suffix “X” (MOVX), the data is
exchanged with external memory.
Data Transfer Instructions…
Instruction to Access External Data Memory:
Arithmetic Instructions:
Mnemonics Description Bytes Instruction Cycles
SUBB A, direct A A - (direct) - C (Subtract direct byte from Acc with borrow) 2 1
SUBB A, @Ri A A - @Ri - C (Subtract indirect RAM from ACC with borrow) 1 1
SUBB A, #data A A - data - C (Subtract immediate data from Acc with borrow) 2 1
Divide A by B (Divide A by B)
DIV AB A quotient 1 4
B remainder
• After the timer is started, it starts count up until it reaches its limit of FFFFH.
When it rolls over from FFFF to 0000H, it sets high a flag bit called TFx
(timer flag).
• This timer flag can be monitored. When this timer
flag is raised, one option would be stop the timer with
the instructions “CLR TR0“ or CLR TR1 for timer 0
and timer 1 respectively. Again, it must be noted that
each timer flag TF0 for timer 0 and TF1 for timer1.
• After THx is loaded with 8 bit value, the 8051 gives a copy of
it to TLx. Then the timer must be started. It is done by the
instruction “SETB TR0” for timer 0 and “SETB TR1” for
timer1. This is like mode 1.
MODE 2…
• After timer is started, it starts to count up by incrementing the TLx
register. It counts up until it reaches its limit of FFH. When it rolls
over from FFH to 00, it sets high the TFx (timer flag).
If we are using timer 0, TF0 goes high; if using TF1 then TF1 is raised.
Given:
Square wave frequency=5 kHz
Clock frequency=11.0592 MHz
Step 1: Calculate the Time delay
T=1/f=1/5 kHz =0.2 ms
T=0.2 ms which is the period of square wave
T/2 =0.2/2=0.1 ms delay for high and low
Step 2: Divide the desired time delay by 1.085 us
Count=0.1ms/1.085 us = 92
Step 3: Perform 65536 – n
TH0-TL0= 65536-92=65444= FFA4 H
MOV TMOD,#10 ;Timer 1, mode 1, 16-bitmode
AGAIN: MOV TL1,#A4H ;TL1=A4, low byte of timer
MOV TH1,#0FFH ;TH1=FF, the high byte
9600 -3 FD
4800 -6 FA
2400 -12 F4
1200 -24 E8
Write a program for the 8051 to transfer letter ‘A’
serially a 4800 baud rate continuously.