0% found this document useful (0 votes)
13 views59 pages

Micro Controller Notes

Uploaded by

avukuharshitha4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views59 pages

Micro Controller Notes

Uploaded by

avukuharshitha4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

MODULE 1

INTRODUCTION TO MICROCONTROLLERS
1. Major components of computer system:
(such as timers, counters, serial communication interfaces), and often
other specialized hardware modules like analog-to-digital converters
(ADCs).

 Purpose: Microcontrollers are designed for specific tasks and embedded


systems where real-time computing, low power consumption, and
integration of peripherals are crucial. They are commonly found in
devices such as microwave ovens, washing machines, automotive
systems, and IoT devices, where they control and monitor hardware
components and execute specific sets of instructions repeatedly.

Key Differences:

 Complexity: Microprocessors are more complex and capable of executing


a wide range of tasks with high processing power, whereas
microcontrollers are simpler and more specialized for dedicated
applications.
 Integration: Microprocessors need extra components (such memory and
peripherals) in order to work as a complete system; microcontrollers, on the
other hand, integrate all necessary components for a single application,
decreasing the need for external hardware.
 Power Consumption: Because of their low power consumption,
microcontrollers are a good fit for battery-operated gadgets and energy-
efficient applications.

In summary, while both microprocessors and microcontrollers are essential for


computing and control systems, their design and purpose cater to
different needs in terms of complexity, integration, and power efficiency.

1.4 Concept of embedded system:

Embedded systems are specialized computer systems designed to perform


dedicated functions within larger mechanical or electrical systems. Here
are some key concepts related to embedded systems:

1. Hardware Integration: Hardware elements like microcontrollers or


microprocessors, memory (RAM and ROM), input/output interfaces (sensors,
actuators), and frequently communication interfaces (UART, SPI, Ethernet) are
all closely integrated into embedded systems.
2. Real-time Operation: Since many embedded systems function in real-time,
they are subject to stringent timing requirements when responding to inputs or
events. Applications such as medical devices, industrial automation, and
automobile control systems require this.
3. Single-Purpose Design: Embedded systems, as contrast to general-purpose
computers, are made for particular uses or tasks. They frequently run without
the need for user intervention and are geared for dependability and efficiency.
4. Low Power Consumption: Due to their often-mobile or remote
deployment (e.g., in battery-operated devices or IoT sensors), embedded
systems are designed to minimize power consumption while maintaining
functionality.
5. Embedded Software: The software running on embedded systems is
typically developed to manage the hardware resources efficiently,
perform specific tasks, and interact with external devices. This software
is often lightweight and tailored for the specific hardware platform.
6. Applications: Embedded systems are ubiquitous in everyday life, found
in consumer electronics (e.g., smartphones, smart home devices),
automotive (e.g., engine control units), industrial automation (e.g., PLCs),
healthcare (e.g., medical devices), aerospace, and more.
7. Development Challenges: Designing embedded systems involves
dealing with constraints such as limited processing power, memory, and
storage, as well as ensuring reliability, security, and compatibility with
other systems.
8. Embedded System Design Lifecycle: The design process includes
hardware design (choosing components, PCB layout), firmware
development (coding for embedded systems), testing (verification and
validation), and often maintenance or updates over the product lifecycle.
9. Internet of Things (IoT) Integration: Many modern embedded systems
are part of IoT networks, connecting them to the internet for remote
monitoring, control, and data collection. This integration adds new
dimensions of functionality and complexity.
10. Security Considerations: With the proliferation of connected embedded
devices, security becomes critical to protect against vulnerabilities and
ensure data integrity and privacy.

Understanding these concepts is essential for engineers and developers


working with embedded systems to create efficient, reliable, and secure
solutions for various applications.

1.5 Criteria for choosing a microcontroller:

Choosing the right microcontroller for a project depends on several key criteria
that align with the specific requirements and constraints of the
application. Here are some important factors to consider:

1. Processing Power and Speed:


o Evaluate the processing power (CPU clock speed, instruction set
architecture) required to handle the computational tasks of your
application.
o Consider the performance requirements for real-time processing or
complex algorithms.
2. Memory Requirements:
o Assess the need for both volatile memory (RAM) and non-volatile
memory (ROM or flash) based on program size, data storage
requirements, and program execution speed.
o Check if the microcontroller has sufficient memory for storing variables,
constants, and program code.
3. Peripherals and Interfaces:

