8051 PPT
8051 PPT
8051 PPT
Operation of stack
push
pop
stack pointer
stack
Internal memory
128 bytes of RAM.
Directly addressable range:
00 to 7F hexadecimal.
Indirectly addressable range:
00 to FF hexadecimal.
Bit addressable space:
20 to 2F hexadecimal .
Four register banks:
00 to 1F hexadecimal.
Internal
Memory
Internal RAM
The 128 byte internal RAM shown in figure
It is organized into three areas.
1.Working register:
Thirty-two bytes from address 00h to 1Fh that make up 32 working register
organized as Four bank of eight bit each.
Bits RS0 and RS1 in the PSW determine which bank of register is currently
Is use.
Bank 0 is selected upon reset
2.Bit addressable:
A bit addressable area of 16 bytes occupies RAM bytes addresses 20h to
2Fh,forming A total of 128 addressable bits.
An addressable bit may be specified by its bit address of 00h to 7Fh.
3.General purpose:
A general-purpose RAM area above the bit area,form 30h to
7Fh,addresable
Internal RAM
Organization
External memory
External memory is used in cases when the internal ROM
and RAM memory Available On chip is not sufficient. Two
separate are made available by the 16-bit PC and the DPTR
and by different control pins for enabling external ROM and
RAM chips.
If the 128 bytes of internal RAM is insufficient, the
external RAM is accessed by the DPTR. In the 8051 family,
external RAM of upto 64 KB can be added to any chip.
Special Function
Register Map
Bit Addressable
F8
F0
E8
E0
ACC
D8
D0
PSW
C8
C0
B8
IP
B0
P3
A8
IE
A0
P2
98
SCON
SBUF
90
P1
88
TCON
TMOD
80
P0
DPL DPH
SP
- ACC : Accumulator.
- B : B register.
- PSW : Program Status Word.
- SP: Stack Pointer.
- DPTR : Data Pointer (DPH, DPL).
Interrupt control:
-IE
: Interrupt Enable.
-IP
: Interrupt Priority.
- P0
: Port 0.
- P1
: Port 1.
- P2
: Port 2.
- P3
: Port 3.
I/O Ports:
- TH0
- TL0
- TH1
- TL1
Serial I/O:
- SCON
- SBUF
- PCON
: Power control
Other:
I/O Ports
- Four 8-bit I/O ports.
Port 0
Port 1
Port 2
Port 3
- Most have alternate functions.
- Quasi-bidirectional:
Port 0
-
Port 1
- Port 1 is a dedicated I/O port from pin 1 to pin 8.
- Upon reset it is configured as outport.
- It is generally used for interfacing to external device
- thus if you need to connect to switches or LEDs, you could make use of
these 8 pins,
- but it doesnt need any pull- up resistors as it is having internally
- As an I/O port: Standard quasi-bidirectional.
Port 2
- Like port 0, port 2 is a dual-purpose port.(Pins 21 through 28)
- It can be used for general I/O or as the high byte of the address bus for
designs with external code memory.
- Like P1 ,Port2 also doesnt require any pull-up resistors
- As an I/O port:
Standard quasi-bidirectional.
- Alternate functions:
High byte of address bus for externalprogram and data memory
accesses.
Port 3
- Port 3 is also dual purpose but designers generally avoid using this
port unnecessarily for I/O because the pins have alternate
functions which are related to special features of the 8051.
- Indiscriminate use of these pins may interfere with the normal
operation of the 8051.
- As an I/O port:
Standard quasi-bidirectional.
- Alternate functions:
Timer/Counters
Two 16-bit up counters, named T0 and T1, are provided for the general use
of the programmer.
Each counter may be programmed to count internal clock pulses, acting as a timer, or programmed to count
external pulses as a counter.
The counters are divided into two 8-bit registers called the timer low (TL0,TL1) and high (TH0,
TH1) bytes.
All counter action is controlled by bit states in the timer mode control register (TMOD), the
timer/counter control register (TCON) and certain program instructions.
TMOD is dedicated to the two timers and can be consider two duplicate 4-bit registers, each of
which controls the action of the timers.
TCON has control bits and flags for the timers in the upper control bits and flags for the external interrupts in the
lower nibble.
Timer/Counters(cont..)
These timers exist in the SFR area as pairs of 8- bit registers.
TL0 (8AH) and TH0 (8CH) for Timer0.
TL1 (8BH) and TH1 (8DH) for Timer1. (LSB is bit 0 ; MSB is bit 7)
Timer/Counters: Block
Schematic
Timer/Counters:
Application
The timers can be used for:
1. Interval timing
The timer is programmed to overflow at a regular interval
and set the timer overflow flag. Overflow means reaching
maximum count of FFFFH.
2. Event counting
Determine the number of occurrences of an event. An
event is any external stimulus that provides a 1-to-0 transition on
a pin of the C.
TMOD
GATE C/T M1 M0 GATE
Timer 1
C/T M1 M0
Timer 0
M0
Mode
Interrupt
System
5 Interrupt Sources (in order of priority):
1 External Interrupt 0 (IE0)
2 Timer 0 (TF0)
3 External Interrupt 1 (IE1)
4 Timer 1 (TF1)
5 Serial Port (RI/TI)
Each interrupt type has a separate vector
address.
Each interrupt type can be programmed
to one of two priority levels.
External interrupts can be programmed
for edge or level sensitivity.
Interrupt vector
Addresses
Source
IE0
TF0
IE1
TF1
RI&TI
Address
03H
0BH
13H
1BH
23H
IE : Interrupt Enable
Register
EA
EX0
- PS
- PT1
- PX1
- PT0
- PX0
: Serial interface.
: Timer 1.
: External interrupt 1.
: Timer 0.
: External interrupt 0.
-
0 = Low priority.
1 = High priority.
Basics of serial
communication
Types of Serial
communications
SM1
TI RI
SM2
REN
TB8
RB8
SM0 , SM1
These two bits of SCON register determine
the framing of data by specifying the
number of bits per character and start bit
and stop bits. There are 4 serial modes.
SM0 SM1
0
0
Serial Mode 0
0
1
Serial Mode 1, 8 bit data,
1 stop bit, 1 start bit
1
0
Serial Mode 2
1
1
Serial Mode 3
REN
REN (Receive Enable) also referred as
SCON.4. When it is high,it allows the
8051 to receive data on the RxD pin.
So to receive and transfer data REN
must be set to 1.When REN=0,the
receiver is disabled. This is achieved
as below
SETB SCON.4
&
CLR SCON.4
TI , RI
TI (Transmit interrupt) is the D1 bit of
SCON register. When 8051 finishes the
transfer of 8-bit character, it raises the TI
flag to indicate that it is ready to transfer
another byte. The TI bit is raised at the
beginning of the stop bit.
RI (Receive interrupt) is the D0 bit of the
SCON register. When the 8051 receives
data serially ,via RxD, it gets rid of the
start and stop bits and places the byte in
the SBUF register. Then it raises the RI flag
bit to indicate that a byte has been
Serial Interface
Full duplex UART.
Four modes of operation:
1.Synchronous serial I/O expansion.
2.Asynchronous serial I/O with variable
baud rate.
3.Nine bit mode with variable baud rate.
4.Nine bit mode with fixed baud rate.
10 or 11 bit frames.
Registers:
SCON - Serial port control register.
SBUF - Read received data.
- Write data to be transmitted.
PCON - SMOD bit.
Multi-Drop
Communication
Serial Communication Modes 2 and 3 allow one "Master" 8051 to control
several "Slaves":
The serial port can be programmed to generate an interrupt if the 9th data bit = 1.
The TXD outputs of the slaves are tied together and to the RXD input of the master. The RXD inputs of the slaves are tied together
and to the TXD ouput of the master.
Each slave is assigned an address. Address bytes transmitted by the master have the 9th bit = 1.
When the master transmits an address byte, all the slaves are interrupted. The slaves then check to see if they
are being addressed or not.
The Addressed slave can then carry out the master's commands.