Professional Documents
Culture Documents
2
MICROPROCESSOR MICROCONTROLLER
General-purpose Single-purpose
3
THE NECESSARY TOOLS FOR A
MICROPROCESSOR/CONTROLLER
On-chip ROM
for program On-chip
INTERRUPT code TIMER1
RAM
CONTROLL
TIMER0
CPU
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)
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
13
REGISTER ADDRESSING MODE
14
REGISTER INDIRECT ADDRESSING MODE
15
I/O PINS
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
21
INTERFACING PUSH BUTTON
22
INTERRUPT
Program
INTERRUPT
Program
23
INTERRUPT FUNTION
Program Program
Save Restore
Context Context
Interrupt
Service
Routine
time t
24
8051 INTERRUPTS
25
TIMER
27
TIMER 0/TIMER 1 MODE SELECT BITS
0 0 0 13 bit Counter/Timer
0 1 1 16 bit Counter/Timer
Timer 1: Inactive
1 1 3
Timer 0: Two 8 bit Counter/Timers
28
TMOD REGISTER
29
TCON REGISTER
30
UART SERIAL COMMUNICATION
31
METHODS OF SERIAL COMMUNICATION
33
SBUF REGISTER
35
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.
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.
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
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.
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.
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.
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.
Range = 0 to 2x Vref/2.
for Vin = 2x Vref/2. we get 256 as a digital output on D0-D7. (Refer
Table)
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)
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
65
66
67
68
69
70
71
72
73
74
75
77
78
79
80
81
82
SIMULATION
DOWNLOADING
Universal Programmer
87
88
89