You are on page 1of 89

1

WHY DO WE NEED TO LEARN


MICROPROCESSORS/CONTROLLERS?

The microprocessor is the core of computer systems.


Nowadays many communication, digital
entertainment, portable devices, are controlled by them.
A designer should know what types of components he
needs, ways to reduce production costs and product
reliable.

2
MICROPROCESSOR MICROCONTROLLER

CPU is stand-alone, RAM, CPU, RAM, ROM, I/O and


ROM, I/O, timer are separate timer are all on a single chip

Designer can decide on the Fix amount of on-chip ROM,


amount of ROM, RAM and I/O RAM, I/O ports
ports.

Expansive and versatility For applications in which cost,


power and space are critical

General-purpose Single-purpose

3
THE NECESSARY 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
Parallel Port
4
5
BLOCK DIAGRAM

On-chip ROM
for program On-chip
INTERRUPT code TIMER1
RAM
CONTROLL
TIMER0

CPU

I/O PORT SERIAL PORT


OSC Bus Control

P0 P1 P2 P3 TX RX
Address/Data

6
FEATURES
8-bit CPU optimized for control applications
Supports up to 64K of program memory.
4 K bytes of on-chip program memory.
128 or 256 bytes of on-chip data RAM
Four 8 bit ports.
Two 16-bit timer/counters
UART
Interrupts
On-chip clock oscillator
Full duplex serial data receiver/transmitter
7
Feature 8051 8052 8031

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

RAM (bytes) 128 256 128

Timers 2 3 2

I/O pins 32 32 32

Serial port 1 1 1

Interrupt sources 6 8 6

8
MEMORY MAP

9
ROM MEMORY MAP

10
RAM MEMORY MAP

11
INSTRUCTION SET

Instruction Types
Arithmetic operations
Logical operations
Data transfer instructions
Boolean variable instructions
Program branching instructions

Addressing Modes
Register addressing
Direct addressing
Indirect addressing
Immediate constant addressing
Indexed addressing
12
IMMEDIATE ADDRESSING MODE

Immediate Data is specified in the instruction itself


Egs:
MOV A,#65H
MOV A,#’A’
MOV R6,#65H
MOV DPTR,#2343H
MOV P1,#65H

13
REGISTER ADDRESSING MODE

MOV Rn, A ;n=0,..,7


ADD A, Rn
MOV DPL, R6
DIRECT ADDRESSING MODE

MOV R0, 40H


MOV 56H, A
MOV A, 4 ; ≡ MOV A, R4
MOV 6, 2 ; copy R2 to R6
; MOV R6,R2 is invalid !

14
REGISTER INDIRECT ADDRESSING MODE

In this mode, register is used as a pointer to the data.


MOV A,@Ri
; move content of RAM loc. Where address is held by Ri
into A
( i=0 or 1 )
MOV @R1,B
In other word, the content of register R0 or R1 is sources or
target in MOV, ADD and SUBB insructions.

15
I/O PINS

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.


Ex:P0.0 is the bit 0(LSB)of P0
Ex:P0.7 is the bit 7(MSB)of P0
Each port can be used as input or output (bi-direction).

16
PIN DIAGRAM

P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
P1.2 3 38 P0.1(AD1)
P1.3 4 37 P0.2(AD2)
P1.4 5 36 P0.3(AD3)
P1.5 6 35 P0.4(AD4)
P1.6 7 34 P0.5(AD5)
P1.7 8 33 P0.6(AD6)
RST 9 32 P0.7(AD7)
(RXD)P3.0 10 31 EA/VPP
(TXD)P3.1 11 AT89S52 30 ALE/PROG
(INT0)P3.2 12 29 PSEN
(INT1)P3.3 13 28 P2.7(A15)
(T0)P3.4 14 27 P2.6(A14)
(T1)P3.5 15 26 P2.5(A13)
(WR)P3.6 16 25 P2.4(A12)
(RD)P3.7 17 24 P2.3(A11)
XTAL2 18 23 P2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8)
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):
These 2 pins provide external clock.
Way 1:using a quartz crystal oscillator
Way 2:using a TTL oscillator
Example 4-1 shows the relationship between XTAL and the
machine cycle.