o Determine whatever peripherals are required, including DACs (Digital-to- Analog


Converters), ADCs (Analog-to-Digital Converters), timers, counters, SPI (Serial
Peripheral Interface), I2C (Inter-Integrated Circuit), USB, Ethernet, and UARTs
(Universal Asynchronous Receiver/Transmitter).
o Verify that the necessary communication interfaces are compatible, available,
and supported by external devices.

4. Power Requirements:
o Consider power consumption constraints, especially for battery-operated
devices or applications requiring low-power operation.
o Evaluate the microcontroller's power-saving features like sleep modes,
power-down modes, and efficiency of operation.
5. Development Tools and Ecosystem:

o The accessibility and caliber of development tools, including integrated


development environments (IDEs), debuggers, and compilers.
o Assist ance with middleware, software development libraries, and
community forums for support and debugging.

6. Cost and Availability:


o Evaluate the cost of the microcontroller itself as well as associated
development tools and peripherals.
o Consider the long-term availability of the microcontroller to ensure
continuity of supply and support.
7. Size and Packaging:
o Physical size and package type (e.g., surface-mount, through-hole)
should match the design constraints and assembly requirements of your
project.
8. Reliability and Quality:
o Consider the reputation and reliability of the microcontroller
manufacturer, including factors like product quality, warranty, and
documentation availability.
9. Environmental and Operational Conditions:
o Assess the operating temperature range and environmental conditions
(humidity, vibration, etc.) where the microcontroller will operate.
o Ensure the microcontroller meets required industry standards or
certifications if applicable (e.g., automotive, industrial).
10. Scalability and Future Expansion:
o Anticipate future needs for scalability and expansion in terms of
processing power, memory, and additional peripherals.
o Evaluate if the microcontroller can support future enhancements or
upgrades without significant redesign.

By carefully considering these criteria, engineers and developers can select a


microcontroller that best fits the technical requirements, performance
expectations, and constraints of their embedded system project.
MODULE 2
ACHITECTURE OF 8051
2.1 Introduction :

The 8051 microcontroller family, introduced by Intel in 1980, has evolved over
the years with several variants and improvements from different
manufacturers. Here’s a comparison of some notable members:

1. Intel 8051:
o The original microcontroller introduced by Intel.
o Generally operates at a clock speed of up to 12 MHz.
o Limited on-chip peripherals and memory (128 bytes of RAM, 4 KB of
ROM).
2. Intel 8031/8052:
o Variants of the original 8051 with additional features.
o Intel 8031 has 128 bytes of RAM and 1 KB of ROM.
o Intel 8052 has 256 bytes of RAM and 8 KB of ROM.
3. Atmel AT89 Series:
o Atmel (now Microchip Technology) produced a wide range of 8051-
compatible microcontrollers under the AT89 series.
o AT89C51, AT89C52, AT89S52 are popular variants.
o They offer expanded memory options (up to 64 KB of Flash) and
additional features like UART, timers/counters, and ADC.
4. Silicon Labs C8051F Series:
o Silicon Labs (formerly Cygnal Integrated Products) enhanced the 8051
architecture with the C8051F series.
o These microcontrollers offer higher clock speeds (up to 25 MHz), more
on-chip peripherals (UARTs, ADCs, DACs), and larger memory options (up
to 64 KB of Flash).
5. STMicroelectronics STC89 Series:
o STMicroelectronics produces several variants of 8051-compatible
microcontrollers under the STC89 series.
o They offer features similar to other variants, with options for different
memory sizes and peripherals.
6. NXP (formerly Philips) P89V51RD2:
o NXP’s variant of the 8051 includes features like dual data pointers,
extended RAM (1 KB), and large Flash memory (64 KB).
o It also supports in-system programmability and a wide range of
communication interfaces.

Comparison Summary:
 Clock Speed: Ranges from 12 MHz in older models to up to 25 MHz in
newer variants like the Silicon Labs C8051F.
 Memory: Ranges from as low as 128 bytes of RAM and 1 KB of ROM in
older models to 1 KB of RAM and up to 64 KB of Flash in newer models.
 Peripherals: Basic UART, timers, and GPIOs in older models; newer
models include advanced peripherals like ADCs, DACs, and multiple
UARTs.
 Manufacturer: Intel, Atmel (Microchip), Silicon Labs, STMicroelectronics,
NXP (Philips), and others produce different variants with varying features
and specifications

The 8051 microcontroller and its various family members, including the 8052
and 8031, offer a range of features suited for different applications.
Here's a breakdown of their key characteristics and uses:

