You are on page 1of 32

8051 MICROCONTROLLER

AND
EMBEDDED SYSTEMS

MICROPROCESSOR VS MICROCONTROLLER

MICROCONTROLLER APPLICATION TREE

CRITERIA CHOOSING A MICROCONTROLLER

Conti..

1.
2.

3.
4.
5.
6.
7.

Wide availability and reliable sources of the microcontroller


The 8051 family has the largest number of diversified
(multiple source) suppliers
Intel (original)
Atmel
Philips/Signetics
AMD
Infineon (formerly Siemens)
Matra
Dallas Semiconductor/Maxim

8051 Family

8051 PROGRAMMING IN C
The reasons for writing programs in C
It is easier and less time consuming to
write in C than Assembly.
C is easier to modify and update
You can use code available in function
libraries.
C code is portable to other microcontroller
with little of no modification.

DATA TYPES
Data Type

Size in bits

Data range/Usage

Unsigned Char

0 to 255

signed Char

-128 to +127

Unsigned int

16

0 to 65535

signed int

16

-32,768 to +32,767

Sbit

SFR bit addressable only

bit

RAM bit addressable only

SFR

RAM addresses 80-FF H


only

TIME DELAY
There are two way s to create a time delay in 8051 C

Using the 8051 timer

Using a simple for loop

be mindful of three factors that can affect the accuracy of the delay

The 8051 design

The number of machine cycle


The number of clock periods per machine cycle

The crystal frequency connected to the X1 X2 input pins

Compiler choice

C compiler converts the C statements and functions to Assembly


language instructions
Different compilers produce different code

Conti

Conti

Conti

LOGIC OPERATIONS
Logical operators
AND (&&), OR (||), and NOT (!)
Bit-wise operators
AND (&), OR (|), EX-OR (^), Inverter (~),
Shift Right (>>), and Shift Left (<<)

Conti

PIN DESCRIPTION

Conti

CONNECTION DIAGRAM

XTAL1 andXTAL2
The 8051 has an on-chip oscillator but requires
an external clock to run it.
1. A quartz crystal oscillator is connected to
inputs XTAL1 (pin19) and XTAL2 (pin18).
2. The quartz crystal oscillator also needs two
capacitors of 30 pF value.

Conti

If you use a frequency source other than a


crystal oscillator, such as a TTL oscillator

1.

It will be connected to XTAL1

2.

XTAL2 is left unconnected

RESET

RESET pin is an input and is active high


(normally low)

Upon applying a high pulse to this pin, the


microcontroller will reset and terminate all activities
This is often referred to as a power-on reset.
Activating a power-on reset will cause all values in the
registers to be lost.

i.
ii.

EA PIN

EA, external access, is an input pin and must be


connected to Vcc or GND
The 8051 family members all come with on-chip ROM to
store programs
-EA pin is connected to Vcc
The 8031 and 8032 family members do no have on-chip
ROM, so code is stored on an external ROM and is
fetched by 8031/32
-EA pin must be connected to GND to indicate that the
code is stored externally

I/O PORT PINS


The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins
All the ports upon RESET are configured as output, ready to
be used as input ports
Port 0

Port 0 is also designated as AD0-AD7, allowing it to be


used for both address and data.

When connecting an 8051/31 to an external memory,


port 0 provides both address and data

ALE indicates if P0 has address or data

When ALE=0, it provides data D0-D7


When ALE=1, it has address A0-A7

Conti

It can be used for input or output , each pin must be


connected externally to a 10K ohm pull-up resistor
This is due to the fact that P0 is an open drain, unlike P1,
P2, and P3
Open drain is a term used for MOS chips in the same way
that open collector is used for TTL chips

PORT 3
Port 3 can be used as input or output.
Port 3 does not need any pull-up resistors.
Port 3 has the additional function of providing
some extremely important signals.

TIMER PROGRAMMING

The 8051 has two timers/counters, they can be used either as


Timers to generate a time delay or as
Event counters to count events happening outside the
microcontroller.
Both Timer 0 and Timer 1 are 16 bits wide
Since 8051 has an 8-bit architecture, each 16-bits timer is accessed
as two separate registers of low byte and high byte.
Accessed as low byte and high byte
The low byte register is called TL0/TL1 and
The high byte register is called TH0/TH1
Accessed like any other register

Conti
Both timers 0 and 1 use the same register, called TMOD
(timer mode), to set the various timer operation modes.
TMOD is a 8-bit register
The lower 4 bits are for Timer 0
The upper 4 bits are for Timer 1
In each case,
I.
The lower 2 bits are used to set the timer mode
II.
The upper 2 bits to specify the operation

Conti

Conti

??????

You might also like