Microcontroller 8051 100110090948 Phpapp02
Microcontroller 8051 100110090948 Phpapp02
Overview
Introduction
Block Diagram and Pin
Description of the 8051
Registers
Memory mapping in 8051
Stack in the 8051
I/O Port Programming
Timers
Interrupts &
Applications
O.K ????
Then What is a
Microcontroller ?
A smaller computer
On-chip RAM, ROM, I/O ports...
Example Motorolas 6811, Intels 8051,
Zilogs Z8 and PIC 16X
CPU
I/O
Port
RAM ROM
Serial
Timer COM
Port
A single chip
Microcontroller
General-purpose microprocessor
CPU for Computers
No RAM, ROM, I/O on CPU chip
itself
Example Intels
x86,
Data Bus
CPU
Motorolas 680x0
GeneralPurpose
Microprocessor
RAM
ROM
Address Bus
I/O
Port
Timer
Serial
COM
Port
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
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
ARM Controllers
Types of Microcontrollers
8-bit
68HC05
68HC08
68HC11
16-bit
68HC12
68HC16
32-bit
683xx
Texas Instruments
TMS370
MSP430
Zilog
Z8
Z86E02
MCS-51 Family of
Microcontollers
Feature
8751
8031
8051
ROM
Eprom
NO
RAM (Bytes)
128
128
256
TIMERS
I/O PINS
32
32
32
32
SERIAL PORTS 1
INTERRUPT
SOURCES
4kB
8052
8kB
4kB UV
128
Microcontroller
Architectures
Memory
Address Bus
CPU
Program
+ Data
Data Bus
2n
Address Bus
CPU
Fetch Bus
Memory
Program
Address Bus 0
Data Bus
Von Neumann
Architecture
Data
Harvard
Architecture
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
Microcontroller
Oscillator
and timing
4096 Bytes
Program Memory
(ROM)
128 Bytes
Data Memory
(RAM)
Two 16 Bit
Timer/Event
Counters
8051
CPU
64 K Byte Bus
Expansion
Control
Programmable
I/O
subsystem interrupts
External interrupts
Control
Parallel ports
Address Data Bus
I/O pins
Programmable
Serial Port Full
Duplex UART
Synchronous Shifter
Serial Output
Serial Input
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.
8051 CPU
Registers
A (8-bit Accumulator)
B (8-bit register for Mul &Div)
PSW (8-bit Program Status Word)
SP (8-bit Stack Pointer)
PC (16-bit Program Counter)
DPTR (16-bit Data Pointer)
List of Registers
(*Denotes the SFRs)
Contd
PSW REGISTER
0000H
8k
0000H
0000H
32k
0FFFH
DS5000-32
8051
1FFFH
from Atmel
Corporation
8752
7FFFH
from Dallas
Semiconductor
30H
2FH
Bit-Addressable RAM
20H
1FH
18H
17H
10H
0FH
08H
07H
00H
Register Bank 3
Register Bank 2
Register Bank 1( Stack)
Register Bank 0
PORTS OF 8051
MOV A, #22
MOV P0 ,A
ACALL DELAY
CPL A
Ports.
Ports contd
Alternate functions of P3
I/O
Port contd
Timers /Counters
Timer/Counter 0
Timer/Counter 1
2.
An event counter.
Timer
P2
P1
TH0
TL0
to
LCD
Counter
a switch
T0
P3.4
to
LCD
Registers Used in
Timer/Counter
TMOD
Register
(MSB)
GATE C/T M1
Timer 1
M0 GATE C/T M1
Timer 0
(LSB)
M0
Gate
TMod contd.
C/T :
M0
0
(x= 0 or 1)
0
1
Mode
0
timer/counter;
Operation
into
TMod contd
Steps of Mode 1
1.
2.
3.
MOV
MOV
TH0,#FFH
TL0,#FCH
4.
MOV TMOD,#01H
CLR TF0
SETB TR0
Mode 1
contd
5. The
TH0-TL0= FFFCH,FFFDH,FFFEH,FFFFH,0000H
TR0=1
Start timer
TH0
TR0=0
TL0
Stop timer
FFFC
FFFD
FFFE
FFFF
0000
TF = 0
TF = 0
TF = 0
TF = 0
TF = 1
TF
Mode 1
6.
7.
8.
9.
contd
When TH0-TL0 rolls over from FFFFH to
0000, the 8051 set TF0=1.
TH0-TL0= FFFE H, FFFF H, 0000 H (Now
TF0=1)
Keep monitoring the timer flag (TF) to see
if it is raised.
AGAIN: JNB TF0, AGAIN
Clear TR0 to stop the process.
CLR TR0
Clear the TF flag for the next round.
CLR TF0
TCON Register
Timer
a 8-bit
register which is bit
addressable and in
which Upper nibble is for
timer/counter,
contd
Tcon
=
=
SETB TCON.4
CLR TCON.4
SETB TF0
CLR TF0
=
=
SETB TCON.5
CLR TCON.5
SETB TR1
CLR TR1
=
=
SETB TCON.6
CLR TCON.6
For timer 1
SETB TF1 =
SETB TCON.7
CLR Timer/Counter
TF1 =
CLR
TCON.7
TCON:
Control
Register
TF1
TR1
TF0
TR0
IE1
IT1
IE0
IT0
HERE
: SETB
P1.0
LCALL DELAY
CLR P1.0
LCALL DELAY
SJMP HERE : Keep doing it
Here same delay is used for both
High & low
Square-wave of 66%duty
cycle.
HERE : SETB P1.0
( Make bit of Port 0 High)
LCALL DELAY
LCALL DELAY
CLR P1.0
LCALL DELAY
SJMP HERE : Keep doing it
Square-wave generation
using Timer
Square wave of 50% duty on P1.5
Timer 0 is used
; each loop is a half clock
MOV TMOD,#01 ;Timer 0,mode 1(16-bit)
HERE: MOV TL0,#0F2H ;Timer value = FFF2H
MOV TH0,#0FFH
CPL P1.5
ACALL DELAY
SJMP HERE
DELAY:
SETB TR0
;start the timer 0
AGAIN: JNB TF0,AGAIN
CLR TR0
;stop timer 0
CLR TF0
;clear timer 0 flag
RET
8051- SERIAL
COMMUNICATION
Basics of serial
communication
Types of Serial
communications
Interfacing to PC
SM0 , SM1
REN, TI, RI
Contd
8051 Interrupts
interrupts &
polling.
Steps in executing an
interrupt
Interrupt Sources
Interrupt
Each interrupt
has a specific place in
Vectors
Interrupt Enable
Register
EA : Global enable/disable.
--: Undefined.
ET2 : Enable Timer 2 interrupt.
ES : Enable Serial port interrupt.
ET1 : Enable Timer 1 interrupt.
EX1 :Enable External 1 interrupt.
ET0 : Enable Timer 0 interrupt.
EX0 : Enable External 0 interrupt .
By bit operation
EA
ET0
ET1
EX0
EX1
ES
SETB
SETB
SETB
SETB
SETB
IE.7
IE.1
IE.3
IE.0
IE.2
SETB
IE.4
;Enable
;Enable
;Enable
;Enable
;Enable
;Enable
By Mov instruction
Recommended in the first of program
MOV IE, #10010110B
All
Timer0 ovrf
Timer1 ovrf
INT0
INT1
Serial port
Interrupt
WhatPriorities
if two interrupt sources interrupt at the
same time?
The interrupt with the highest PRIORITY gets
serviced first.
All interrupts have a power on default priority
order.
1.
2.
3.
4.
5.
---
PT2
PS
PT1
PX1
PT0
IP.7: reserved
IP.6: reserved
IP.5: Timer 2 interrupt priority bit (8052 only)
IP.4: Serial port interrupt priority bit
IP.3: Timer 1 interrupt priority bit
IP.2: External interrupt 1 priority bit
IP.1: Timer 0 interrupt priority bit
IP.0: External interrupt 0 priority bit
PX0
---
PS
MOV IP , #00000100B
priority order
1.
2.
3.
4.
5.
PT2
PT1
PX1
PT0
Int1
Int0
Timer0
Timer1
Serial
Int1
Timer1
Int0
Timer0
Serial
PX0
---
PT2
PS
PT1
PX1
PT0
PX0
Applications of
Microcontrollers
Simple Interfacing
Examples
Seven segment
Interfacing
Recent
Wonders
Recent Wonders
contd ........
Recent Wonders
contd ........
2)
3)
4)
9)
10)
Useful websites
Useful websites
contd
1.
2.
3.
4.
5.
6.
http://www.eg3.com
http://www.ARM.MCU.com
http://www.mcjournal.com
http://www.iar.com
http://
http://www.embedded.com
http://www.powersoftsystems.
com
Epilogue