Uses of Comparison

1. Selecting the Appropriate Microcontroller: Engineers can choose


based on the specific needs of their application. For example, if more
RAM or ROM is required, the 8052 might be preferred. If no on-chip ROM
is needed, the 8031 could be suitable.
2. Code Migration: Understanding the similarities in instruction set and
pinout allows engineers to migrate code between different members of
the 8051 family. This facilitates reusability and compatibility across
projects.
3. Upgrading Existing Systems: Engineers can assess whether upgrading
from an 8051-based system to a newer family member like the 8052 or
8031 would benefit their application. This includes evaluating additional
features such as more timers or interrupt sources.
4. Learning and Development: Students and hobbyists can explore
different members to understand microcontroller architecture and
determine which features are most relevant for their projects. This
knowledge aids in developing new applications.
5. Developing New Applications: By leveraging the additional features of
newer family members (e.g., on-chip flash memory, expanded interrupt
structure), engineers can create more sophisticated embedded systems
that meet specific requirements.

Issues to Consider

1. Compatibility Challenges: While most family members are largely


compatible, slight variations in features or pinout could impact code
migration. Careful evaluation and testing are necessary.
2. Development Tools: Different development tools could be needed for
different microcontrollers. For effective development, interoperability
with programmers, debuggers, and compilers is essential.
3. Availability and Cost: Availability and pricing can vary between different
family members and manufacturers. Engineers should consider these
factors alongside their project requirements.
4. Training and Support: Adequate resources for training and technical
support are essential, particularly for less commonly used variants. This
ensures smooth development and troubleshooting.
5. Power Consumption: Although the 8051 series is recognized for having
low power consumption, subsequent models may require more power
due to added functionalities. Assessing power usage is essential for
battery-powered devices.

2.2 8051 ARCHITECTURE

Fig 2.2.1 Block Diagram of 8051


Fig 2.2.2 Architectural block diagram of microcontroller 8051

It seems like you've provided a detailed overview of various components and


features of the 8051 microcontroller. Here's a breakdown and summary
of the main components and their functions:

Components of 8051 Microcontroller

1. ALU (Arithmetic Logical Unit)


o Performs arithmetic and logical operations.
2. A-Accumulator
o 8-bit register for arithmetic operations.
o Bit-addressable for individual bit manipulation.

3. B-Register
o Used specifically in MUL AB and DIV AB instructions.
o Bit-addressable and 8-bit register.

4. PC-Program Counter
o 16-bit register pointing to the next instruction in ROM.
o Address range from 0000H to FFFFH (64KB).
o Initialized using ORG directive.
o Automatically incremented after each instruction.

5. PSW Register (Program Status Word)


o Contains flags indicating arithmetic conditions.
o Bit-addressable and 8-bit wide.
o Flags include Carry (CY), Auxiliary Carry (AC), Overflow (OV), and others.
Stack and Stack Pointer (SP)

o RAM locations 08H to 1FH used as stack.


o Stack operates on Last In, First Out (LIFO) principle.
o SP is an 8-bit register pointing to the current top of stack.
o Initialized to 07H, increments with PUSH, decrements with POP.

6. DPTR (Data Pointer)


o 16-bit register for accessing program and external data memory.
o Consists of DPH (high byte) and DPL (low byte).

7. I/OPorts (P0, P1, P2, P3)


o Four 8-bit ports for general-purpose I/O.
o P0 and P2 can serve dual purposes as address/data buses when interfacing with
external memory.
o P3 has additional functions like serial communication (RXD, TXD), interrupts
(INT0, INT1), and memory control signals (RD, WR).
8. Oscillator
o Provides clock signal to the microcontroller.
o Typically uses a crystal oscillator ranging from 4MHz to 30MHz.
o Determines the operating speed and baud rate.

9. Interrupts
o Special events that can interrupt normal program flow.
o Handled by Interrupt Service Routines (ISR).
o External interrupts INT0 and INT1 are associated with P3 pins.

10. Timers and Counters


o T0 and T1 are 16-bit timers/counters.
o Used for generating delays or counting external events.
o Controlled by TMOD (Timer Mode) and TCON (Timer Control) registers.
o TH0/TL0 and TH1/TL1 used for loading timer values.

11. Serial Port


o TXD and RXD pins for serial communication.
o SBUF register holds serial data.
o SCON register controls serial port operation.

The 8051 microcontroller is a versatile 8-bit architecture with a rich set of


