8051 Pin Configaration and Architecture
8051 Pin Configaration and Architecture
LERS
8051
Created By: J.Samrajam
Assistant.professor
JNTUHCEH
Pin Description of the 8051
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
P1.2 3 38 P0.1(AD1)
P1.3 4 8051 37 P0.2(AD2)
P1.4 5 36 P0.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 P2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8)
Pin Description
• Pin 1-8(port 1,p1.0 to p1.7): These are 8
pins of port 1. Each of these pins can be
configured as input or output.
• EA(pin 31)
• By applying logic 0 to this pin ,P2 and P3 are
used for data and address transmission with no
regards to whether there is internal memory or
not. Otherwise by applying logic 1bto EA pin,
the microcontroller will use both memories, first
internal and afterwards external (if exists) .
• PSEN(pin 29):program store enable
• If external Rom is used for storing program then
it has logic 0 value every time the
microcontroller reads a byte from memory.
Pins of 8051
4 eight-bit ports
Control register
The first 6 crystal pulses (clock cycle) is used to fetch the Opcode
and the second 6 pulses are used to perform the operation on the
operands in the ALU.
As the CPU fetches the opcode from the program ROM,
the program counter is increasing to point to the next
instruction.
stack pointer
stack
Internal
memory
128 bytes of RAM.
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
as bytes.
Internal RAM
Organization
Sachin Bhalavat
(9409049436)
External
memory
External memory is used in some 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.
Interrupt control:
-IE : Interrupt Enable.
-IP : Interrupt Priority.
I/O Ports:
- P0 : Port 0.
- P1 : Port 1.
- P2 : Port 2.
- P3 : Port 3.
Special Function Register
(SFR)cont..
Timers:
- TMOD : Timer mode.
- TCON : Timer control.
- TH0 : Timer 0 high byte.
- TL0 : Timer 0 low byte.
- TH1 : Timer 1 high byte.
- TL1 : Timer 1 low byte.
Serial I/O:
- SCON : Serial port control.
- SBUF : Serial data registers.
Other:
- PCON : Power control
I/O
Ports
-Four 8-bit I/O ports.
Port 0
Port 1
Port 2
Port 3
- Quasi-bidirectional:
Port 0
- Port 0 is a dual purpose port, it is located from pin 32 to pin 39
(8 pins).
- To use this port as both input/output ports each pin must be connected
externally to pull-up resistor.
- As an I/O port.
- Alternate functions:
As a multiplexed data bus.
8-bit instruction bus, strobed by PSEN. Low
byte of address bus, strobed by ALE. 8-bit
data bus, strobed by WR and RD.
Port 1
-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 doesn’t 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:
Serial I/O - TXD, RXD
Timer clocks - T0, T1
Interrupts - INT0, INT1
Data memory- RD, WR
I/O Port
structure
The internal circuitry for the I/O port is shown in
the figure
If you want to read in from a pin, you must first
give a logic ‘1’ to the port latch to turn off the
FET otherwise the data read in will always be
logic ‘0’.
When you write to the port you are actually
writing to the latch e.g. a logic 0 given to the
latch will be inverted and turn on the FET
which cause the port pin to be connected to
I/O Port structure
Diagram
Sachin Bhalavat
(9409049436)
Timer/Counte
rs
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(con
t..)
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)
The pins must be held high for one complete machine cycle and then
low for one complete machine cycle.
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.
TCON (Counter/Timer Control
Register)
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
Timer 1 Timer 0
M1 M0 Mode
0 0 0
0 1 1
1 0 2
1 1 3
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.
- 0 = Disabled.
- 1 = Enabled.
IP: Interrupt Priority
Register
----- ----- ----- PS PT1 PX1 PT0 PX0
- PS : Serial interface.
- PT1 : Timer 1.
- PX1 : External interrupt 1.
- PT0 : Timer 0.
- PX0 : External interrupt 0.
- 0 = Low priority.
- 1 = High priority.
Basics of serial
communication
Types of Serial
communications
RxD and TxD pins in the
8051
The 8051 has two pins for transferring and
receiving data by serial communication.
These two pins are part of the Port3(P3.0
&P3.1)
These pins are TTL compatible and hence
they require a line driver to make them
RS232 compatible
Serial communication is controlled by an 8-
bit register called SCON register, it is a bit
addressable register.
SCON : Serial Control
Register
SMO SM1 SM2 REN TB8 RB8 TI RI
Mode 0:
Shift Register Mode. Serial data is transmitted/received on
RXD. TXD outputs shift clock. Baud Rate is 1/12 of clock
frequency.
Mode 1:
10-bits transmitted or received. Start (0), 8 data bits (LSB
first), and a stop bit (1). Baud Rate Clock is variable using
Timer 1 overflow or external count input. Can go up to
104.2KHz (20MHz osc.).
Serial Interface
Modes of
Operation(cont..)
Mode 2:
11-bits transmitted or received. Start (0), 8 data bits
(LSB first), programmable 9th bit, and stop bit (1).
Baud Rate programmable to either 1/32 or 1/64
oscillator frequency (625KHz for 20MHz osc.).
Mode 3:
11-bit mode. Baud Rate variable using Timer 1
overflow or external input. 104.2 KHz max. (20 MHz
osc.).
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.
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.