theory class 1dggfg

242
Saturday , April 06, 2013 WELCOME

Upload: kumar-gorla

Post on 08-Aug-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 1/250

Saturday, April 06, 2013

WELCOME

Page 2: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 2/250

Saturday, April 06, 2013

BASIC ELECTRICAL AND

ELECTRONIC COMPONENTS

• RESISTORS

• DIODES

• CAPACITORS

• INDUCTORS

• TRANSISTORS

• BATTERY

TRANSFORMER • VOLTAGE REGULATORS

• LDR (LIGHT DEPENDENT RESISTOR)

• RELAYS

Page 3: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 3/250

Saturday, April 06, 2013

The first band gives the first digit

The second band gives the second digit

The third band indicates the number of zeroes.

RESISTOR:

A resistor is a device which opposes the flow of 

current. It is invented by OTIS F.BOYKIN in 1938.

Page 4: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 4/250

Saturday, April 06, 2013

Colour   Number 

Black  0

Brown 1

Red 2

Orange 3 Yellow 4

Green 5

Blue 6

 Violet 7

Grey 8

White 9

Page 5: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 5/250

Saturday, April 06, 2013

DIODE:

A Diode is a two terminal electronic component that

conducts electric current only in one direction. It is

invented by William Henry Eccles in 1919.

Based on applications diodes are divided into two

types

-> PN junction

-> ZENER diode

Page 6: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 6/250

Saturday, April 06, 2013

PN junction diode:

The most common function of a diode is toallow an electric current in one direction (called

the forwarddirection) while blocking current in

the opposite direction (the reversedirection). 

Page 7: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 7/250

Saturday, April 06, 2013

ZENER DIODE:

A Zener diode is a type of diode that permits current inthe forward direction like a normal diode, but also in the

reverse direction if the voltage is larger than the

breakdown voltage known as "Zener knee voltage" or

"Zener voltage".

Page 8: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 8/250

Saturday, April 06, 2013

LIGHT EMITTING DIODE (LED)

A light-emitting diode (LED) is a semiconductor light

source. LEDs are used as indicator lamps in many

devices, and are increasingly used for lighting. 

k  

 A

Page 9: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 9/250

 

In forward bias the led will be in on condition

and vice versa.

It takes 2 to 3 v of voltage and 10 to 20mamps

of current. 

Saturday, April 06, 2013

Page 10: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 10/250

Saturday, April 06, 2013

It is invented by Ewald George Von Kelisf. In

1745. Active Capacitors(low), Passive

Capacitors(high).

Capacitor block AC signals. capacitors

easily pass DC signals 

CAPACITOR:

Page 11: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 11/250

Types of Capacitors…… 

Saturday, April 06, 2013

Electrolytic Capacitor

Film CapacitorDisk Capacitor

Page 12: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 12/250

Saturday, April 06, 2013

INDUCTOR:

• An inductor or a reactor can store energy in a

magnetic field created by the electric currentpassing through it. It is denoted in Henry.

• Typically an inductor is a conducting wire shaped

as a coil, the loops helping to create a strongmagnetic field inside the coil due to Faraday'sLaw of Induction.

Page 13: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 13/250

Saturday, April 06, 2013

TRANSISTORS:

A transistor is a semi conductor device commonly used

to amplify or switch electronic signals. A voltage orcurrent applied to one pair of the transistor's terminals

changes the current flowing through another pair of 

terminals. Because the controlled (output) power can be

much more than the controlling (input) power, the

transistor provides amplification of a signal. 

Page 14: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 14/250

TRANSISTOR 

• It is defined as Transfer of resistance and

for amplification purpose it is used.

• In the year 1947 at AT & T‟s BellLaboratories by JOHN Bardeen & Brattain

transistor is invented.

Saturday, April 06, 2013

Page 15: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 15/250

Saturday, April 06, 2013

Page 16: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 16/250

Saturday, April 06, 2013

Transformer:

Page 17: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 17/250

Transformer:

•Two types of transformers

Step up

Step down

• Transformer ratings

9-0-9

12-0-12

18-0-18

Saturday, April 06, 2013

Page 18: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 18/250

Saturday, April 06, 2013

VOLTAGE REGULATOR:

• A voltage regulator is an electrical regulator designed

to automatically maintain a constant voltage level.

It may use an electromechanical mechanism, or  passive or active electronic components. Depending

on the design, it may be used to regulate one or more

AC or DC voltages.

Page 19: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 19/250

Saturday, April 06, 2013

The voltage regulators are classified into two types.

positive series(7805)

negative series(7905)

7805

I/P GND O/P

7805SERIES Output

voltage

7905

I/P O/PGND

Page 20: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 20/250

Saturday, April 06, 2013

Light Dependent Resistor (LDR): 

An LDR is an input transducer (sensor)which converts brightness (light) to

resistance. It is made from cadmium

sulphide (CdS) and the resistance

decreases as the brightness of lightfalling on the LDR increases.

Page 21: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 21/250

Saturday, April 06, 2013

RELAY:

A Relay is an electrically controllable switch widelyused in industrial controls, automobiles, etc… 

inductor

Page 22: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 22/250

Saturday, April 06, 2013

OPERATION OF RELAY:

• The relay's switch connections are usually labeled COM,

NC and NO:• COM = Common, always connect to this, it is the

moving part of the switch.

• NC = Normally Closed, COM is connected to this whenthe relay coil is off.

• NO = Normally Open, COM is connected to this whenthe relay coil is on.

Connect to COM and NO if you want the switchedcircuit to be on when the relay coil is on.

• Connect to COM and NC if you want the switchedcircuit to be on when the relay coil is off.

Page 23: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 23/250

Saturday, April 06, 2013

 N/C

COM

 N/O

AC230V

Relay

I   ND

 U C T  OR

IRON

ARM

ON

OFF

Diagrammatic explanation:

Page 24: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 24/250

Saturday, April 06, 2013

REGULATED POWER SUPPLY:

Page 25: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 25/250

Saturday, April 06, 2013

7812

7805

C1

C2

5V

12V

REGULATED POWER SUPPLY CIRCUIT 

C

C=1000uF C1,C2=104pF R1,R2=330

R1

R2

Page 26: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 26/250

Saturday, April 06, 2013

RECTIFIER:

• The primary application of rectifiers is to drive usable

DC power from an AC supply. Virtually all electronics

except simple motor circuits such as fans require a DC

supply but mains power is AC so rectifiers find usesinside the power supplies of virtually all electronic

equipment. 

Page 27: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 27/250

Saturday, April 06, 2013

FILTERS:

• Electronic filters are electronic circuits which

perform signal processing functions, specifically toremove unwanted frequency or voltage or currentcomponents from the signal, to enhance wantedones. 

RECTIFIER 

OUTPUT FILTER PURE DC

AC+DC DC

AC

Page 28: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 28/250

Saturday, April 06, 2013

How the Transistor act as a switch ?

what is a transistor?

A transistor is a semi conductor device commonlyused to amplify or switch electronic signals.

Page 29: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 29/250

Saturday, April 06, 2013

What is a switch? In electronics, a switch is an electrical component

that can break an electrical circuit, interrupting

the current or diverting it from one conductor to

another.

Page 30: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 30/250

Saturday, April 06, 2013

Transistor as a switch:

• Transistor can be used as an electronic switch, in

grounded-emitter configuration.

• Transistors are commonly used as electronic

switches, for both high power applicationsincluding switched mode power supply and low

power applications.

V

Page 31: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 31/250

Saturday, April 06, 2013

 N/C

COM

 N/O

LDR 

100K 

PRESET

Vcc

relay

330

LED

LIGHT VB<0.7V

T-OFF

 NO

LIGHT

VB>0.7VT-ON

LOAD

Transistor as a switch

example

Page 32: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 32/250

Saturday, April 06, 2013

Page 33: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 33/250

 EMBEDDED SYSTEMS

MATLAB(Simulation)

 VLSI(Simulation)

Saturday, April 06, 2013

PROJECTS

Page 34: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 34/250

Saturday, April 06, 2013

1. First Embedded systems was introducedby CHARLES. Later on Students of MIT

University in the year 1961 in US.

2. Embedded Systems was First used for theproject MINITE MANE.9Processors Were

First Used for this project.

3. Embedded Systems is Divided into Two

Types

1. Simple E.S

2. Complex E.S

Page 35: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 35/250

Saturday, April 06, 2013

Embedded Systems

Simple

SystemsComplex

Systems

µp(1971) µc(1981)

Page 36: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 36/250

Saturday, April 06, 2013

•A uP•only is a single-chip CPU•bus is available•RAM capacity, num of port is selectable•RAM is larger than ROM (usually)

•A uC•contains a CPU and RAM,ROM ,Peripherals,I/O port in a single IC•internal hardware is fixed•Communicate by port•

ROM is larger than RAM (usually)•Small power consumption•Single chip, small board•Implementation is easy•Low cost

uP vs. uC 

Page 37: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 37/250

Saturday, April 06, 2013

Company 4 bit 8 bit 16 bit 32 bit 64 bit

INTEL4004

4040

8008

8080

8085

8088/6

80186

80286

80386

80486

80860

PENTIUM

ZILOG Z80

Z8000

Z8001

Z8002

MOTOR 

OLA

6800

6802

6809