features suitable for embedded systems. Its components include
arithmetic units, registers for data manipulation, program control
through PC and PSW, flexible I/O ports, stack management,
timers/counters for timing and event counting, and serial communication
capabilities. Understanding these components and their functionalities
helps in effectively designing and programming applications on the 8051
family of microcontrollers.

 Memory organization:
The 8051 microcontroller features 4kB of on-chip ROM and 128 bytes of
internal RAM.
o Another name for RAM is data memory, and another name for ROM is
program memory.
o Code memory is another name for program memory.

o This code memory contains the actual 8051 software that has to be
executed.
o The 8051 has a meager 64K of memory.
o Code memory is found in on-chip ROMs and EPROMs. Alternatively, and
this is the more common option, it can be retained completely off-chip in
an external EPROM or ROM.
The 8051 has only 128 bytes of internal RAM, however it can support
64kB of external RAM. As the name suggests, external RAM is any
random access memory that is not on-chip. The 8051 microcontroller has
128 bytes of internal RAM and 4kB of on-chip ROM.
o The RAM is also known as data memory and the. This code memory
contains the actual 8051 software that has to be executed.
o The 8051's memory is located off-chip.
o For example, increasing a position by one in Internal RAM requires only
one instruction and one instruction cycle, while increasing a 1-byte value
stored in External RAM requires four instructions and seven instruction
cycles.
As a result, this external memory operates seven times slower.

 Internal RAM OF 8051:


 The 8051's internal RAM is located on-chip.

o As a result, it is the quickest RAM on the market and offers the greatest
flexibility for reading, writing, and editing data.
o Because internal RAM is volatile, it is cleared during an 8051 reset.
o The internal 128 bytes Bank0, Bank1, Bank2, and Bank 3 are the four
register banks, each with
eight bits (a total of 32 bytes). Bank0 is the default bank registration. The
RS0 and RS1 bits of
the PSW Register are used to assist choose the remaining Banks.
As seen in the diagram, there are 16 bytes of bit addressable area and
80 bytes of general
purpose area (Scratch pad memory). The microcontroller additionally uses
this space as a
storage place for o The 8051's internal RAM is located on-chip.
o As a result, it is the quickest RAM on the market and the most
adaptable in terms of reading the
operating system.
o Working registers, arranged into four banks of eight registers each, are
created using the 32
bytes of RAM from address 00 H to 1FH.
o R0-R7 is the name of the registries. Either the RAM address or the
register name can be used to
address each one.

Fig2.2.3 Structure of RAM


The 8051 has 4KB of read-only memory (ROM) that can be used to store
programs.
o Permanent data storage is done here. or the data that is kept
unchanged while being processed, such as an algorithm or program
designed for a particular use.
This memory is volatile, meaning that even in the event of a power
outage, the data stored inside remains intact.
If the application is substantial, we can interface up to 64KB of ROM
memory externally.
o The companies have varying specifications for these sizes.
o PC Address Range: The program counter on a PC, which indicates the
next command to be executed, can be moved between various locations
based on its address range, or the program can be saved from one
location to another. It is possible to compute the address range in the
same way just like the RAM which is discussed in previous section

o Address range of PC is 0000H to 0FFFH means total 4KB locations are


available from 0000H to 0FFFH.

 SPECIAL FUNCTION REGISTERS (SFRs):

A few registers on the 8051 microcontroller use RAM addresses between 80h
and FFh and are designed for specific purposes.
o These registers are referred to as special function registers, or SFRs.
o Some of these registers are also bit addressable. The list of SFRs and
their functional names are displayed below. These SFRs fall into three
groups: those linked to I/O ports (P0, P1, P2, and P3), those meant for
control activities (TCON, SCON, PCON, etc.), and the other SFRs, which
are auxiliary in nature and do not directly configure the 8051.
Table : SFRs of 8051 Microcontroller
Fig 2.3.1 Pin Diagram of 8051
XTAL1,XTAL2:

The on-chip oscillator is powered by a quartz crystal oscillator, which is coupled


to these two pins.
o As seen in figure 2.3.2, the quartz crystal oscillator is connected to the
two pins together with a 30 pF capacitor.
o As illustrated in figure 2.3.3, if a source other than the crystal oscillator
is used, it will be connected to XTAL1 and XTAL2 will remain
disconnected.
Fig 2.3.2 Crystal Oscillator as Source Fig 2.3.3 External Clock Source

 ALE (Address latch enable): an active high pin.


