Embedded Systems
Embedded Systems
Embedded Systems
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION ENGINEERING
EMBEDDED SYSTEMS
8051 Microcontroller 1
Mrs.R.Kiruthikaa,AP/ECE,Karpagam
8051 Microcontroller Institute of Technology 2
DEVELOPMENT OF MICROPROCESSOR
First Generation (1940-1956) Vacuum Tubes
First generation computers relied on machine language
8051 Microcontroller
Mrs.R.Kiruthikaa,AP/ECE,Karpagam Institute of Technology 5
DEVELOPMENT OF MICROPROCESSOR
The first integrated circuit (IC) was developed in the 1950s by Jack Kilby of Texas
Instruments and Robert Noyce of Fairchild Semiconductor.
Accumulato Flag
r s
B C
D E
Timing & Data Lines
Control H L
Unit
Program Counter
Stack Pointer
Microprocessor Microcontroller
CPU is stand-alone, RAM, CPU, RAM, ROM, I/O
ROM, I/O, timer are and timer are all on a
separate single chip
Designer can decide on the Fixed amount of on-chip
amount of ROM, RAM and
I/O ports.
ROM, RAM, I/O ports
Not Expansive
Expansive
Versatility Single-purpose
Advantages:
Speeding up the data transfer rate,
Permits the designer to implement different bus widths
and word sizes for program and data memory space.
0xFF
SFR(direct access)
128 bytes External code memory
ROM or EPROMext
64k
0x80
0x7F
0x30
0x2F
0x20
0x1F Register bank 0(R0-R7)
P2.0 - P2.7 I/O Port 2: Port 2 is an 8-bit bidirectional I/O. Port 2 emits the
high order address byte during fetches from external
program memory and during accesses to external data
memory that use 16 bit addresses.
P3.0 - P3.7 I/O Port 3: Port 3 is an 8 bit bidirectional I/O port. Port 3 also
serves special features as explained.
CPU
Bus Serial
OSC 4 I/O Ports
Control Port
TXD RXD
P0 P1
8051 Microcontroller P2 P3
Mrs.R.Kiruthikaa,AP/ECE,Karpagam In 41
Detailed Block Diagram
8051 Microcontroller 42
Mrs.R.Kiruthikaa,AP/ECE,Karpagam Institute of
8051
Memory Space
External
60K
64K 64K
SFR
EXT INT 4K
128
EA = 0 EA = 1 Internal
Data Memory
Program Memory
8051 Microcontroller Mrs.R.Kiruthikaa,AP/ECE,Karpagam In 44
Internal RAM Structure
Direct
Addressing
Only
SFR [ Special Function
Direct & Registers]
Indirect
Addressing
128 Byte Internal RAM
C AC F0 RS1 RS0 OV F1 P
Carry Parity
Auxiliary Carry User Flag 1
User Flag 0 Register Bank Select Overflow
groups as follows:
1. A total of 32 bytes from locations 00 to 1F BIT Addressable
Area
hex are set aside for register banks and the 128 BYTE
stack. INTERNAL RAM
Reg Bank 3
2. A total of 16 bytes from locations 20H to 2FH
are set aside for bit-addressable read/write Reg Bank 2
memory. Register Banks
Reg Bank 1
3. A total of 80 bytes from locations 30H to 7FH
Reg Bank 0
are used for read and write storage, called
scratch pad.
8051 Microcontroller Mrs.R.Kiruthikaa,AP/ECE,Karpagam In 49
8051 RAM with addresses
Bank 3 R0 R1 R2 R3 R4 R5 R6 R7
Bank 2 R0 R1 R2 R3 R4 R5 R6 R7
Bank 1 R0 R1 R2 R3 R4 R5 R6 R7
Bank 0 R0 R1 R2 R3 R4 R5 R6 R7
1. Immediate
2. Register
3. Direct
4. Register indirect
5. External Direct
PUSH A is invalid.
8051 Microcontroller 74
Mrs.R.Kiruthikaa,AP/ECE,Karpagam Institute of
Multiplication of Unsigned Numbers
MUL AB ; A B, place 16-bit result in B and A
8051 Microcontroller 75
Mrs.R.Kiruthikaa,AP/ECE,Karpagam Institute of
Division of Unsigned Numbers
DIV AB ; divide A by B
8051 Microcontroller 78
Mrs.R.Kiruthikaa,AP/ECE,Karpagam Institute of
Call Instructions
LCALL (long call): 3-byte instruction
◦ 2-byte address
◦ Target address within 64K-byte range
8051 Microcontroller 79
Mrs.R.Kiruthikaa,AP/ECE,Karpagam Institute of Technology
Separate read instructions for external data and code memory.
Internal code
External data memory
Memory
RAM
ROM or EPROM
64k
4k or up
0xFF
SFR(direct access)
128 bytes External code memory
ROM or EPROMext
64k
0x80
0x7F
0x30
0x2F
0x20
0x1F Register bank 0(R0-R7)
T PIN
INTERRUPT
TR
Gate
INT PIN
8051
Microcontroller Mrs.R.Kiruthikaa,AP/ECE,Karpagam Institute of Technology 84
TMOD Register
GATE:
When set, timer/counter x is enabled, if INTx pin is high
and TRx is set.
When cleared, timer/counter x is enabled, if TRx bit set.
C/T*:
When set, counter operation (input from Tx input pin).
When cleared, timer operation (input from internal clock).
Timer 0 Timer 1
Mode 0 Mode 0
Mode 1 Mode 1
Mode 2 Mode 2
Mode 3
T 0 PIN
TR 0 INTERRUPT
Gate
INT 0 PIN
OSC ÷12
C /T 0 TL0 TH0 INTERRUPT
TF0
(5 Bit) (8 Bit)
C /T 1
T 0 PIN
TR 0
Gate
INT 0 PIN
OSC ÷12
C /T 0 TL0 TH0 INTERRUPT
TF0
(8 Bit) (8 Bit)
C /T 1
T 0 PIN
TR 0
Gate
INT 0 PIN
OSC ÷12
C /T 0 TL0 TH0 INTERRUPT
TF0
(8 Bit) (8 Bit)
C /T 1
T 0 PIN
TR 0
Gate Reload
INT 0 PIN
TH0
(8 Bit)
OSC ÷12
C /T 0 TL0 INTERRUPT
TF0
(8 Bit)
C /T 1
T 0 PIN
TR 0
Gate
INT 0 PIN
TR1
8051 Microcontroller Mrs.R.Kiruthikaa,AP/ECE,Karpagam In 93
TIMER 1
OSC ÷12
C /T 0
TL1 TH1 TF1
C /T 1
T 1PIN
INTERRUPT
TR1
Gate
INT 1 PIN
OSC ÷12
C /T 0 TL1 TH1 INTERRUPT
TF1
(5 Bit) (8 Bit)
C /T 1
T 1PIN
TR1
Gate
INT 1 PIN
OSC ÷12
C /T 0 TL1 TH1 INTERRUPT
TF1
(8 Bit) (8 Bit)
C /T 1
T 1PIN
TR1
Gate
INT 1 PIN
OSC ÷12
C /T 0 TL1 TH1 INTERRUPT
TF1
(8 Bit) (8 Bit)
C /T 1
T 1PIN
TR1
Gate Reload
INT 1 PIN
TH1
(8 Bit)
Solution:
The start bit is always one bit, but the stop bit
can be one or two bits
1. SBUF Register
2. SCON Register
3. PCON Register
• We can set it to high by software and thereby double the baud rate.
◦ Timer 0 Overflow.
◦ Timer 1 Overflow.
◦ Reception/Transmission of Serial Character.
◦ External Event 0.
◦ External Event 1.
• EA : Global enable/disable.
• --- : Reserved for additional interrupt hardware.
MOV IE,#08h
• ES : Enable Serial port interrupt.
or • ET1 : Enable Timer 1 control bit.
SETB ET1
• EX1 : Enable External 1 interrupt.
• ET0 : Enable Timer 0 control bit.
• EX0 : Enable External 0 interrupt.
8051 Microcontroller Mrs.R.Kiruthikaa,AP/ECE,Karpagam In 129
Enabling and Disabling an Interrupt
Example: Show the instructions to (a) enable the serial interrupt,
timer 0 interrupt, and external hardware interrupt 1 and (b) disable
(mask) the timer 0 interrupt, then (c) show how to disable all the
interrupts with a single instruction.
Solution:
Serial Port
INT 0 Pin
Timer 1 Pin