18
RST(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
Way 1:Power-on reset circuit
Way 2:Power-on reset with debounce

19
/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.
“/” means active low.
/PSEN(pin 29):program store enable
This is an output pin and is connected to the OE pin of the
ROM.
See Chapter 14.
20
INTERFACING PUSH BUTTON

 Electrical connection of a push-button key is same as


that of a DIP switch except that the connection is
temporary when the key is pressed.

 When a key is pressed (or released), mechanical


metal contact bounces momentarily as shown in
Figure 9-10 (b) and can be read as multiple inputs.

 The reading of one contact as multiple inputs can be


eliminated by a key-debounce technique, using either
hardware or software.

21
INTERFACING PUSH BUTTON

22
INTERRUPT

Event that disrupts the normal execution of a program and


causes the execution of special instructions.

Program
INTERRUPT

Program
23
INTERRUPT FUNTION

Program Program
Save Restore
Context Context
Interrupt
Service
Routine

time t

24
8051 INTERRUPTS

25
TIMER

 8051 has two 16-bit on-chip timers that can be


used for timing durations or for counting external
events

 The high byte for timer 1 (TH1) is at address 8DH


while the low byte (TL1) is at 8BH

 The high byte for timer 0 (TH0) is at 8CH while


the low byte (TL0) is at 8AH.

 Timer Mode Register (TMOD) is at address 88H 26


TIMER MODES

(Mode 0) – 13-bit mode (not commonly


used)
 (Mode 1) - 16-bit timer mode
(Mode 2) - 8-bit auto-reload mode
(Mode 3) – Split timer mode

27
TIMER 0/TIMER 1 MODE SELECT BITS

TxM1 TxM0 Mode Description

0 0 0 13 bit Counter/Timer

0 1 1 16 bit Counter/Timer

1 0 2 8 bit Counter/Timer with Auto-reload

Timer 1: Inactive
1 1 3
Timer 0: Two 8 bit Counter/Timers

28
TMOD REGISTER

29
TCON REGISTER

30
UART SERIAL COMMUNICATION

COMPUTERS TRANSFER DATA IN TWO WAYS:


Parallel
Often 8 or more lines (wire conductors) are used to transfer
data to a device that is only a few feet away
Serial
To transfer to a device located many meters away, the serial
method is used
The data is sent one bit at a time

31
METHODS OF SERIAL COMMUNICATION

1.Synchronous method transfers a block of data at a time

2.Asynchronous method transfers a single byte at a time


There are special IC chips made by many manufacturers for serial
communications:

UART (universal asynchronous receiver transmitter)


USART (universal synchronous asynchronous receiver
transmitter)
32
SCON

SCON is an 8-bit register used to program the start bit,


stop bit, and data bits of data framing, among other
things.

33
SBUF REGISTER

 SBUF is an 8-bit register used for serial


communication
◦ For a byte data to be transferred via the TxD line, it
must be placed in the SBUF register
 The moment a byte is written into SBUF, it is
framed with the start and stop bits and transferred
serially via the TxD line
◦ SBUF holds the byte of data when it is received by
8051 RxD line
 When the bits are received serially via RxD, the
8051 deframes it by eliminating the stop and start
bits, and then placing the byte in SBUF
34
FRAME FORMAT

35
INTERFACING MATRIX KEYPAD

To recognize and encode the key pressed, the


program should:

Ground all the columns by sending zeros.

Check each key in a row for logic zero.

Ground one column at a time and check all


the rows in that column.

Once a key is identified, it is encoded based


on its position in the column.
36
INTERFACING MATRIX KEYPAD

37
 A liquid crystal display (LCD) is a thin, flat display device
made up of any number of color or monochrome pixels
arrayed in front of a light source or reflector.

 It is often utilized in battery-powered electronic devices


because it uses very small amounts of electric power.
Pin Symbol I/O Description
1 Vss - Ground
2 Vcc - +5V Power supply
3 VEE - Power supply to control Contrast
4 RS | RS = 0 to select command register RS = 1 to select
data register
5 R/W | R/W = 0 for write, R/W = 1 for read
6 E I/O Enable
7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus
15 LED- I Ground for LED backlight
16 LED+ I +5v for LED backlight
VCC,VSS, and VEE
While Vcc and Vss provide +5V and ground, respectively, VEE is used for
controlling LCD contrast.

Rs,register select
There are two very important registers inside the LCD. The RS pin is used
for their selection as follows. If Rs=0, the instruction command code
register is selected, allowing the user to send a command such as clear
display, Cursor at home, etc. If RS=1 the data to be displayed on the LCD
R/W, read/write
R/w input allows the user to write information to the LCd or read
information from it.
R/W=1 when reading ; R/W=0 when writing .
EN
The enable pin is used by the LCD to latch information presented to its
data pins
 The 8 bit data pins, D0-D7 are used to send information to
the LCD or read the contents of the LCDs internal registers.

 To display letters and numbers, we send ASCII codes for the


letters A-Z,a-z, and numbers 0-9 to these pins while making
RS=1.
Hex
1 Clear display screen
2 Return Home
4 Decrement cursor (shift cursor to left)
5 Increment cursor (shift cursor to right)
6 shift display right
7 shift display left
8 Display off, cursor off
A Display off, cursor on
C Display on, cursor off
E Display on, cursor blinking
F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to the beginning of 1st line
C0 Force cursor to the beginning of 2nd line
38 2 lines and 5 x 7 matrix
BLOCK DIAGRAM
 EEPROM (electrically erasable programmable read-only memory) is
user-modifiable read-only memory (ROM) that can be erased and
reprogrammed (written to) repeatedly through the application of higher
than normal electrical voltage. It is a type of non-volatile memory used in
computers and other electronic devices to store small amounts of data
that must be saved when power is removed.

45
46
 I2C is a Master-Slave protocol. I2C has a clock pulse along with the data.
Normally, the master device controls the clock line, SCL. This line
dictates the timing of all transfers on the I2C bus. No data will be
transferred unless the clock is manipulated. All slaves are controlled by
the same clock, SCL.

 The I2C Controller here acts as a master device and controls EEPROM
which acts as a slave. The read-write operations are accomplished by
sending a set of control signals including the address and/or data bits. The
control signals must be accompanied with proper clock signals.

47
 The I2C Controller here acts as a master device and controls EEPROM
which acts as a slave. The read-write operations are accomplished by
sending a set of control signals including the address and/or data bits. The
control signals must be accompanied with proper clock signals.

48
In normal data transfer, the data line only changes state when the clock is low

Change of data
allowed

SDA

SCL

Data line stable;


Data valid

49
SDA
SDA

SCL SCL

Start Stop
Condition Condition

50
After the STOP bit is receive the device internally programs the EEPROM
with the received data byte.
The programming can take up to 10ms (max.). The device will be busy
during this period and will not respond to its slave address.

51
52
 The output of any sensors which deals with physical equality like
temperature, humidity, pressure, viscosity, velocity which are used most
of the data acquisition flat forms are in the form of analog signals or
continuous signals.

 Microcontrollers, microprocessors are do nothing with these signals.


Because they require the signal in the form of binary numbers. So we
should convert these analog signals into digital format. Then here comes
ADC (Analog to digital converters) in picture.
 This ADC converts an analog data into a binary coded data
which can be fed directly to the digital processors. ADC
0804 which is widely used by the digital computing
designers.

 ADC 0804 chip has works on a +5v supply. The fact that
influences while selecting an ADC is its conversion
time. The conversion time is nothing but the time taken by
the ADC to convert an analog data into its respective digital
data or into a binary number.

 This time is depends on the respective digital data or into a


binary number. This time is depends on respective ICs. In
ADC 0804 this time can be controlled by using two external
components resister and capacitor . ADC 0804 chip has some
input signals which can control performance of the
chip. This control signal is sent by the microcontroller
8051.
PINOUT:
• CS – Chip Select , active low
• RD – Read Digital data from ADC, H-L edge triggered
• WR -- Start conversion, L-H pulse edge triggered
• INTR -- end of conversion, Goes low to indicate conversion done
• Data bits -- D0-D7
• CLK IN & CLK R

– CLK IN is an input pin connected to an external clock source when an external


clock is used for timing. However, ADC804 has an internal clock generator.

To use the internal clock generator of the ADC804, the CLK IN and CLK R
pins are connected to a capacitor and a resistor. In that case, the clock
frequency is determined by the equation.

f = 1/1.1RC
R=10K and C=150pF f=606Hz
the conversion time is 110us.
I). Chip Select (CS) :
Chip Select (CS) is an input which activates the ADC 0804 chip. Whenever
ADC 0804 chip is to be function this pin is made low.