Port 0 multiplexes address and data, delivering both address and
data, when it is connected to an external memory device.
o This ALE pin will be used to demultiplex the address and data
busses.
o When the pin is high, the AD bus acts as the address bus;
otherwise, it acts as the data bus.
2.4 PARALLEL I/O PORTS:

In the context of microcontrollers like the 8051, parallel I/O (Input/Output)


ports play a fundamental role in interfacing with external devices
and peripherals. The 8051 microcontroller specifically has four
parallel I/O ports, namely P0, P1, P2, and P3, each of which is 8 bits
wide. Here’s an overview of parallel I/O ports and their significance:

Parallel I/O Ports in 8051 Microcontroller

1. P0 (Port 0):
o Address: 80h
o Functionality:
 Port 0 is an 8-bit bidirectional I/O port.
 It can be used for general-purpose digital I/O.
 Additionally, it has alternate functions related to address and data bus
multiplexing.

2. P1 (Port 1):
o Address: 90h
o Functionality:
 Port 1 is another 8-bit bidirectional I/O port.
 It is used primarily for general-purpose digital I/O operations.
 It may also have additional alternate functions depending on specific
applications.

3. P2 (Port 2):
o Address: A0h
o Functionality:
 Port 2 is also an 8-bit bidirectional I/O port.
 It is often used for interfacing with higher-order address lines (A8-A15)
when external memory is used.
 Like other ports, it supports general-purpose digital I/O.

4. P3 (Port 3):
o Address: B0h
o Functionality:
 Port 3 is an 8-bit bidirectional I/O port.
 It has dual functions:
 General-purpose digital I/O.
 Special functions for external interrupt handling (INT0, INT1), serial
communication (TXD, RXD), and control signals (RD, WR).

Features and Usage

 Bidirectional Operation: Each port can be configured as either an input


or output port under program control.
 General-Purpose I/O: Used for connecting and controlling external
devices such as LEDs, switches, sensors, and actuators.
 Address and Data Bus Multiplexing: P0 and P2 can serve dual roles by
multiplexing address and data lines when interfacing with external
memory.
 Interrupts and Special Functions: Port 3 (P3) includes pins dedicated to
external interrupts (INT0, INT1), serial communication (TXD, RXD), and
memory control signals (RD, WR), making it versatile for various system-
level tasks.

Programming Considerations

 Configuring Ports: Ports are configured using appropriate control and


data direction registers.
 Bit-Level Access: Some ports (P0, P1, P3) are bit-addressable, allowing
individual bits to be manipulated directly.
 Interrupt Handling: Port 3 pins for interrupts require proper configuration
of interrupt enable registers (IE) and interrupt priority registers (IP).

Applications

 Embedded Systems: Used extensively in embedded systems for


interfacing with sensors, actuators, displays, and other peripherals.
 Industrial Automation: Controls and monitors various devices and
processes through digital I/O operations.
 Communication Interfaces: Handles communication protocols via UART
(Universal Asynchronous Receiver/Transmitter) using P3 (TXD, RXD).

Understanding the parallel I/O ports of the 8051 microcontroller is


essential for designing and implementing efficient control and
interfacing solutions in embedded systems applications. Each port’s
flexibility and features contribute to its versatility in a wide range of
electronic projects and industrial applications.
MODULE 3
PROGRAMMING 8051 AT ASSEMBLY LEVEL

3.1ADDRESSING MODES OF 8051:


The 8051 microcontroller employs several addressing modes to facilitate
efficient and flexible programming. These addressing modes allow the
programmer to access data and instructions in various ways, optimizing
code size and execution speed. Here are the addressing modes supported
by the 8051:

5.
Indexed Addressing Mode (XDATA):

 Format: MOVX A, @DPTR


 Description: Used specifically for external data memory access. The
instruction accesses data at the address specified by DPTR (Data Pointer).
This mode is useful when interfacing with external RAM or memory-
mapped peripherals.
6. Relative Addressing Mode:

 Format: Conditional jump instructions (e.g., JZ, JNZ, JC, etc.)


 Description: These instructions use a signed 8-bit offset to determine the
target address for conditional branching. The offset is added to the
current value of the Program Counter (PC), allowing the program to jump
to a location within -128 to +127 bytes relative to the current PC.

7. Bit Addressing Mode:

 Format: SETB bit or CLR bit


 Description: Allows individual bits within a byte in special function
registers (SFRs) or general-purpose RAM locations to be set or cleared.
This mode is essential for controlling specific bits that represent flags,
status bits, or control signals.