68006

68008

68010

68020

68030

68040

History of Processors

E b dd d S t

Page 38: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 38/250

Saturday, April 06, 2013

Embedded SystemsBy Using the Software we are going to control

the operation of a hardware device.

Advantages:

•Automatic

•Power consumption

•Man power reduces

•Life time increases

•Efficiency increases

•Accurate In usage

Page 39: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 39/250

Saturday, April 06, 2013

• In general, "embedded system" is not a strictly

definable term, as most systems have some element of 

extensibility or programmability.

• For example, handheld computers share some elements

with embedded systems such as the operating systems

and microprocessors which power them, but they allow

different applications to be loaded and peripherals to

be connected or a few dedicated functions", and is thus

appropriate to call "embedded".

Page 40: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 40/250

Saturday, April 06, 2013

Embedded system

• An embedded system is a special purpose computer

system designed to perform one or a few dedicatedfunctions, often with real time computing

constraints.

• It is usually embedded as part of a complete device

including hardware and mechanical parts. 

• Since the embedded system is dedicated to specific

tasks, design engineers can optimize it, reducing the

size and cost of the product, or increasing the

reliability and performance.

• Embedded systems span all aspects of modern life.

Ch t i ti

Page 41: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 41/250

Saturday, April 06, 2013

Characteristics:

• Embedded systems are designed to do some

specific task, rather than be a general-purposecomputer for multiple tasks.

• Embedded systems are not always standalone

devices. Many embedded systems consist of small, computerized parts within a larger device

that serves a more general purpose.

• The program instructions written for embedded

systems are referred to as firmware, and arestored in read-only memory or Flash memory

chips.

Page 42: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 42/250

Saturday, April 06, 2013

Applications:

• Telecommunications• Consumer electronics like mp3 players, mobile

phones, digital cameras, DVD's, ovens, washing

machine, to control lights, to provide security,

climate, etc..

Page 43: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 43/250

Saturday, April 06, 2013

•  A more sophisticated devices use graphical

screen with touch sensing or screen-edge

buttons provide flexibility while minimizing space

used. the meaning of the buttons can change

with the screen.

Page 44: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 44/250

Saturday, April 06, 2013

• Serial Communication Interfaces (SCI): RS-232,RS-422, RS-485 etc

• Synchronous Serial Communication Interface: I2C,

ESSI (Enhanced Synchronous Serial Interface)

• Universal Serial Bus (USB)

• Multi Media Cards (SD Cards, Compact Flash etc)

Peripherals

Page 45: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 45/250

Saturday, April 06, 2013

• Networks: Ethernet, Controller Area Network, Lan

networks, etc 

• Timers: PLL(s), Capture/Compare and Time

Processing Units

•  Analog to Digital/Digital to Analog (ADC/DAC)

• Debugging: JTAG, ISP, ICSP, BDM Port, BITP DP9

port … 

Peripherals

Page 46: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 46/250

Saturday, April 06, 2013

• Embedded system means the processor is embeddedinto that application.

• An embedded product uses a microprocessor or

microcontroller to do one task only.

• In an embedded system, there is only one applicationsoftware that is typically burned into ROM.

• Example: printer, keyboard, video game player.

Overview of Embedded System

Page 47: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 47/250

Saturday, April 06, 2013

Page 48: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 48/250

Saturday, April 06, 2013

Contents

IntroductionBlock Diagram and PinDescription of the 8051

I/O Port Description

Led InterfacingSwitch Interfacing

Led And switch Interfacing

LCD Interfacing

Relay InterfacingADC Interfacing

Serial communication

Page 49: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 49/250

Saturday, April 06, 2013

Why do we need to learn

Microprocessors/controllers?

• The microprocessor is the core of computer

systems.

• Nowadays many communication, digital

entertainment, portable devices, are controlledby them.

• A designer should know what types of 

components they needs, ways to reduce

production costs and product reliable.

Page 50: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 50/250

Saturday, April 06, 2013

Aspects of a microprocessor/controller

• Hardware :

Interfacing devices with the real world. Ex-LCD, LED, printers, keyboard etc.

• Software :

In order how to deal with inputs. By usingsoftware we can control the hardware to

obtain the desired outputs.

Page 51: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 51/250

Saturday, April 06, 2013

Tools for a microprocessor/controller:

• CPU: Central Processing Unit

• I/O: Input /Output

• Bus: Address bus & Data bus

•Memory: RAM & ROM

• Timer

• Interrupt

• Serial Port

i (19 1)

Page 52: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 52/250

Saturday, April 06, 2013

CPU

General-

Purpose

Micro-

 processor 

RAM ROM I/O

PortTimer

Serial

COM

Port

Data Bus

Address Bus

General-Purpose Microprocessor System

• CPU for Computers.

• No RAM, ROM, I/O on CPU chip itself.

• Example: Intel's x86, Motorola‟s 680x0. 

Many chips on mother board

General-purpose microprocessor:

Microprocessors(1971):

Microcontroller(1981):

Page 53: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 53/250

Saturday, April 06, 2013

RAM ROM

I/O

PortTimer

Serial

COM

PortMicrocontroller

CPU

• A smaller computer.

• On-chip RAM, ROM, I/O ports...

• Example: Motorola‟s 6811, Intel‟s8051, Zilog‟s Z8, PIC16X,ATMEL,AVR,ARM.

A single chip

Microcontroller(1981):

Page 54: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 54/250

Saturday, April 06, 2013

Microprocessor 

• CPU is stand-alone,RAM, ROM, I/O,timer are separate

• designer can decideon the amount of ROM, RAM andI/O ports.

•Expansive,versatility.

• general-purpose

Microcontroller

• CPU, RAM, ROM, I/O

and timer are all on a

single chip

• fix amount of on-chipROM, RAM, I/O ports

for applications inwhich cost, power and

space are critical

• single-purpose

Microprocessor vs. Microcontroller

Page 55: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 55/250

Saturday, April 06, 2013

1. Meeting the computing needs of the task efficientlyand cost effectively

• speed, the amount of ROM and RAM, the numberof I/O ports and timers, size, packaging, power

consumption• easy to upgrade

• cost per unit

2. Availability of software development tools

• assemblers, debuggers, C compilers, emulator,simulator, technical support

3. Wide availability and reliable sources of themicrocontrollers.

Three criteria in Choosing a

Microcontroller:

Page 56: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 56/250

Saturday, April 06, 2013

Block Diagram:

CPU

On-chip

RAM

On-chip

ROM for

program

code

4 I/O Ports

Timer 0

Serial

PortOSC

Interrupt

Control

External interrupts

Timer 1

Timer/Counter

Bus

Control

TxD RxDP0 P1 P2 P3

Address/Data

Counter

Inputs

Page 57: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 57/250

Saturday, April 06, 2013

Feature 8051 8052 8031

ROM (program space in bytes) 4K 8K 0K 

RAM (bytes) 128 256 128

Timers 2 3 2I/O pins 32 32 32

Serial port 1 1 1

Interrupt sources 6 8 6

Comparison of the 8051 Family Members

Page 58: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 58/250

Saturday, April 06, 2013

4K Bytes On Chip ROM

128 bytes On Chip RAM

6 Interrupts

32 I/O channels

Bit Addressability

2 Timers

Features of 8051:

Other 8051 features

Page 59: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 59/250

Saturday, April 06, 2013

•only 1 On chip oscillator (external crystal)

•6 interrupt sources (2 external , 3 internal, Reset)

•64K external code (program) memory(only read)

•64K external data memory(can be read and write) by

RD,WR.

•Code memory is selectable by EA (internal or

external)

•We may have External memory as data memory and

code memory.

Other 8051 features 

Comparison of the 8051 Family

Page 60: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 60/250

Saturday, April 06, 2013

ROM type8031 no ROM80xx mask ROM87xx EPROM89xx Flash EEPROM

89xx

8951895289538955898252891051

892051Example (AT89C51,AT89LV51,AT89S51)

AT= ATMEL(Manufacture)C = CMOS technologyLV= Low Power(3.0v) S=Flash Programming.

Comparison of the 8051 Family

Members

Comparison of the 8051

Page 61: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 61/250

Saturday, April 06, 2013

89XX ROM RAM TimerInt

Source IO pin Other8951 4k 128 2 6 32 -

8952 8k 256 3 8 32 -

8953 12k 256 3 9 32 WD

8955 20k 256 3 8 32 WD

898252 8k 256 3 9 32 ISP

891051 1k 64 1 3 16 AC

892051 2k 128 2 6 16 AC

Comparison of the 8051

Family Members

WD: Watch Dog Timer

AC: Analog Comparator

ISP: In System Programmable

Pi D i ti f th 8051

Page 62: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 62/250

Saturday, April 06, 2013

Pin Description of the 8051:

1

23

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

40

3938

37

36

35

34

33

32

31

30

29

28

27

26

25

24

23

22

21

P1.0

P1.1P1.2

P1.3

P1.4

P1.5

P1.6

P1.7

RST

(RXD)P3.0

(TXD)P3.1

(T0)P3.4

(T1)P3.5

XTAL2

XTAL1

GND

(INT0)P3.2

(INT1)P3.3

(RD)P3.7

(WR)P3.6

Vcc

P0.0(AD0)P0.1(AD1)

P0.2(AD2)