ii). Write (WR):


This is a control signal tells ADC chip to start the conversion. This is the active
low input. A low to high going pulse is applied to write pin of ADC chip, chip
starts the conversion. It depends on the input clock (CLKIN) and CLKR
inputs.
iii). CLK IN and CLKR:
These two pins determines the conversion time. When an external clock signal
is applied for the timing CLK IN pin is connected to the external clock signal.
But there is an extra feature in ADC 0804 chip. It has its own internal clock
generator. If one wants to use this internal clock signal CLK IN and ClKR are
connected to resister and capacitor respectively. In this case the clock
frequency is calculated by
f = 1/ 1.1 RC Hz
where R is the resistance value and C is the capacitance value. Normally we use
R=10 kΩ and C=150pF and this value is standardized. We get the frequency as
606KHz and conversion time 110 micro seconds.
iv). Read (RD):
Read is an input signal also called output enable. When the conversion
completes the ADC chip 0804 stores the converted data in its internal
registers. To get this data as output, read (RD) signal is applied. For this
ADC chip RD is an active low signal. When the data is to be read a low
signal is sent to RD pin keeping the CS pin low. The converted 8 bit data is
available on the output pins D0 to D7.

v). Interrupt (INTR) :


Interrupt is an output signal given by the ADC chip. This signal is used as an
input signal to microcontroller normally this signal is at logic high. When the
conversion completes the ADC produces an active low interrupt
signal. When this happens to read the converted data the read signal is to be
applied to ADC 0804 keeping CS signal low.