8. Immediate Addressing for Data Memory (IDATA):

 Format: MOV R0, #data


 Description: Similar to immediate addressing mode, but used specifically
for accessing data in internal RAM (IDATA space). The data is an 8-bit
constant that is immediately loaded into a register or memory location.

3.2INSTRUCTION SETS:
NOP: No operation.
 HLT: Halt CPU operation.
 MOVX @DPTR, A: Move accumulator to external RAM pointed by DPTR.
 MOVC A, @A+DPTR: Move code byte to accumulator from address
A+DPTR.
 LCALL addr: Long call to subroutine at specified address.
 RET: Return from subroutine.
 RETI: Return from interrupt.

8. Special Function Register (SFR) Instructions:

 MOVX A, @Ri: Move data from external RAM pointed by register Ri to


accumulator.
 MOVX @DPTR, A: Move accumulator to external RAM pointed by DPTR.
 MOVX A, @DPTR: Move data from external RAM pointed by DPTR to
accumulator.
 MOVX @Ri, A: Move accumulator to external RAM pointed by register Ri.

9. Serial Communication Instructions:

 MOV SBUF, A: Move accumulator to serial buffer register.


 MOV A, SBUF: Move data from serial buffer register to accumulator.

10. Timer and Interrupt Instructions:

 MOV TMOD, data: Load Timer/Counter mode register with data.


 MOV TCON, data: Load Timer/Counter control register with data.
 MOV THx, data: Load Timer/Counter high byte register with data.
 MOV TLx, data: Load Timer/Counter low byte register with data.

MODULE
4

PROGRAMMING ON CHIP
RESOURCES AT
ASSEMBLY LEVEL

4.1 TIMERS AND COUNT ERS

 TMOD (timer mode) Register:

This is an 8-bit register which is used by both timers 0 and 1 to set the
various timer modes. o In this TMOD register, lower 4 bits are set aside for
timer0 and the upper 4 bits are set aside for timer1. o In each case, the
lower 2 bits are used to set the timer mode and upper 2 bits to specify the
operation.
TMOD Register
Fig 4.1.1 Mode 1 Operation of Timer

 Mode 2
 o The timer is an 8-bit device that only accepts values in the range
of 00 to FFH to be entered into its register TH.
o The 8051 provides TL with a copy of the 8-bit value that was
loaded into TH.
o Next, you need to set the timer.
o The commands "SETB TR0" for timer 0 and "SETB TR1" for timer 1
do this.
This resembles mode 1.
o The timer increments the TL register to begin counting up after it
is started.
 The number counts up until the FFH limit is reached. when it shifts
to 00 from FFH. The TF (timer flag) is raised.
o When utilizing timer 0, TF0 rises; when utilizing TF1, TF1 rises.
· The original value stored by the TH register is immediately
reloaded into TL when the Tl register rolls from FFH to 00 and TF is
set to 1.
o All that is required to repeat the operation is to clear TF and let it
go, eliminating the need for the coder to reload the initial value.
o As a result, mode 2 reloads automatically, but mode 1 requires
the programmer to reload TH and TL.
o The Mode 2 is explained in figure 4.1.2.

Fig 4.1.2 Mode 1 Operation of Timer

Figure 4.1.3 Mode 1 and Mode 2 Operation of Timer With External Input

 Mode0
o Mode 0 is identical to mode 1, with the exception that it uses a 13-
bit timer rather than a 16-bit one. In TH-TL, the 13-bit counter may
store values from 0000 to 1FFFH. As a result, the timer rolls over to
0000 and TF is raised when it reaches its maximum of 1FFH.

 Mode3
Example
𝐶𝑟𝑦𝑠𝑡𝑎𝑙 𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦
  Machine Cycle Frequency =
12∗16

Table 4.2.3: Baud Rate Comparison For SMOD=0 Vs SMOD=1


TH1 TH1 (Hex) SMOD = 0 SMOD = 1
(Deci
mal)
-3 FD 9600 19200
-6 FA 4800 9600
-12 F4 2400 4800
-24 E8 1200 2400
4.3 RS232 STANDARD:

[Link] and Slew rates :

Rate of data transmission through RS232C is up to 20Kbps. The rate of


change in signal levels ie. slew rate is up to 30V/microsecond.

[Link] :

Maximum current rating is 3Amps at the maximum operating voltage of


250V AC.

Pins and Working :


