8051 basics

Post on 20-Mar-2017

441 Views

Category:

Education

2 Downloads

Preview:

Click to see full reader

Transcript

8051 microcontroller

Vishnu chittan.M

What is an Embedded System? Application-specific systems which contain hardware and

software tailored for a particular task and are generally part

of a larger system.

Characteristics

Are dedicated to a particular application.

Include processors dedicated to specific functions.

Represent a subset of reactive (responsive to external

inputs) systems.

Contain real-time constraints.

Embedded Systems Applications

Aerospace Navigation systems, automatic landing systems, flight attitude controls, engine controls, space exploration (e.g.. The mars pathfinder)

Automotive Fuel injection control, passenger environmental controls, anti-locking braking systems, air bag controls, GPS mapping, cruise control

Children's toys Video games, MindStone system

Communication

Satellites, network routers, switches, hubs

Computer Peripherals

Printers, scanners, keyboards, displays, modems, hard disk drives, CD-ROM drives, USB

Home Dishwashers, microwave ovens, VCR’s, DVD, televisions, stereos, fire/security alarm systems, lawn sprinkler controls, thermostats, digital cameras, clock radios, cell phones

Industrial Elevator controls, surveillance systems, robots

Instrumentation Data collection, oscilloscopes, signal generators, signal analyzers, power supplies

Embedded Systems Applications

Medical CT, One touch glucose meter, almost all medical facility

Office Automation

FAX machines, copiers, telephones,

Personal PDA’s, pagers, cell phones, video games, Ipod, MP3 players

Embedded Systems Applications

Essential ComponentsEssential components :-

- Microcontroller / DSP core

- Sensors

- Converter ( A-D and D-A )

- Actuators

- Memory (on-chip and off-chip )

- Communication path with interfacing

environment

Why do we need to learn Microcontrollers ?

• Its not an exaggeration if I say that ,today there is no

electronic gadget on the earth which is designed without a

Microcontroller. Ex: communication devices, digital

entertainment, portable devices etc…

Not believable ??? See the next slide

• Personal information products: Cell phone, pager, watch, pocket

recorder, calculator

• Laptop components: mouse, keyboard, modem, fax card, sound

card, battery charger

• Home appliances: door lock, alarm clock, thermostat, air

conditioner, TV remote, VCR, small refrigerator, exercise

equipment, washer/dryer, microwave oven

• Industrial equipment: Temperature/pressure controllers,

Counters, timers, RPM Controllers

• Toys: video games, cars, dolls, etc.

So, A good designer should always know what type of controller he/she is using ,their architecture, advantages , disadvantages , ways to reduce production costs and product reliability etc….

Then What is a Microcontroller ? • A smaller computer

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

• Example : Motorola’s 6811, Intel’s 8051, Zilog’s Z8 and PIC

16X

RAM ROM

I/O Port

TimerSerial COM Port

CPU

A single chip Microcontroller

How is it different from a Microprocessor ??

CPU for ComputersNo RAM, ROM, I/O on CPU chip itself

Example: Intel’s x86, Motorola’s 680x0

CPU

General-Purpose Micro-processor

RAM ROM I/O Port

TimerSerial COM Port

Data Bus

Address Bus

Microprocessor CPU is stand-alone, RAM,

ROM, I/O, timer are separate designer can decide on the

amount of ROM, RAM and I/O ports.

expansive versatility general-purpose

Microcontroller• CPU, RAM, ROM, I/O and

timer are all on a single chip• fix amount of on-chip ROM,

RAM, I/O ports• Highly bit addressable• for applications in which cost,

power and space are critical• single-purpose

Microprocessor vs. Microcontroller

EVOLUTION Flashback !!!!

In the year 1976, Motorola created a Microprocessor chip called 6801 which replaced its brother 6800 with certain add-on chips to make a computer. This paved the way for the new revolution in the history of chip design and gave birth to a new entity called

MICROCONTROLLER.

The INTEL bagged the credit of producing the first Microcontroller 8048 with a CPU and 1K bytes of EPROM, 64 Bytes of RAM an 8-Bit Timer and 27 I/O pins in 1976.

Evolution contd…• Then followed the most popular controller 8051 in the year

1980 with 4K bytes of ROM,128 Bytes of RAM , a serial port, two 16-bit Timers , and 32 I/O pins.