P0.3(AD3)

P0.4(AD4)

P0.5(AD5)

P0.6(AD6)

P0.7(AD7)

EA/VPP

ALE/PROG

PSENP2.7(A15)

P2.6(A14)

P2.5(A13)

P2.4(A12)

P2.3(A11)

P2.2(A10)

P2.1(A9)

P2.0(A8)

8051

Page 63: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 63/250

Saturday, April 06, 2013

8051

SchematicPin out

Page 64: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 64/250

Saturday, April 06, 2013

8051 Description:

Vcc, gnd and xtal:

• Vcc pin 40

 – Vcc provides supply voltage to the chip.

 – The voltage source is +5V.

• GND: pin 20 ground

• XTAL1 and XTAL2 pins 19,18

Page 65: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 65/250

Saturday, April 06, 2013

8051 Description:

• Reset: pin 9 reset

 – It is an input pin and is active high normally low .

• The high pulse must be high at least 2 machine

cycles. – It is a power-on reset.

• Upon applying a high pulse to RST, the

microcontroller will reset and all values in

registers will be lost.• Reset values of some 8051 registers

Figure (b). Power-On RESET Circuit:

Page 66: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 66/250

Saturday, April 06, 2013

g ( )

30 pF

30 pF

8.2 K 

10 uF

+

Vcc

11.0592 MHz

EA/VPP

X1

X2

RST

31

19

18

9

8051 

Page 67: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 67/250

Saturday, April 06, 2013

0000DPTR 0007SP

0000PSW

0000B0000ACC

0000PC

Reset ValueRegister

RESET Value of Some 8051Registers: 

RAM are all zero 

SOME IMPORTANT PINS

Page 68: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 68/250

Saturday, April 06, 2013

PSEN (out): Program Store Enable, the read

signal for external program memory (active low).

ALE (out): Address Latch Enable, to latchaddress outputs at Port0 and Port2

EA (in): External Access Enable, active low toaccess external program memory locations 0 to4K 

RXD,TXD: UART pins for serial I/O on Port 3

XTAL1 & XTAL2: Crystal inputs for internaloscillator.

SOME IMPORTANT PINS

Pi f 8051

Page 69: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 69/250

Saturday, April 06, 2013

Pins of 8051:

EA: pin 31 external access – There is no on-chip ROM in 8031 and 8032 .

 – The EA pin is connected to GND to indicate the

code is stored externally.

 – PSEN ALE are used for external ROM.

 – For 8051, EA pin is connected to Vcc.

• PSEN: pin 29 program store enable

 – This is an output pin and is connected to the OE

pin of the ROM.

Pins of 8051:

Page 70: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 70/250

Saturday, April 06, 2013

Pins of 8051:

• ALE: pin 30 address latch enable

 – It is an output pin and is active high.

 – 8051 port 0 provides both address and data.

 – The ALE pin is used for de-multiplexing the

address and data by connecting to the G pin of the 74LS373 latch.

• I/O port pins

 – The four ports P0, P1, P2, and P3.

 – Each port uses 8 pins.

 – All I/O pins are bi-directional.

Page 71: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 71/250

Saturday, April 06, 2013

Address Multiplexing

for External Memory

 Accessingexternal

codememory

Pins of I/O Port:

Page 72: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 72/250

Saturday, April 06, 2013

Pins of I/O Port:

• The 8051 has four I/O ports

 – Port 0: pins 32-39, P0 P0.0-P0.7 – Port 1: pins 1-8 , P1 : P1.0-P1.7

 – Port 2: pins 21-28, P2 : P2.0-P2.7

 – Port 3: pins 10-17, P3 : P3.0-P3.7

 – Each port has 8 pins.• P0.X ,X=0,1,...,7, P1.X, P2.X, P3.X

• Ex: P0.0 is the bit 0, LSB of P0

• Ex: P0.7 is the bit 7, MSB of P0

• These 8 bits form a byte.

• Each port can be used as input or output (bi-direction).

Page 73: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 73/250

Saturday, April 06, 2013

Other Pins:

• P1, P2, and P3 have internal pull-up resisters.

 – P1, P2, and P3 are not open drain.

• P0 has no internal pull-up resistors and does not

connects to Vcc inside the 8051. – P0 is open drain.

• However, for a programmer, it is the same toprogram P0, P1, P2 and P3.

• All the ports upon RESET are configured asoutput.

Page 74: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 74/250

Saturday, April 06, 2013

Port 0 with Pull-Up Resistors:

Pull-up resistors are used in electronic logic circuits to

ensure that inputs to logic systems settle at expected logic

levels if external devices are disconnected.

Pull-up resistors may also be used at the interface

between two different types of logic devices, possibly

operating at different power supply voltages.

Pull Up Resistors

Page 75: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 75/250

Saturday, April 06, 2013

P0.0P0.1

P0.2P0.3P0.4P0.5P0.6P0.7

DS5000

8751

8951

Vcc

10 K 

 or  t  

0

Pull-Up Resistors 

P 3 Al F i

Page 76: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 76/250

Saturday, April 06, 2013

Port 3 Alternate Functions:

17RDP3.7

16WR P3.615T1P3.5

14T0P3.4

13INT1P3.3

12INT0P3.2

11TxDP3.1

10RxDP3.0

PinFunctionP3 Bit

Page 77: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 77/250

Saturday, April 06, 2013

Page 78: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 78/250

Saturday, April 06, 2013

ADDRESSING MODES:

There are five addressing modes available in the8051:

•  Register

•  Direct

•  Indirect

•  Immediate

•  Indexed

REGISTER ADDRESSING

Page 79: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 79/250

Saturday, April 06, 2013

REGISTER ADDRESSING:

• 8051 has access to eight working registers (R0

to R7)

• Some instructions are specific to a certain

register, such as the accumulator etc.

Example: ADD A,R7Example: MUL AB

Page 80: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 80/250

Saturday, April 06, 2013

Direct Addressing: •

Direct addressing is so-named because thevalue to be stored in memory is obtained by

directly retrieving it from another memory

location.

Example: MOV A,30h 

Page 81: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 81/250

Saturday, April 06, 2013

Indirect Addressing:

• In 8051 assembly language, indirect addressing is

represented by an @ before R0 or R1.

Example: MOV A, @R0

Moves a byte of data from internal RAM atlocation whose address is in R0 to the

accumulator.

Page 82: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 82/250

Saturday, April 06, 2013

Immediate Addressing:

• In assembly language, immediate operands are

preceded by #.

• Operand my be a numeric constant, a symbolic

variable or an arithmetic expression using

constants, symbols and operators.

Example: MOV A,#12

Page 83: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 83/250

Saturday, April 06, 2013

Indexed Addressing:

• Indexed addressing uses a base register (either the

program counter or data pointer) and an offset

(the accumulator) in forming the effective address

for a JMP or MOVC instruction.

Example: MOVC A, @A+DPTR 

On-Chip Memory

Page 84: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 84/250

On-Chip Memory

Internal RAM

Register Banks

Page 85: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 85/250

Saturday, April 06, 2013

Active bank selected by PSW[RS1,RS0] bit

Permits fast “context  switching” in interrupt service routines (ISR).

Register Banks

Registers F R i t

Page 86: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 86/250

Registers

0706050403020100

R7R6R5R4R3R2R1R0

0F

08

17

10

1F

18

Bank 3

Bank 2

Bank 1

Bank 0

Four RegisterBanks

Each bank hasR0-R7

Bit Addressable Memory

Page 87: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 87/250

Bit Addressable Memory

20h – 2Fh (16

locations X 8-bits

= 128 bits)

7F 78

1A

10

0F 08

07 06 05 04 03 02 01 00

27

26

25

24

23

22

21

20

2F

2E

2D

2C

2B

2A

29

28

Bit addressing:

mov a, 1Ahor

mov a, 23h.2

Special Function Registers

Page 88: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 88/250

Special Function Registers

DATA registers

CONTROL registersTimersSerial portsInterrupt systemAnalog to Digital converterDigital to Analog converter

Addresses 80h – FFh

Direct Addressing used toaccess SFRs

Page 89: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 89/250

Page 90: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 90/250

8051 CPU Registers

Page 91: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 91/250

•A (Accumulator)•B•PSW (ProgramStatus Word)•

SP (StackPointer)•PC (ProgramCounter)•DPTR (Data Pointer)

Used inassembler

instructions

Registers

Page 92: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 92/250

Registers

R0 

R1 

R3 

R4 

R2 

R5 

R7 

R6 

DPH  DPL 

PC 

DPTR  

PC 

Some 8051 16-bit Register 

Some 8-bit Registers

of the 8051 

Page 93: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 93/250

The 8051

Assembly Instructions

Overview

Page 94: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 94/250

Overview

• Data transfer instructions

• Data processing (arithmetic and logic)

• Program flow instructions or BranchingInstructions

• Addressing modes

Data Transfer Instructions

Page 95: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 95/250

Data Transfer Instructions

• MOV dest, source dest source• Stack instructions

PUSH byte ;increment stack pointer,

;move byte on stack

POP byte ;move from stack to byte,;decrement stack pointer

• Exchange instructionsXCH a, byte ;exchange accumulator and byte

XCHD a, byte ;exchange low nibbles of;accumulator and byte

Addressing Modes