1. RI –
When an incoming call on the telephone line is detected by DCE, then
the Ring Indicator gets activates.
MODULE 5
8051 INTERFACING
5.1 8255 Introduction:
Control word of PPI 8255A
Port A – as bidirectional
Mode for Port A –
mode 2 Port B – input
port
Mode for Port B – mode 1
Sol: The control word for this case is given as

Interfacing of 8255 to 8051

One can program the 8255 chip in any of the three previously stated
modes by passing a byte to the chip's control register. The port
addresses assigned to ports A, B, C, and CWR must first be located.
We refer to this as mapping the IO port. As seen in Fig., the 8255 is
connected to an 8051a. Because the IO chip is mapped into
memory space, this type of IO chip connection to CPU is known as
memory mapped IO. To access the 8255, we thus utilize
instructions like MOVX.
Programming example:
4 switches connected to the upper 4 bits of port A (PA4 – PA7). Write a
program to transfer status of switches to LEDs which connected to
the lower 4 bits of port B (PB0 – PB4)
CWR for above example –
99H
Address Port
4000H Port A
4001H Port B
4002 H port C
4003 H CWR
42

MOV A, 99H
MOV DPTR, #4003H MOVX A,
@DPTR
BACK: MOV DPTR, #4000H MOVX
A, @DPTR SWAP A
MOV DPTR, #4001H
MOV @DPTR, A SJMP BACK

5.2 Interfacing 8051 to 7 segment LED:


This explain the process of connecting a seven-segment LED display to an
8051 microcontroller. Besides showing digits 0 through 9, these displays
can also depict characters like A, B, C, H, E, e, F, n, o, t, u, y, and more.
Understanding how to interface these displays with microcontrollers is
crucial for embedded systems development.

A seven-segment display consists of seven LEDs arranged in the shape of a


slightly inclined "8", with an additional LED for displaying a dot character.
Different characters are displayed by selectively illuminating specific LEDs.
These displays come in two types: common cathode and common anode.

In common cathode displays, all cathodes of the seven LEDs are connected
together to a common terminal (often labeled "com"), while their anodes
are separate and labeled as "a," "b," "c," "d," "e," "f," "g," and "h" (or dot).
Conversely, in common anode displays, all anodes are connected together
to a common terminal, and the cathodes are individually designated.

The pin layout and an illustration of a typical seven-segment LED display


are depicted in the figure below.

R L V Prasad, Sr. Lect., Dept of Electronics, SGCSR College,


Rajam
43

Fig 5.1.17 segment LED display

Digit drive pattern.


The 'a' to 'h' terminals of a seven segment LED display can be configured in
various logic combinations to display different characters and digits,
which is known as the "digit drive pattern." The table below displays a
seven segment display's common digit drive patterns, numbered 0
through 9.

Digit a b C d E f g

0 1 1 1 1 1 1 0

1 0 1 1 0 0 0 0

2 1 1 0 1 1 0 1

3 1 1 1 1 0 0 1

4 0 1 1 0 0 1 1

5 1 0 1 1 0 1 1

6 1 0 1 1 1 1 1

7 1 1 1 0 0 0 0

8 1 1 1 1 1 1 1

9 1 1 1 1 0 1 1
44

Interfacing seven segment display to 8051.

Fig 5.1.2 Interfacing 7 segment display to 8051

A 0 to 9 counter based on an AT89S51 microprocessor is interfaced to a 7


segment LED display in the circuit diagram above to display the
count. This simple circuit illustrates two points. Build a simple 0 to 9
up counter with an 8051. More importantly perhaps, how to
connect a seven-segment LED display to an 8051 so it can display a
certain result. The connection between the common cathode seven
segment display D1 and the microprocessor (AT89S51) is depicted
in the circuit schematic. R3 through R10 are resistors that limit
current. S3 is the reset switch, and R2 and C3 make up the
debouncing circuitry. C1, C2, and X1 are components linked to
clock circuits. The software component of the project must finish
the following assignments.
45

• Set a delay of, let's say, thirty seconds and create a 0 to 9


counter.
• Using the existing count, create a digit drive design.
• Place the current digits' drive pattern into a port for display.
All of the aforementioned responsibilities are fulfilled by the
program that is stated below.

5.3 Stepper motor interfacing to 8051

Fig 5.3.1 stepper motors

R L V Prasad, Sr. Lect., Dept of Electronics, SGCSR College,


Rajam
46
47

To identify exact key pressed