• The 8051 family has many additions and improvements over the years and remains a most soughtafter tool for todays circuit designers.

• The same INTEL introduced a 16 bit controller 8096 in the year 1982

• Later INTEL introduced 80c196 series of 16-bit microcontrollers for mainly industrial applications

• Microchip, another company has introduced a microcontroller PIC 16C64 an 8-bit in the year 1985.

• 32-bit microcontrollers have been developed by IBM and Motorola-MPC 505 is a 32-bit RISC controller of Motorola

• The 403 GA is a 32 -bit RISC embedded controller of IBM

ARM Controllers• In recent times ARM company (Advanced Risc machines)

has developed and introduced 32 bit controllers which are highend application devices,especially communication devices like mobiles , ipods etc..(Refer www.arm.com)

Types of Microcontrollers

Microcontrollers from different manufacturers

•Atmel •ARM •Intel

• 8-bit • 8XC42 • MCS48 • MCS51 • 8xC251

• 16-bit • MCS96 • MXS296

•National Semiconductor • COP8

•Microchip • 12-bit instruction PIC • 14-bit instruction PIC

• PIC16F84 • 16-bit instruction PIC

•NEC

•Motorola • 8-bit

• 68HC05 • 68HC08 • 68HC11

• 16-bit • 68HC12 • 68HC16

• 32-bit • 683xx

•Texas Instruments • TMS370 • MSP430

•Zilog • Z8 • Z86E02

MCS-51 “Family” of MicrocontollersFeature 8031 8051 8052 8751 ROM NO 4kB 8kB 4kB UV

Eprom

RAM (Bytes) 128 128 256 128

TIMERS 2 2 3 2

I/O PINS 32 32 32 32

SERIAL PORTS 1 1 1 1

INTERRUPT 6 6 8 6 SOURCES

Microcontroller Architectures

CPUProgram + Data

Address Bus

Data Bus

Memory

Von NeumannArchitecture

CPUProgram

Address Bus

Data Bus

HarvardArchitecture

Memory

Data

Address Bus

Fetch Bus

0

0

0

2n

Important Features of 8051

•4K bytes ROM•128 bytes RAM•Four 8-bit I/O ports•Two 16-bit timers•Serial interface•64K external code memory space•64K data memory space

“Original” 8051 MicrocontrollerOscillator and timing

4096 Bytes Program Memory

(ROM)

128 BytesData Memory

(RAM)

Two 16 Bit Timer/Event

Counters

8051 CPU

64 K Byte Bus Expansion

Control

Programmable I/O

Programmable Serial Port Full Duplex UART

Synchronous Shifter

Internal data bus

External interrupts

subsystem interrupts

Control Parallel portsAddress Data BusI/O pins

Serial InputSerial Output

Pin Description of the 8051

• The 8051 is a 40 pin device, but out of these 40 pins, 32 are used for I/O.

• 24 of these are dual purpose, i.e. they can operate as I/O or a control line or as part of address or date bus.

24

Inside Architecture of 8051

CPU

On-chip RAM

On-chip ROM for program code

4 I/O Ports

Timer 0

Serial Port

Inside the 8051 Microcontroller Block Diagram

OSC

Interrupt Control

External interrupts

Timer 1

Timer/Counter

Bus Control

TxD RxDP0 P1 P2 P3

Address/Data

Counter Inputs

Microcontroller Packaging and Appearance

25

26

Three criteria in Choosing a Microcontroller

Meeting the computing needs of the task efficiently and cost

effectively.

• Speed, the amount of ROM and RAM, the number of I/O

ports and timers, size, packaging, power consumption.

• Easy to upgrade.

• Cost per unit.

Availability of software development tools.

• Assemblers, debuggers, C compilers, emulator, simulator,

technical support.

Wide availability and reliable sources of the microcontrollers.

27

28

A Pin on Port 1

D Q

Ck Q

VccLoad (L1)

Read latch

Read pin

Write to latch

Internal CPU bus

M1

P1.X pinP1.X

TB1

TB2

29

A Pin of Port 0

D Q

Clk Q

Read latch

Read pin

Write to latch

Internal CPU bus

M1

P0.X pinP0.X

TB1

TB2

30

Memory mapping in 8051 ROM memory map in 8051 family

0000H