Page 96: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 96/250

Addressing Modes

Immediate Mode  – specify data by its value

 mov A, #0 ;put 0 in the accumulator

;A = 00000000

 mov R4, #11h ;put 11hex in the R4

register

;R4 = 00010001

 mov B, #11 ;put 11 decimal in b register;B = 00001011

 mov DPTR,#7521h ;put 7521 hex in DPTR

;DPTR = 0111010100100001

Addressing Modes

Page 97: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 97/250

Addressing Modes

Register Addressing  – either source ordestination is one of CPU register

 MOV R0,A 

 MOV A,R7

 ADD A,R4

 ADD A,R7

 MOV DPTR,#25F5H

 MOV R5,DPL

 MOV R3,DPH

Note that MOV R4,R7 is incorrect

Addressing Modes

Page 98: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 98/250

Addressing ModesDirect Mode  – specify data by its 8-bit

addressUsually for 30h-7Fh of RAM

 Mov a, 70h ; copy contents of RAM at 70h to a

 Mov R0,40h ; copy contents of RAM at 40h to R0

 Mov 56h,a ; put contents of a at 56h

Addressing Modes

Page 99: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 99/250

Addressing Modes

Direct Mode  – play with R0-R7 by directaddress 

 MOV A,4    MOV A,R4

 MOV A,7    MOV A,R7

 MOV 7,2    MOV R7,R2 Invalid instruction

 MOV R2,#5 ;Put 5 in R2

 MOV R2,5 ;Put content of RAM at 5 in R2

Addressing Modes

Page 100: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 100/250

Addressing Modes

Register Indexed Mode  – source ordestination address is the sum of the base

address and the accumulator(Index)

• Base address can be DPTR or PC mov dptr, #4000h

 mov a, #5

 movc a, @a + dptr ;a M[4005]

SFRs Address

Page 101: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 101/250

 All SFRs such as( ACC, B, PCON, TMOD, PSW, P0~P3, …)

are accessible by name and direct

address

But

both of theseMust be coded as direct address

Stacks

Page 102: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 102/250

Stacks

pushpop

stack

stack pointer 

Go do the stack exercise….. 

Page 103: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 103/250

Data Processing Instructions

 Arithmetic Instructions

Logic Instructions

Arithmetic Instructions

Page 104: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 104/250

 Arithmetic Instructions

• Add

• Subtract

• Increment• Decrement

• Multiply

• Divide

• Decimal adjust

 Arithmetic Instructions

Page 105: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 105/250

Mnemonic Description

ADD A, byte add A to byte, put result in A

ADDC A, byte add with carry

SUBB A, byte subtract with borrow

INC A increment AINC byte increment byte in memory

INC DPTR increment data pointer

DEC A decrement accumulator

DEC byte decrement byte

MUL AB multiply accumulator by b register

DIV AB divide accumulator by b register

DA A decimal adjust the accumulator

 ADD Examples

Page 106: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 106/250

a p es

mov a, #3Fh

add a, #D3h • What is the value of theC, AC, OV flags after thesecond instruction isexecuted?

0011 11111101 0011

0001 0010 C = 1

 AC = 1OV = 0

Increment and Decrement

Page 107: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 107/250

• The increment and decrement instructions do NOT affect the Cflag.

• Notice we can only INCREMENT the data pointer, notdecrement.

INC A  increment A

INC byte increment byte in memory

INC DPTR  increment data pointer

DEC A  decrement accumulator

DEC byte decrement byte

Logic Inst ctions

Page 108: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 108/250

Logic Instructions

Bitwise logic operations

(AND, OR, XOR, NOT)

Clear

Rotate

Swap

Logic instructions do NOT affect the flags in PSW

Bitwise Logic

Page 109: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 109/250

g

 ANL  AND

ORL  OR

XRL  XOR

CPL  Complement 

Examples:

0000111110101100ANL

00001111

10101100ORL

00001111

10101100XRL

10101100CPL

00001100

10101111

10100011

01010011

Other Logic Instructions

Page 110: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 110/250

g

CLR  - clear

RL  – rotate left

RLC  – rotate left through CarryRR   – rotate right

RRC  – rotate right through

CarrySWAP – swap accumulator nibbles

CLR ( Set all bits to 0)

Page 111: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 111/250

CLR A 

CLR byte (direct mode)

CLR Ri (register mode)CLR @Ri (register indirect mode)

Rotate

Page 112: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 112/250

• Rotate instructions operate only on a

RL a

 Mov a,#0xF0 ; a 11110000

RR a ; a 11100001

RR a Mov a,#0xF0 ; a 11110000

RR a ; a 01111000

Swap

Page 113: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 113/250

p

SWAP a

 mov a, #72h ; a 72h 

swap a ; a 27h

Bit Logic Operations

Page 114: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 114/250

•Some logic operations can be used with single bitoperands

 ANL C, bit

ORL C, bit

CLR CCLR bit

CPL C

CPL bit

SETB C

SETB bit

•  “bit” can be any of the bit-addressable RAM locations orSFRs. 

Program Flow Control

Page 115: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 115/250

• Unconditional jumps (“go to”) 

• Conditional jumps

• Call and return

Unconditional Jumps

Page 116: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 116/250

•SJMP <rel addr>  ; Short jump,

relative address is 8-bit 2’s complement number,

so jump can be up to 127 locations forward, or 128

locations back.

•LJMP <address> ; Long jump

• AJMP <address> ; Absolute jump to

anywhere within 2K block of program memory

•JMP @A + DPTR  ; Long indexed jump

Infinite Loops

Page 117: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 117/250

p

Start: mov C, p3.7

 mov p1.6, C

sjmp Start

Microcontroller application programs are almost always infinite loops!

Conditional Jump

Page 118: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 118/250

• These instructions cause a jump to occur only if acondition is true. Otherwise, program executioncontinues with the next instruction.

loop: mov a, P1jz loop ; if a=0, goto loop, 

; else goto next instruction

 mov b, a

• There is no zero flag (z)

• Content of A checked for zero on time

Conditional jumps

Page 119: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 119/250

j p

Mnemonic DescriptionJZ <rel addr>  Jump if a = 0

JNZ <rel addr>  Jump if a != 0

JC <rel addr>  Jump if C = 1

JNC <rel addr>  Jump if C != 1

JB <bit>, <rel addr>  Jump if bit = 1

JNB <bit>,<rel addr>  Jump if bit != 1

JBC <bir>, <rel addr>  Jump if bit =1, &clear

bitCJNE A, direct, <rel addr> Compare A and memory,

jump if not equal

Example: Conditional Jumps

Page 120: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 120/250

if (a = 0) is truesend a 0 to LED

else

send a 1 to LED

More Conditional Jumps

Page 121: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 121/250

 Mnemonic Description

CJNE A, #data <rel addr>  Compare A and data, jump

if not equal

CJNE Rn, #data <rel addr>  Compare Rn and data,

jump if not equalCJNE @Rn, #data <rel addr>  Compare memory and data,

jump if not equal

DJNZ Rn, <rel addr>  Decrement Rn and then

jump if not zero

DJNZ direct, <rel addr>  Decrement memory and

then jump if not zero

Call and Return

Page 122: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 122/250

• Call is similar to a jump, but – Call pushes PC on stack before branching

acall <address ll>  ; stack

PC; PC address 11 bit

lcall <address 16>  ; stack PC

; PC address 16 bit

Return

Page 123: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 123/250

• Return is also similar to a jump, but

 – Return instruction pops PC from stack to getaddress to jump to

ret ; PC stack

Subroutines

Page 124: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 124/250

 Main: ...

acall sublabel

...

...

sublabel: ...

...

ret

the subroutine

call to the subroutine

Why Subroutines?

Page 125: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 125/250

• Subroutines allow us to have "structured"assembly language programs.

• This is useful for breaking a large designinto manageable parts.

• It saves code space when subroutines can

be called many times in the sameprogram.

Timer Delay Calculation for

Page 126: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 126/250

XTAL = 11.0592 MHz(a) in hex

• (FFFF  –  YYXX + 1) × 1.085 s 

• where YYXX are TH, TL initial values respectively.

•Notice that values YYXX are in hex.

(b) in decimal

• Convert YYXX values of the TH, TL register to

decimal to get a NNNNN decimal number • then (65536  –  NNNNN) × 1.085 s

Page 127: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 127/250

Saturday, April 06, 2013

Page 128: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 128/250

Saturday, April 06, 2013

Page 129: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 129/250

Saturday, April 06, 2013

LED (Light Emitting Diode):

• Light-emitting diodes are elements for light

signalization in electronics.

• They are manufactured in different shapes, colors and

sizes.• Low price, low consumption and simple use

•  These LED‟s are used for indication purpose i.e., ON

& OFF.

Symbol of LED:

Page 130: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 130/250

Saturday, April 06, 2013

Symbol of LED:

Some different colors of LED:

Page 131: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 131/250

Saturday, April 06, 2013

Some different colors of LED:

How to interface LED with

Page 132: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 132/250

Saturday, April 06, 2013

microcontroller ?

• Anode is connected through a resistor to Vcc &

the Cathode is connected to the Microcontroller

pin.

• So when the Port Pin is HIGH the LED is OFF &

when the Port Pin is LOW the LED is turned ON. 

Page 133: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 133/250