Microcontroller Start with the top row by grounding it, then it reads the
columns. If the data read is all 1s, no key in that row is activated and
the process is moved to the next row until reach the row that has a
pressed key. At this stage, microcontroller identifies the row that has
a pressed key and can setup the starting address in the look-up table
for that row. The last step is finding the column that has a pressed
key by rotating the column bits by using carry flag and RRC
instruction, when 0 bit found in carry, microcontroller pulls the
corresponding code from the look-up table.
The following code is for scanning the 4 X 4 keyboard.
48

MOV
49

LOOK-UP TABLE POR EACH ROW


ORG 0000H DB ‘0’,’1’,’2’,’3’
DB ‘4’,’5’,’6’,’7’
DB ’8’,’9’,’A’,’B’
DB ‘C’,’D’,’3’,’F’ END
50

R L V Prasad, Sr. Lect., Dept of Electronics, SGCSR College,


51

5.5Analog -to-digital converters (ADC)

Analog-to-digital converters are a commonly used data collecting


equipment. Digital computers employ binary (discrete) values, but
everything in the actual world is analog (continuous), including
temperature, humidity, velocity, and pressure (liquid or wind).

An apparatus that transforms a physical quantity into electrical impulses is


called a transducer. Sensors are another term for transducers. We need to
use an ADC to convert the analog signals to digital values so that the
microcontroller can read and interpret them. There are options for both
parallel and serial ADCs.

Parallel ADC 0804

1
f 

R L V Prasad, Sr. Lect., Dept of Electronics, SGCSR College,


52

Digital and analog grounds


These are the input pins that provide ground to both analog and digital
signals.

The following steps must be taken in order to convert data using the
ADC0804.
• Set CS = 0 and pulse pin WR from low to high to start the conversion.
• Keep watching the INTR pin.
• If the INTR is low, the conversion procedure is finished.
• After the INTR decreases, we transmit high-to-low data to RD and set CS
= 0 to retrieve the data from ADC0804.
Figure illustrates the process's time.

R L V Prasad, Sr. Lect., Dept of Electronics, SGCSR College,


53

Fig shows interfacing connections between ADC0804 and 8051. Here CLKIN
connected to the external CLK at 8051’s crystal oscillator.
The program that follows enters an analog input into register A while
keeping an eye on the INTR pin. Subroutines for data presentation and
hex-to-ASCII conversion are then called. The pins D0-D7, which are the out
data pins of the ADC0804, are linked to port 1 of the 8051. The pins P2.5,
P2.6, and P2.7 of the 8051 are connected to the RD, WR, and INTR of the
ADC0804.

R L V Prasad, Sr. Lect., Dept of Electronics, SGCSR College,


54

Another useful chip is the


ADC0808/0809 has 8 analog
inputs. This chip allows 8
different analog inputs by
using selection ckt and has 8
output data lines just like
ADC0804.
Fig. shows pin configuration of ADC
0808/09 and table shows
selection of analog input
channel.

R L V Prasad, Sr. Lect., Dept of Electronics, SGCSR College,


55

5.6 DAC interfacing


Digital-to-analog (DAC) converter

One common tool for converting digital pulses to analog signals is the
digital-to-analog converter (DAC). We basically have two approaches for
creating a DAC from digital electronics.
1. Weighted binary
[Link] R/2R network

The R/2R approach is used by the MC1408 (DAC0808). An 8bit DAC is used
to transform digital data (of 8 bits) into analog signals. The number of data
inputs determines the DAC's resolution. Given n, the number of data bit
inputs, the number of analog output levels is therefore equal to 2n.
Consequently, the output of an 8-input DAC (0808) is 256 discrete voltage
or current values. The DAC0808 converts digital inputs to current (Iout).
The output is then converted to voltage by attaching a resistor to the Iout
pin.
The reference current (Iref) and the binary numbers D0 through D7 inputs
of the DAC0808 determine the total current supplied by the Iout pin, which
is determined by:
I =I
56

R L V Prasad, Sr. Lect., Dept of Electronics, SGCSR College,


Rajam
57

Interfacing LM 35 to 8051
58

Signal conditioning

P2.5 CS PIN P2.4


MYDATA EQU P1 CLR CS
SETB INTR BACK: CLR
WR
SETB WR HERE: JB INTR
HERE
CLR RD
MOV A, MYDATA ACALL DIPLAY
SJMP BACK

The interfacing ckt for temperature sensor to the microcontroller via ADC0804
as shown in fig.
59

You might also like