Professional Documents
Culture Documents
What is a microprocessor?
The microprocessor is the integration of a
number of useful functions.These functions are:
General-purpose microprocessor.
General-
Purpose Serial
RAM ROM I/O Timer
Micro- COM
Port
processor Port
Address Bus
What is Microcontroller?
Microcontroller is a device which integrates a
number of the components of a microprocessor
system onto a single microchip.
So a microcontroller combines onto the same
microchip :
The CPU core
Memory (both ROM and RAM)
Some parallel digital I/O
Example Motorola’s 6811, Intel’s 8051, Zilog’s Z8
and PIC 16X,ATMEL 89S51,52 etc…
Microprocessor vs Micro-controllers
Microprocessors
High end of market where performance matters
High power dissipation–high cost
Need peripheral devices to work
Mostly used in microcomputers.
Microcontollers
Targeted for low end of market where performance
does not matter
Low power dissipation –low cost
Memory plus I/O devices, all integrated into one
chip
Mostly used in embedded systems
Embedded Systems
Features of 8051
ROM - 4K bytes
RAM - 128 bytes
Timer - 2
I/O pins - 32
Serial port - 1
Interrupt sources - 6
CPU
Bus Serial
4 I/O Ports
OSC Control Port
P0 P1 P2 P3 TxD RxD
Address/Data
Registers in 8051
In CPU, registers are used to store information
temporarily. That information could be a byte of data
to be processed, or an address pointing to the data
to be fetched. 8051 have 8-bit registers
D7 D6 D5 D4 D3 D2 D1 D0
MSB LSB
PC
Flag Bit
8051 has a flag register to indicate arithmetic
conditions such as carry bit. The flag register of
8051 is called Program Status Word (PSW) register.
PSW (Program Status Word) Register
1)38h+2Fh=67
0001 1100
+0010 1111
0110 0111
30
2F
Bit-Addressable RAM
20
1F Register Bank 3
18
17
10 Register Bank 2
0F
Register Bank 1(Stack)
08
07
Register Bank 0
00
8051 register banks and stacks
128 bytes of RAM
Address range from 00-7Fh
128bytes are divided into 3 different groups.
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0
P1.2 3 38 P
) 0.1(AD1)
P1.3
P1.4
4
5
8051 37
36
P0.2(AD2
P
) 0.3(AD3)
P1.5 6 (8031) 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 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 P ) 2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8)
The voltage source is +5V.
RST pin 9
C1
XTAL1
30pF
GND
Addressing Modes
The CPU can access data in various ways. The
data could be in a register or in memory or be
provided as an immediate value. These various ways
of accessing data are called addressing modes.
Total 5 addressing modes:
1)Immediate
2)Register
3)Direct
4)Register indirect
5)Indexed
Immediate addressing mode
Ex:
MOV A,#25h ;load 25h into A
Immediate data must be preceded by the pound
sign “#”.
Although DPTR is 16 bit, it can be accessed as two
8-bit registers, DPH and DPL.
Ex:
MOV DPTR, #2550h
is same as,
MOV DPL, #50h
MOV DPH,#25h
Register Addressing Modes
Ex:
MOV A, R0 ;copy contents of R0 into A
Solution
25H
+ 62H
+ 3FH
+ 52H
118H
8-bit datatype.
value range from 0-255(00-FFh).
Signed char
8-bit datatype.
D7 of D7-D0 represent sign(-ve or +ve).
We have 7 bits for value of signed number.
Range from -128 to 127.
Default is signed value.
Unsigned int
16bit datatype.
value in a range of 0-65535.
used to define 16-bit memory address.
8051 is 8-bit microcontroller, so int datatype take
2bytes of RAM.
Signed int
8051 Timers
TH0 TL0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Timer 1 register
Timer 1 is also 16 bit register, and its 16-bit
register is split into two bytes, referred to as
TL1(Timer 1 low byte) and TH1 (Timer 1 high byte).
These registers are accessible in the same way as
Timer 0.
TH1 TH0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
TMOD (Timer mode) register
Solution:
Therefore, we have
TH=EE
TL=00
XTAL TF
/12 TH TL
Oscillator
TR
TF goes high Overflow
C/T=0 When FFFF=0 flag
Mode 0
Its exactly similar to mode1 except that it is a 13 bit
timer instead of 16bit.
Mode 3
Timer mode 3 is a split-timer mode.
D7
Transmitter Receiver
Half Duplex Transmitter
Receiver
Transmitter Receiver
Full Duplex
Receiver Transmitter
Asynchronous serial communication
and data framing
Start and Stop bits
Asynchronous serial communication is widely
used for character-oriented transmission, while
block-oriented data transfer uses synchronous
method.
In asynchronous method, each character is
placed between start and stop bits. This is called
framing.
Start bit is always one bit and it is a low bit
Stop bit can be one or two bits and it is a high bit
stop 0 0 0 1 0 1 0 1 start
space
bit bit
Goes out last D7 D0 Goes out first
Data transfer rate
The rate of data transfer in serial data
communication is stated in bps (bits per second) or
called as baud rate.
Ex: IBM PC could transfer data at rates of 100 to
9600bps.
It must be noted that in asynchronous serial data
communication, the baud rate is generally limited to
100,000bps.
RS232 Standards
To allow compatibility among data communication
equipment made by various manufacturers, an
interfacing standard called RS232 was set by the
Electronics Industries Association (EIA) in 1960.
Many types like RS232A,RS232B,RS232C
This standard is used in PCs and numerous types
of equipment.
This standard was set long before the advent of
TTL logic family, its input & output voltage levels are
not TTL compatible.
9600 -3 FD
4800 -6 FA
2400 -12 F4
1200 -24 E8
19,200 9,600 -3 FD
9,600 4,800 -6 FA
Priority bit =1 assigns high priority. Priority bit=0 assigns low priority
Serial Communication RI + TI 4
VSS = Ground
4.7K
3 2 1 0 4.7K
D0
D1 7 6 5 4
B A 9 8
D2
D3 F E D C
Port 1
(Out)
Row D3 D2 D1 D0
Port 2
(In)
Column
Keypad are the mostly used input devices of the
8051/52.Keypad is organized in a matrix of rows and
columns.
20
VCC
10K 6 Vin (+)
POT 7 18
Vin (-) D0
8 17
A GND D1
16
9 Vref / 2 D2 15
D3 14
CLK R D4 LEDs
19
10K D5 13
4 CLK in D6 12
D7 11
150 pF 1 CS
2
RD WR 3 Normally
10 5
D GND Open
INTR START
Vref / 2 Relation to Vin Range (ADC0804)
Vref / 2 (V) Vin (V) Step size (mV)
D0 – D7 Data out