Saturday, April 06, 2013

Can we connect like this?

Page 134: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 134/250

Saturday, April 06, 2013

• When the port Pin is HIGH the Anode is positivewith respect to the Cathode so the LED should

Page 135: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 135/250

Saturday, April 06, 2013

pturn ON right?

• But the internal pull-up resistor comes in serieswith the resistor thus limiting the current flowingthrough the LED. This current is not sufficient

enough to Turn ON the LED.

A Simple Program to glow an LED:

Page 136: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 136/250

Saturday, April 06, 2013

A Simple Program to glow an LED:

ORG 0000HCLR P1.0 //Turn ON LED

CLR P1.1

CLR P1.2END

A program using port to glow an LED :

Page 137: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 137/250

Saturday, April 06, 2013

A program using port to glow an LED :

ORG 0000H

MOV p1,#OOH //Copy P1 to A

END

A program to ON &OFF the LED:

Page 138: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 138/250

Saturday, April 06, 2013

CASE1:ORG 0000H

MOV P1,#OFFHMOV P1,#OOH

END

CASE 2:

Page 139: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 139/250

Saturday, April 06, 2013

CASE 2: 

ORG 0000H

MOV P1,#OFFH

MOV A,P1

CPL A //ComplimentMOV P1,A

END

Page 140: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 140/250

Saturday, April 06, 2013

SWITCH INTERFACING

Page 141: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 141/250

Saturday, April 06, 2013

An electrical switch is any device used to interrupt

the flow of electrons in a circuit. Switches areessentially binary devices: they are eithercompletely on ("closed") or completely off ("open").

• CPU accesses the switches through ports.Therefore these switches are connected to amicrocontroller. This switch is connected between

the supply and ground terminals.

• These switches are connected to an input port.

Vcc

Page 142: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 142/250

Saturday, April 06, 2013

P2.1R

GND

Interfacing switch with the microcontroller 

8

0

5

1

Thus now the two conditions are to beremembered:

Page 143: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 143/250

Saturday, April 06, 2013

• When the switch is open, i.e., when not pressed the

total supply i.e., Vcc appears at the port pin P2.0

P2.0 = 1

• When the switch is closed i.e., when it is pressed,

the total supply path is provided to ground. Thusthe voltage value at the port pin P2.0 will be zero.

P2.0 = 0

Vcc

Page 144: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 144/250

Saturday, April 06, 2013

P2.1

R

GND

Interfacing Led And Switch with the Microcontroller 

8

0

5

1

Vcc

P1.0

Page 145: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 145/250

Saturday, April 06, 2013

Liquid crystal display (LCD):

• A liquid crystal display (LCD) is a thin flat panel

Page 146: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 146/250

Saturday, April 06, 2013

• A liquid crystal display (LCD) is a thin, flat panel

used for electronically displaying information such

as text, images, and moving pictures. 

• Its uses include monitors for computers,

televisions, instrument panels, and other devices

ranging from aircraft cockpit displays, to every-day consumer devices such as gaming devices,

clocks, watches, calculators, and telephones.

•  Among its major features are its lightweight

construction its portability and its ability to be

Page 147: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 147/250

Saturday, April 06, 2013

construction, its portability, and its ability to be

produced in much larger screen sizes than are

practical for the construction of cathode ray tube

(CRT) display technology.

Why we are using LCD ?

Page 148: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 148/250

Saturday, April 06, 2013

• Its low electrical power consumption enables it tobe used in battery-powered electronic equipment.

It is an electronically-modulated optical device

made up of any number of pixels filled with liquid

crystals and arrayed in front of a light source

(backlight) or reflector to produce images in color

or monochrome.

Pin Description of LCD:

Page 149: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 149/250

Saturday, April 06, 2013

1.  Ground2. Vcc +5V

3. Contrast control

4. Register select (RS)5. Read/Write (RD/WR)

6. Enable (EN)

7 – 14 pins all are data pins D0 – D7

15. Vcc +5V }

16. Ground }For backlight purpose

RS (register select):

The register select pin is used for the selection of the required register either data or command

Page 150: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 150/250

Saturday, April 06, 2013

the required register either data or commandregister

If RS=0 ; command register is selected

If RS=1 ; data register is selected

R/W (read or write):

This pin is for the selection of read or write modeIf R/W=0 ; write mode is selected

If R/W=1 ; read mode is selected

EN (enable):• Enable pin is a active high to low pin used for

writing the data to the LCD.

LCD COMMAND CODES:

Page 151: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 151/250

Saturday, April 06, 2013

• 01 Clear display screen

• 06 Increment cursor

• 38 2lines and 5 by 7 matrix

• 80 Force cursor to beginning of 1st line

• 0E Display on, cursor blinking

• C0 Force cursor to beginning 0f 2nd line

LCD INTERFACING WITH MICROCONTROLLER:

Page 152: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 152/250

Saturday, April 06, 2013

P0.0P0.1P0.2

P0.3

P0.4

P0.5

P0.6

P0.7

D0

D1

D2

D3

D4

D5

D6

D7RS R/W E

P2.0

P2.1

P2.2

Vss

Vee

Vss

10k

POT

8

0

51

LCD

GND

How To Send Commands To LCD: 

Page 153: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 153/250

Saturday, April 06, 2013

COMMAND:

CLR RS

CLR R/W

SETB EN

CLR EN

How to send Data to LCD:

Page 154: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 154/250

Saturday, April 06, 2013

DATA:

SETB RS

CLR R/W

SETB EN

CLR EN

A Simple Program Of LCD:

Page 155: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 155/250

Saturday, April 06, 2013

ORG OOH

MOV A,#38H

ACALL COMMAND

MOV A,#0EH

ACALL COMMAND

MOV A,# ‟H‟ 

ACALL DATA

MOV A,# „I‟ 

ACALL DATA

COMMAND : CLR RSCLR R/W

SETB EN

Page 156: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 156/250

Saturday, April 06, 2013

SETB EN

CLR ENRET

DATA:

SETB RSCLR R/W

SETB EN

CLR EN

RET

END

Page 157: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 157/250

Saturday, April 06, 2013

Relay Interfacing With

Microcontroller 

Page 158: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 158/250

Saturday, April 06, 2013

Relay: It can be defined as an electrical switch that opens

and closes under the control of another electrical circuit.

The switch is operated by an electromagnet to open or

close one or more of contacts. A relay is able to control an

output circuit of higher power than the input circuit.Relays are devices which allow low power circuits to

switch a relatively high Current/Voltage ON/OFF.

For a relay to operate a suitable pull-in & holding current

should be passed through its coil.

Generally relay coils are designed to operate from a

particular voltage often its 5V or 12V.

Types:

There are many types of relays which are as

f ll

Page 159: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 159/250

Saturday, April 06, 2013

follows:

SPDTDPDT

Symbol Of Relay:

Advantages of relays:

• R l it h AC d DC t i t

Page 160: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 160/250

Saturday, April 06, 2013

• Relays can switch AC and DC, transistors

can only switch DC.• Relays can switch high voltages, transistors

cannot.

• Relays are a better choice for switchinglarge currents (> 5A).

• Relays can switch many contacts at once.

Disadvantages Of Relay: 

Page 161: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 161/250

Saturday, April 06, 2013

• Relays are bulkier than transistors for

switching small currents.

• Relays cannot switch rapidly , transistors

can switch many times per second.

• Relays use more power due to the current

flowing through their coil.

SPDT Relay (Single Pole Double Throw) :

An electromagnetic switch, consist of a coil , 1

Page 162: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 162/250

Saturday, April 06, 2013

g , ,

common terminal , 1 normally closed terminal ,

and one normally open terminal.

When the coil of the relay is at rest (not

energized), the common terminal and thenormally closed terminal have continuity. When

the coil is energized, the common terminal and the

normally open terminal have continuity.

DPDT (Double Pole Double Throw):

• Can be used to isolate float switches from spiking

Page 163: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 163/250

Saturday, April 06, 2013

voltage or excessive current.

• Avoids risk that spiking pump voltage will hurt

float switches.

Specifications:

• Coil voltage: 12VDC

• Coil resistance: 160 Ohms

• Contact rating: 10A at 250VAC or 30VDC.

Why do I want to use a relay and do I really

need to? 

Page 164: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 164/250

Saturday, April 06, 2013

• The coil of an SPDT relay that we most commonly

use draws very little current (less than 200

milliamps) and the amount of current that you can

pass through a relay's common, normally closed,and normally open contacts will handle up to 30 or

40 amps. This allows you to switch devices such as

headlights, parking lights, horns, etc.,

SPDT & DPDT:

Page 165: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 165/250

Saturday, April 06, 2013

Relay Interfacing with the Microcontroller:

Page 166: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 166/250

Saturday, April 06, 2013

1 U 16

2 L 15

3 N 14

4 2 13

5 8 12

6 0 11

7 3 10

8 9 

RELAY LOAD 

Ground Vcc 

AT 89S52

P1.0

ULN2003 CURRENT DRIVER:

• The ULN2003 current driver is a high voltage, high

Page 167: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 167/250

Saturday, April 06, 2013

g g , g

current Darlington arrays each containing seven

open collector Darlington pairs with common

emitters. Each channel is rated at 500mA and can

withstand peak currents of 600mA. 