vi). Vin (+) and Vin(-):


These are two differential analog input. The effective Vin is Vin (+) Vin (-).
Normally analog signal is applied to Vin (+) keeping Vin (-) to ground. Vin
should not be exceeded than + 5V.
vii). Vref/2 :
This is as reference voltage. To vary the range of signal voltage this pin is
used. This pin is kept at a potential deference half of the Vin applied. The
maximum Vin can be applied is + 5V. When Vref/2 pin is kept open ADC
reads to voltage from 0 to 5V.

viii). D0 to D7 :
These are the 8 bit binary output pins of ADC 0804 chip.

ix). VCC :
This is a power supply used for the proper functioning of ADC chip. Normally
this voltage is + 5v.

x). Ground (GND):


There are two ground pins in ADC chip. Analog ground and digital ground.
 Default 0-5V. Can be changed by setting different value for Vref/2 pin.
Vin=Vin(+) – Vin (-)

 Range = 0 to 2x Vref/2.
for Vin = 2x Vref/2. we get 256 as a digital output on D0-D7. (Refer
Table)

 •Step Size a Smallest change


– (2 x Vref/2)/ 256 for ADC804

 for e.g for step size 10mv ,digital output on D0-D7 changes by one count
for every 10mv change of the input analog voltage.
Vref/2 Vin
Step size (mV)
(Volts) (Volts)

Open (2.5) 0 to 5 5/256 = 19.53

2.56 0 to 5.12 5.12/256 =20

1.28 0 to 2.56 2.56/256 = 10

0.5 0 to 1 1/256=3.90
 Data Out
Dout = Vin / Step Size

 for input vtg. of 2.56 volts (Vref=1.28 volts) and stepsize of 10mv Dout
=2560/10 =256 or FF that is full scale output.

 Conversion Time
Greater than 110us for ADC804

 Resolution
8 bits for ADC804
64
INTRODUCTION TO KEIL SOFTWARE

Keil development tools for the 8051 Microcontroller Architecture


support every level of software developer from the professional
applications engineer to the student just learning about embedded
software development.

KEIL IDE is basically an assembler and a compiler or whatever you


name it. You can write either an Assembly or C language code and KEIL
will take care of the rest for you. Furthermore, it supports many of the
8051 variants that you will face.

65
66
67
68
69
70
71
72
73
74
75
77
78
79
80
81
82
SIMULATION
DOWNLOADING
Universal Programmer
87
88
89

You might also like