0FFFH

0000H

1FFFH

0000H

7FFFH

8751AT89C51 8752

AT89C52

4k

DS5000-32

8k 32k

from Atmel Corporationfrom Dallas Semiconductor

31

221-Introduction to Embedded C

32

Advantages It is a ‘mid-level’, with ‘high-level’ features (such as

support for functions and modules), and ‘low-level’

features (such as good access to hardware via

pointers) C is the most common Embedded language 85%, of

embedded applications are coded in C. It directly manipulates the hardware and memory

addresses. Cx51 Cross compiler supports all of the ANSI Standard

C directives.

33

Data Types Data types Bits Bytes Value range • Bit 1 0 to 1• Signed char 8 1 -128 to +127• Unsigned char 8 1 0 to 255• Signed short 16 2 -32768 to +32767 • Unsigned short 16 2 0 to 65535• Signed int 16 2 -32768 to +32767 • Unsigned int 16 2 0 to 65535• Signed long 32 4 -2147483648 to

2147483647 • Unsigned long 32 4 0 to 4294967295• Float 32 4 ±1.175494E-38 to

±3.402823E+38 • sbit 1 0 to 1 • sfr 8 1 0 to 255

34

8051 Memory Areas

• The 8051 architecture supports a number of

physically separate memory areas for program and

data. Each memory area offers certain advantages and

disadvantages.

Program Memory code Internal Data memory bdata, data,

idata External Data memory xdata, pdata

35

code: Program memory (64 Kbytes); accessed by opcode

MOVC A, @A+DPTR.

data: Directly addressable internal data memory; fastest

access to full internal address space (256 bytes).

idata: Indirectly addressable internal data memory; accessed

across the internal address space (128 bytes).

bdata: Bit-addressable internal data memory; allows mixed

bit and byte access (16 bytes).

xdata: External data memory (64 Kbytes); accessed by

opcode

MOVX @DPTR. pdata: Paged (256 bytes) external data memory; accessed

by

opcode . MOVX @Rn.

Explicitly declared Memory types

36

Memory models The memory model determines which default memory

type to use for automatic variables, and declarations with

no explicit memory type specifier. If the memory type specifier is omitted in a variable

declaration, the default or implicit memory type is

automatically selected. Automatic variables which cannot be located in registers

are also stored in the default memory area. The default memory type is determined by the SMALL,

COMPACT and LARGE compiler control directives.

37

Small Model: Internal RAM 128 bytes

All variables, by default, reside in the internal data

memory of the 8051 system. It is the same as if they were declared explicitly using the

data memory --type specifier. Variable access is very efficient. Stack size is critical

because the real stack size depends upon the nesting

depth of the various functions. Using this memory model, the number of global variables

must be kept to a minimum to allow. However the amount

of space required for the stack must be kept in mind.

38

Compact Model: RAM 256 bytes off-chip All variables, by default, reside in one page of external

data memory. It is as if they were explicitly declared using the pdata

memory type specifier. This memory model can

accommodate a maximum of 256 bytes of variables.

The limitation is due to the addressing scheme used,

which is indirect through registers R0 and R1 (@R0,

@R1.

39

Compact Model: RAM 256 bytes off-chip The compact model is rarely used for an entire

program, but more usual in combination with the SMALL switch

reserved for interrupt routines. COMPACT is especially useful for programs with

a large number of medium speed 8 bit variables.

40

Large Model: Total RAM up to 64KB

In this model, all variables, by default, reside in external

data memory (up to 64 Kbytes). It is the same as if they were explicitly declared using

the xdata memory type specifier. Memory access through this data pointer is inefficient,

especially on variables with a length of two or more

bytes. This type of data access mechanism generates more

code than the small or compact models, Permits slow

access to a very large memory space .

Interfacing Dip Switches and Interfacing LEDs

(a)

(b)

Interfacing Push-Button Keys

What is a Keypad ? Collection of keys interfaced

to the microcontroller

Arranged in the form of two

dimensional matrix

Matrix arrangement used for

minimizing the number of

port lines

Junction of each row and

column forms the key

Interfacing a Keyboard

Applications of Microcontrollers

Simple Interfacing Examples

Seven segment Interfacing

Traffic light controller

Closed loop control system-Temperature control example

Home automation system

Single Axis solar tracking system

top related