ULN DRIVER CIRCUIT

Page 168: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 168/250

Saturday, April 06, 2013

This ULN2003 driver can drive seven relays at a

time. The pins 8 and 9 provide ground and Vcc

respectively.

Working Of ULN Driver:

Page 169: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 169/250

Saturday, April 06, 2013

• It can accept seven inputs at a time and produces

seven corresponding outputs. If the input to any

one of the seven input pins is high, then the value

at its corresponding output pin will be low, forexample if the input at pin 6 is high, then the value

at the corresponding output i.e., output at pin 11

will be low. Similarly if the input at a particular

pin is low, then the corresponding output will behigh.

• Thus for the output to be low, the input applied at

that corresponding input pin should be high. The

input to the ULN driver is provided by the

Page 170: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 170/250

Saturday, April 06, 2013

input to the ULN driver is provided by the

microcontroller. Thus the instruction required tooperate the relay through the microcontroller is

SETB PX.Y

• Where X is the port number (P0, P1, P2

and P3).

• And Y is the pin number of Port X.

Applications:

Page 171: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 171/250

Saturday, April 06, 2013

• To control a high-voltage circuit with a low-

voltage signal

• To control a high-current circuit with a low-

current signal,• To detect and isolate faults on transmission and

distribution lines by opening and closing circuit

breakers.

RS232

Page 172: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 172/250

Saturday, April 06, 2013

To ensure fast and reliable data transmission

between two devices

In RS232 it consists of 9 pins but we generally

use only three pins 2,3 and 5 namely TXD RXD

GND respectively. 

MAX232To convert TTL or CMOS voltages to RS232

voltages, and vice versa

Page 173: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 173/250

Saturday, April 06, 2013

voltages, and vice versa 

Complementary metal – oxide – semiconductor

(CMOS)

CMOS uses complementary and symmetrical

pairs of p-type and n-type metal oxide

semiconductor field effect transistors (MOSFET‟s)

for logic functions. 

Two important characteristics of CMOS devicesare high noise immunity and low static power

consumption. 

TTL (Transistor transistor logic)

Page 174: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 174/250

Saturday, April 06, 2013

• TTL integrated circuits were a standard method

of construction for the processors of mini-

computer and mainframe processors

• Transistor – transistor logic (TTL) is a class of digital circuits built from bipolar junction

transistors (BJT) and resistors. It is called

transistor – transistor logicbecause both the logic

gating function (e.g., AND) and the amplifyingfunction are performed by transistors 

MAX232

Page 175: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 175/250

MAX 232 INTERFACING WITH MICRO

CONTROLLER 

Page 176: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 176/250

Saturday, April 06, 2013

13514TxD0(P3.1)

RxD0(P3.0)

11 1110 12

23

8

0

5

1

M

A

X

2

3

2

DB

9 GND

Page 177: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 177/250

Saturday, April 06, 2013

ANALOG TO DIGITAL CONVERTER  

• Analog-to-digital converters are among the most

Page 178: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 178/250

Saturday, April 06, 2013

Analog-to-digital converters are among the most

widely used devices for data acquisition. Digitalsystems use binary values, but in the physical world

everything is continuous i.e., analog values.

Temperature, pressure (wind or liquid), humidity

and velocity are the physical analog quantities.

• These physical quantities are to be converted into

digital values for further processing. Thus, an

analog-to-digital converter is needed to convert

these electrical signals into digital values so that the

microcontroller can read and process them.

ADC0804:

• The ADC chip that is used in this project is

Page 179: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 179/250

Saturday, April 06, 2013

The ADC chip that is used in this project is

ADC0804. The ADC0804 IC is an 8-bit parallelADC in the family of the ADC0800 series from

National Semiconductor. It works with +5 volts

and has a resolution of 8 bits. In the ADC0804, the

conversion time varies depending on the clockingsignals applied to the CLK IN pin, but it cannot be

faster than 110µs.

PIN Diagram of ADC

Page 180: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 180/250

Saturday, April 06, 2013

Pin description of ADC

CS (Chip selection):

Page 181: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 181/250

Saturday, April 06, 2013

Chip select is a active low input used to activatethe ADC 0804.

RD (read):

This is also a active low pin used to get theconverted data out of the ADC 0804.

WR (write):

This is also active low used to inform the ADC tostart the conversion process.

CLK IN & CLK R:

CLK IN is connected to external clock whenexternal clock is used and if internal clock is used

Page 182: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 182/250

Saturday, April 06, 2013

both clocks are connected to capacitor and aresistor.

INTR (INTERRUPT):

It is an active low output pin using for stop theconversion.

Vin(+) & Vin(-):

Vin(+) is used for the conversion of analog todigital by connecting Vin(-) to the ground. 

Vcc:It is the +5v power supply to the chip.

Vref/2:

Pi 9 i d f th f lt If d

Page 183: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 183/250

Saturday, April 06, 2013

Pin 9 is used for the reference voltage. If we need

the input range 0-4V, Vref/2 is connected to 2V.D0-D7:

These are the digital data output pins.

D7 is the MSB.Analog ground & Digital ground:

Analog ground is connected to ground of analogVin while taking the inputs in the same way digital

ground is also used for the digital outputs. 

ADC INTERFACE WITH MICROCONTROLLER 

89C51

Page 184: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 184/250

Saturday, April 06, 2013

89C51 

P2.4P2.5P2.6

P2.7P1.7P1.6

P1.5P1.4P1.3P1.2

P1.1P1.0

Keypads are a part of HMI or Human Machine Interface and

play really important role in a small embedded system where

KEYPAD INTERFACING

Page 185: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 185/250

Saturday, April 06, 2013

play really important role in a small embedded system where

human interaction or human input is needed. Matrix keypadsare well known for their simple architecture and ease of 

interfacing with any microcontroller.

Interfacing the Keyboard to the 8051

At the lowest level, keypads are organized in a matrix of rows

and columns. The CPU accesses both rows and column

through ports; therefore, an 4*4 matrix of keys can be

connected to a microprocessor. When a key pressed, a row andcolumn make a connect; otherwise, there is no connection

between row and column.

Constructing a Matrix Keypad:

Construction of a keypad is really simple. As per the

outline shown in the figure below we have four rows and

Page 186: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 186/250

Saturday, April 06, 2013

outline shown in the figure below we have four rows and

four columns. In between each overlapping row andcolumn line there is a key.keeping this outline we can

construct a keypad using simple SPST Switches as

shown below: 

Consider an example

Row4-row1 = 1110

Page 187: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 187/250

Saturday, April 06, 2013

Row4-row1 1110

Col4-col1 = 1011

That means the row 1 and the col 3 intersected i.e.

sw3 is pressed.

Page 188: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 188/250

Saturday, April 06, 2013

What is communication?

Page 189: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 189/250

Saturday, April 06, 2013

• Communication is nothing but sharing of data or

transferring the data from one system to another.

system1 system2

Types of communication:

Page 190: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 190/250

Saturday, April 06, 2013

In Serial communications means informationis transmitted from source to destination over a

single pathway.

In Parallel Communication, often 8 or more

lines are used to transfer data to a device that isonly a few feet.

COMPUTERS TRANSFER DATA INTWO WAYS:

Page 191: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 191/250

Saturday, April 06, 2013

Sender Receiver Sender Receiver 

Serial Transfer  Parallel Transfer 

D0-D7D0

Other control lines

Other control lines

Why we prefer serial transmission

over parallel transmission?

Page 192: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 192/250

Saturday, April 06, 2013

• In Parallel data transfers, often 8 or more lines

are used to transfer data to a device that is only

a few feet.

• Where as serial transmission uses only singleline to transmit the same data over long

distances

• There are chances of loosing data in parallel

communication rather than in serial

communication.

Simplex vs. Duplex Transmission

Page 193: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 193/250

Saturday, April 06, 2013

• Simplex transmission: the data can sent in onedirection.

 – Example: the computer only sends data to the

printer.

• Duplex transmission: the data can be transmitted

and received.

Transmitter Receiver 

Transmitter 

Receiver Receiver 

Transmitter 

Half vs. Full Duplex

Page 194: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 194/250

Saturday, April 06, 2013

• Half duplex: if the data is transmitted one way at

a time.

• Full duplex: if the data can go both ways at the

same time. Two wire conductors for the data lines.

Transmitter 

Receiver 

Receiver 

Transmitter 

Transmitter 

Receiver 

Receiver 

Transmitter 

RxD and TxD pins in the 8051

Page 195: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 195/250

• TxD pin 11 of the 8051 (P3.1)

• RxD pin 10 of the 8051 (P3.0)

SBUF register MOV SBUF,#’D’ ;load SBUF=44H, ASCII for

‘D’ 

 MOV SBUF,A  ;copy accumulator intoSBUF

 MOV A,SBUF ;copy SBUF into

accumulator

Registers Used in Serial Transfer Circuit

Page 196: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 196/250

Saturday, April 06, 2013

• SBUF (Serial data buffer)

• SCON (Serial control register)

• TMOD (Timer mode register)

SBUF

Page 197: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 197/250

Saturday, April 06, 2013

• This is an 8-bit register used for serial

communication in 8051.For a byte of data to be

transferred it must be placed in sbuf register and

in similar way sbuf holds the data when it isreceived.

SCON Register (serial control)

It used to program the start bit, stop bit and data

Page 198: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 198/250

Saturday, April 06, 2013

SM0 SM1 SM2 REN TB8 RB8 TI RI

It used to program the start bit, stop bit and data

bits of data framing

SM0 , SM1:These two bits determine the framing of data by

specifying the number of bits per character, and

the start and stop bits.

SM0 SM1

0 0 Serial Mode 0

Page 199: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 199/250

Saturday, April 06, 2013

0 0 Serial Mode 0

0 1 Serial Mode 1, 8-bit data, 1 stop bit,

1 start bit

1 0 Serial Mode 2

1 1 Serial Mode 3

RECEIVE - Data receive through the RXD pin startsupon the two following conditions are met: bit REN=1

and RI=0

(both of them are stored in the SCON register) When all

Page 200: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 200/250

Saturday, April 06, 2013

(both of them are stored in the SCON register). When all

8 bits have been received, the RI bit of the SCON register

is automatically set indicating that one byte receive is

complete.

TRANSMIT - Data transmit is initiated by writing data

to the SBUF register. In fact, this process starts after any

instruction being performed upon this register. When all

8 bits have been sent, the TI bit of the SCON register isautomatically set.

Serial control (SCON) Register

SM0 RITIRB8TB8RENSM2SM1

Page 201: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 201/250

SM0 (SCON.7) : mode specifier 

SM1 (SCON.6) : mode specifier 

SM2 (SCON.5) : used for multi processor communication

REN (SCON.4) : receive enable (by software enable/disable)

TB8 (SCON.3) : transmit bit8

RB8 (SCON.2) : receive bit 8

TI (SCON.1) : transmit interrupt flag set by HW clear by SWRI (SCON.0) : receive interrupt flag set by HW clear by SW 

SM0 RITIRB8TB8RENSM2SM1

TMOD

Page 202: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 202/250

Saturday, April 06, 2013

• TMOD is an 8 bit register in which the lower 4 bits

are set aside for Timer0 and the upper 4 bits for

Timer1.

GATE C/T M0 M1 GATE C/T M1 M0

TMOD -Timers 

Bit Number   Type  Working  Timer Type 

7 GATE1Gating Control when

1

Page 203: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 203/250

Saturday, April 06, 2013

7 GATE1g

set1

6 C/T1

To decide whether 

timer is used as a

delay generator or 

as an event counter 

1

5 M1 Timer mode bit 1

4 M0 Timer mode bit 1

3 GATE0Gating Control

Purpose0

2 C/T0

To decide whether 

timer is used as a

delay generator or 

as an event counter 

0

1 M1 Timer mode bit 0

0 M0 Timer mode bit 0

Gate

E ti h f t ti d t i

Page 204: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 204/250

•Every timer has a mean of starting and stopping.

 – GATE=0

• Internal control

• The start and stop of the timer are controlled by way of software. 

• Set/clear the TR for start/stop timer. – GATE=1

• External control

• The hardware way of starting and stopping the timer bysoftware and an external source.

• Timer/counter is enabled only while the INT pin is high and theTR control pin is set (TR).

M1, M0

• M0 and M1 select the timer mode for timers 0 & 1.

Page 205: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 205/250

0 0 0  13-bit timer mode

8-bit THx + 5-bit TLx (x= 0 or 1)

0 1 1  16-bit timer mode

8-bit THx + 8-bit TLx

1 0 2  8-bit auto reload

8-bit auto reload timer/counter;

THx holds a value which is to be reloaded into

TLx each time it overflows.1 1 3 Split timer mode

Example 9-3

Find the value for TMOD if we want to program timer 0 in mode 2,

Page 206: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 206/250

use 8051 XTAL for the clock source, and use instructions to startand stop the timer.

Solution:

TMOD= 0000 0010 Timer 1 is not used.

Timer 0, mode 2,

C/T = 0 to use XTAL clock source (timer)

gate = 0 to use internal (software)

start and stop method.

timer 1  timer 0

Timer modes

Page 207: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 207/250

Timers /Counters Programming

• The 8051 has 2 timers/counters: timer/counter 0 and

Page 208: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 208/250

timer/counter 1. They can be used as1. The timer is used as a time delay generator.

 – The clock source is the internal crystal frequency of the 8051.

2.  An event counter.

 – External input from input pin to count the number of eventson registers.

 – These clock pulses could represent the number of peoplepassing through an entrance, or the number of wheel rotations,or any other event that can be converted to pulses.

C/T (Clock/Timer)

Page 209: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 209/250

• This bit is used to decide whether thetimer is used as a delay generator or anevent counter.

• C/T = 0 : timer

• C/T = 1 : counter

Registers Used in Timer/Counter

Page 210: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 210/250

• TH0, TL0, TH1, TL1• TMOD (Timer mode register)

• TCON (Timer control register)

• Since 8052 has 3 timers/counters, theformats of these control registers are

different. – T2CON (Timer 2 control register), TH2 and TL2

used for 8052 only.

Basic Registers of the Timer

Page 211: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 211/250

• Both timer 0 and timer 1 are 16 bits wide.

 – These registers stores

• the time delay as a timer

• the number of events as a counter

 – Timer 0: TH0 & TL0

• Timer 0 high byte, timer 0 low byte

 – Timer 1: TH1 & TL1• Timer 1 high byte, timer 1 low byte

 – Each 16-bit timer can be accessed as twoseparate registers of low byte and high byte.

Timer Registers

Page 212: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 212/250

D15 D8D9D10D11D12D13D14 D7 D0D1D2D3D4D5D6

TH0 TL0

D15 D8D9D10D11D12D13D14 D7 D0D1D2D3D4D5D6

TH1 TL1

Timer 0

Timer 1

Power control register

Page 213: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 213/250

Power control

Page 214: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 214/250

• A standard for applications where powerconsumption is critical

• two power reducing modes

 – Idle

 – Power down

Idle mode

•  An instruction that sets PCON.0 causes Idle mode– Last instruction executed before going into the Idle mode

Page 215: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 215/250

 – Last instruction executed before going into the Idle mode

 – the internal CPU clock is gated off  

 – Interrupt, Timer, and Serial Port functions act normally.

 –  All of registers , ports and internal RAM maintain their data duringIdle

 –  ALE and PSEN hold at logic high levels

•  Any interrupt – will cause PCON.0 to be cleared by HW (terminate Idle mode)

 – then execute ISR 

 – with RETI return and execute next instruction after Idle instruction.

• RST signal clears the IDL bit directly

Power-Down Mode 

• An instruction that sets PCON 1 causes power dowm mode

Page 216: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 216/250

•  An instruction that sets PCON.1 causes power dowm mode

• Last instruction executed before going into the power downmode

• the on-chip oscillator is stopped.

• all functions are stopped,the contents of the on-chip RAMand Special Function Registers are maintained.

• The ALE and PSEN output are held low

• The reset that terminates Power Down

Power control example

Page 217: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 217/250

Org 0000hLjmp main

Org 0003h

Orl pcon,#02h ;power down mode 

Reti

Org 0030h

 Main:

…… 

…… 

…… 

Orl pcon,#01h ;Idle mode 

end 

Page 218: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 218/250

BAUD RATE

Saturday, April 06, 2013

Baud Rates in the 8051: 

• Baud rate is the number of signal changes per

Page 219: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 219/250

Saturday, April 06, 2013

second• The 8051 transfers and receives data serially at

many different baud rates by using UART.

• UART divides the machine cycle frequency by 32

and sends it to Timer 1 to set the baud rate.• Signal change for each roll over of timer 1.

XTAL

oscillator ÷ 12

÷ 32

By UART

Machine cycle 

frequency28800 Hz

To timer 1

To set the

Baud rate

921.6 kHz

11.0592 MHz

Timer 1

Page 220: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 220/250

Page 221: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 221/250

Page 222: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 222/250

Interrupts andInterrupt

Programming 

Saturday, April 06, 2013

Interrupts Programming

•  An interrupt  is an external or internal event that

Page 223: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 223/250

interrupts the microcontroller to inform it that a deviceneeds its service.

Interrupts vs. Polling 

•  A single microcontroller can serve several devices. • There are two ways to do that: 

 – interrupts

 – polling.

• The program which is associated with the interrupt iscalled the interrupt service routine (ISR) orinterrupt handler .

Steps in executing an interrupt

• Finish  current instruction and saves the PC on stack.

Page 224: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 224/250

• Jumps to a fixed location in memory depend on type of interrupt

• Starts to execute the interrupt service routine until RETI

(return from interrupt) 

• Upon executing the RETI the microcontroller returns tothe place where it was interrupted. Get pop PC fromstack 

Interrupt Sources

• Original 8051 has 6 sources of

Page 225: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 225/250

Original 8051 has 6 sources of interrupts – Reset – Timer 0 overflow – Timer 1 overflow – External Interrupt 0 – External Interrupt 1 – Serial Port events (buffer full, buffer empty, etc)

• Enhanced version has 22 sources

 – More timers, programmable counter array, ADC, moreexternal interrupts, another serial port (UART)

Interrupt Vectors

Each interrupt has a specific place in code memory where

Page 226: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 226/250

Each interrupt has a specific place in code memory whereprogram execution (interrupt service routine) begins.

External Interrupt 0: 0003h

Timer 0 overflow: 000Bh

External Interrupt 1: 0013h

Timer 1 overflow: 001Bh

Serial : 0023h

Timer 2 overflow(8052+) 002bh

Note: that there are

only 8 memory

locations between

vectors.

  SJMP main

ORG 03H

ISRs and Main Program in8051

Page 227: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 227/250

ljmp int0sr ORG 0BH

ljmp t0sr

ORG 13H

ljmp int1sr 

ORG 1BH

ljmp t1sr 

ORG 23H

ljmp serialsr

ORG 30H

 main:

… 

END

Interrupt Enable (IE) register

All interrupt are disabled after resetWe can enable and disable them bye IE

Page 228: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 228/250

Enabling and disabling aninterrupt

by bit operation

Page 229: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 229/250

Recommended in the middle of programSETB EA ;Enable All

SETB ET0 ;Enable Timer0 ovrf

SETB ET1 ;Enable Timer1 ovrf

SETB EX0 ;Enable INT0

SETB EX1 ;Enable INT1

SETB ES ;Enable Serial port

by mov instructionRecommended in the first of program

 MOV IE, #10010110B

SETB IE.7

SETB IE.1

SETB IE.3

SETB IE.0

SETB IE.2SETB IE.4

Example

• A 10khz square wave with 50% duty cycle

Page 230: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 230/250

ORG 0  ;Reset entry poitLJMP MAIN  ;Jump above interrupt

ORG 000BH  ;Timer 0 interrupt vector

T0ISR:CPL P1.0  ;Toggle port bit

RETI  ;Return from ISR to Main program

ORG 0030H  ;Main Program entry point

 MAIN: MOV TMOD,#02H ;Timer 0, mode 2

 MOV TH0,#-50  ;50 us delay

SETB TR0  ;Start timer

 MOV IE,#82H  ;Enable timer 0 interrupt

SJMP $  ;Do nothing just wait

END

Example

Page 231: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 231/250

• Write a program using interrupts tosimultaneously create 7 kHz and 500 Hzsquare waves on P1.7 and P1.6.

71s143s

1ms

2ms

P1.7

P1.6

8051

143s8051

SolutionORG 0

LJMP MAIN

ORG 000BH

LJMP T0ISR 

ORG 001BH

LJMP T1ISR 

Page 232: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 232/250

71s

1ms

2ms

P1.7

P1.6

ORG 0030H MAIN: MOV TMOD,#12H

 MOV TH0,#-71

SETB TR0

SETB TF1

 MOV IE,#8AH

 MOV IE,#8AHSJMP $

T0ISR: CPL P1.7

RETI

T1ISR: CLR TR1

 MOV TH1,#HIGH(-1000)

 MOV TL1,#LOW(-1000)

SETB TR1CPL P1.6

RETI

END

Timer ISR

Page 233: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 233/250

• Notice that – There is no need for a “CLR TFx” instruction

in timer ISR 

 – 8051 clears the TF internally upon jumping

to ISR 

• Notice that

 – We must reload timer in mode 1

 – There is no need on mode 2 (timer autoreload)

External interrupt type control• By low nibble of Timer control register TCON

• IE0 (IE1): External interrupt 0(1) edge flag.

Page 234: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 234/250

 – set by CPU when external interrupt edge (H-to-L) is detected. – Does not affected by H-to-L while ISR is executed(no int on int)

 – Cleared by CPU when RETI executed.

 – does not latch low-level triggered interrupt

• IT0 (IT1): interrupt 0 (1) type control bit. – Set/cleared by software

 – IT=1 edge trigger

 – IT=0 low-level trigger

TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0

Timer 1 Timer0 for Interrupt

(MSB) (LSB)

External Interrupts

Page 235: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 235/250

IE0

(TCON.3)

0003

INT0

(Pin 3.2) 0

1

2

IT0

Edge-triggered

Level-triggered (default)

IE1

(TCON.3)

INT0

(Pin 3.3) 0

1

2

IT1

Edge-triggered

Level-triggered (default)

0013

Example of external interuuptORG 0000H

LJMP MAIN ;

Page 236: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 236/250

;interrupt service routine (ISR);for hardware external interrupt INT1;

ORG 0013H

SETB P1.1

 MOV R0,200

 WAIT: DJNZ R0,WAIT

CLR P1.1

RETI;

;main program for initialization;

ORG 30H

 MAIN: SETB IT1 ;on negative edge of INT1

  MOV IE,#10000100B

 WAIT2: SJMP WAIT2

END

Example of external interuupt

Page 237: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 237/250

Example of external interuuptOrg 0000h

Ljmp main

Page 238: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 238/250

Org 0003h x0isr: clr p1.7

Reti

Org 0013h

x1isr: setb p1.7

Reti

Org 0030h

 Main: mov ie,#85h

Setb it0

Setb it1

Setb p1.7

Jb p3.2,skip

Clr p1.7

Skip: Sjmp $

end 

Interrupt Priorities• What if two interrupt sources interrupt at the same

time?

Page 239: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 239/250

• The interrupt with the highest PRIORITY gets servicedfirst.

•  All interrupts have a power on default priority order.

1. External interrupt 0 (INT0)2. Timer interrupt0 (TF0)

3. External interrupt 1 (INT1)

4. Timer interrupt1 (TF1)

5. Serial communication (RI+TI)

• Priority can also be set to “high” or “low” by IP reg.

Interrupt Priorities (IP) Register

--- PX0PT0PX1PT1PSPT2---

Page 240: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 240/250

IP.7: reserved

IP.6: reserved

IP.5: timer 2 interrupt priority bit(8052 only)

IP.4: serial port interrupt priority bit

IP.3: timer 1 interrupt priority bit

IP.2: external interrupt 1 priority bit

IP.1: timer 0 interrupt priority bitIP.0: external interrupt 0 priority bit

Interrupt Priorities Example

--- PX0PT0PX1PT1PSPT2---

Page 241: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 241/250

•  MOV IP , #00000100B  or   SETB IP.2 gives priority order 

1. Int1

2. Int0

3. Timer0

4. Timer1

5. Serial

•  MOV IP , #00001100B gives priority order 

1. Int1

2. Timer1

3. Int04. Timer0

5. Serial

Interrupt inside an interrupt

--- PX0PT0PX1PT1PSPT2---

Page 242: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 242/250

A high-priority interrupt can interrupta low-priority interrupy

All interrupt are latched internally

Low-priority interrupt wait until 8051has finished servicing the high-priority interrupt

Interrupts

 mov a, #2

 mov b, #16

Page 243: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 243/250

 mul ab mov R0, a

 mov R1, b

 mov a, #12

 mov b, #20

 mul abadd a, R0

 mov R0, a

 mov a, R1

addc a, b

 mov R1, aend 

P r  o gr  am Ex e  c  u

 t  i   on

interruptISR: inc r7

 mov a,r7

jnz NEXT

cpl P1.6

 NEXT: reti

return

Interrupt Sources

Original 8051 has 5 sources of 

Page 244: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 244/250

• interrupts – Timer 0 overflow

 – Timer 1 overflow

 – External Interrupt 0

 – External Interrupt 1 – Serial Port events (buffer full, buffer empty, etc)

• Enhanced version has 22 sources

 – More timers, programmable counter array, ADC, moreexternal interrupts, another serial port (UART)

Interrupt Process

f fl f h

Page 245: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 245/250

If interrupt event occurs AND interrupt flag for that event isenabled, AND interrupts are enabled, then:

1. Current PC is pushed on stack.

2. Program execution continues at the interrupt vector

address for that interrupt.3. When a RETI instruction is encountered, the PC is

popped from the stack and program executionresumes where it left off.

Interrupt Priorities

h f

Page 246: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 246/250

• What if two interrupt sources interrupt atthe same time?

• The interrupt with the highest PRIORITY 

gets serviced first.• All interrupts have a default priority order.

• Priority can also be set to “high” or “low”. 

Interrupt SFRs

Page 247: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 247/250

Global Interrupt Enable

 – must be set to 1 for anyinterrupt to be enabled

Interrupt enables for the 5 original 8051 interrupts:

Timer 2

Serial (UART0)

Timer 1

External 1

Timer 0External 0

1 = Enable

0 = Disable

Interrupt Vectors

Each interrupt has a specific place in code memory where

ti (i t t i ti ) b i

Page 248: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 248/250

program execution (interrupt service routine) begins.

External Interrupt 0: 0003h

Timer 0 overflow: 000Bh

External Interrupt 1: 0013h

Timer 1 overflow: 001Bh

Serial : 0023h

Timer 2 overflow(8052+) 002bh

Note: that there are

only 8 memory

locations between

vectors.

Interrupt Vectors

To avoid overlapping Interrupt Service routines, it ist t JUMP i t ti t th t dd

Page 249: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 249/250

common to put JUMP instructions at the vector address.This is similar to the reset vector.

org 009B ; at EX7 vector

ljmp EX7ISR

cseg at 0x100 ; at Main program

Main: ... ; Main program

...

EX7ISR:... ; Interrupt service routine

... ; Can go after main program

reti ; and subroutines.

Page 250: Theory Class 1dggfg

8/23/2019 Theory Class 1dggfg

http://slidepdf.com/reader/full/theory-class-1dggfg 250/250