Documente Academic
Documente Profesional
Documente Cultură
8051
P1.2 3 38 P0.1(AD1)
P1.3 4 37 P0.2(AD2)
PIN
P1.4 5 36 P0.3(AD3)
P1.5 6 35 P0.4(AD4)
DESCRIPTION
P1.6 7 34 P0.5(AD5)
P1.7 8 8051 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)
Pins of 8051
Vcc(pin 40):
Vcc provides supply voltage to the chip.
The voltage source is +5V.
GND(pin 20):ground
XTAL1 and XTAL2(pins 19,18):
These 2 pins provide external clock.
RST(pin 9):reset
It is an input pin and is active high(normally low).
Upon applying a high pulse to RST, the microcontroller will
reset and all values in registers will be lost.
16 bit register made of two 8 bit register called DPH (High) and DPL (low).
It is an index register that provide access to external memory.
DPH and DPL hold the higher order byte and lower order byte of the
address.
DPH and DPL are assigned internal address separately (DPH:83H and
DPL:82H)
A and B register
These two registers hold the result of many arithmetic and logical operation
of the CPU.
The Accumulator (A) is used in many operations including addition,
subtraction, integer multiplication and division.
It is bit addressable register.
It is also used for all data transfer between 8051 and external memory.
Register B may be used as a location where data may be stored.
It is also used with register A for multiplication and division operation and
has no other function.
PROGRAM STATUS WORD(PSW)
8 bit register
Also referred to as flag register.
It indicates certain condition like status of carry, parity sign etc after
execution of some instruction
Internal Memory
8051 has internal ROM and RAM .
Aditionary memory can be added externally using suitable circuits.
8051 has a Hardvard architecture, which uses same address in different
memories for code and data.
Internal RAM
STACK AND STACK POINTER
pop
push
stack pointer
stack
Special Function Registers
The 8051 operations that do not use the internal 128 byte internal RAM
address from 00H to 7FH are done by a group of specific internal registers,
each called as Special Function Registers (SFR),
Which may be addressed much like internal RAM, using addresses 80H to
FFH.
Internal ROM
Data and program code memory can be in two entirely different physical
memory entities.
Each has the same address range
A block of internal program code contained in a internal ROM occupies
code address space 0000h to 0FFFh.
PC is used to address from 0000h-FFFFh.
Program address higher than 0FFFh – will cause 8051 to fetch code bytes
from external program memory.
/EA to ground cause to fetch from external memory address 0000h-FFFFh.
Input/Output Pins, Ports and Circuits
Each port has a D type output latch for each pin.
The SFR for each port is made up of these eight latches.
It can be addressed at the SFR address for that port.
Eight latches for port 0 are addressed at location 80h.
Port 0 pin 3 is bit 2 of the P0 SFR.
Port 0 Pin Configurations
Port 1Pin Configurations
Port 2 Pin Configurations
Port 3 Pin Configurations
External memory
TCON Register:
7/23/2019
Timers and Counters
Timer Modes of operation
Timer 0 Mode 0
Timer 0 Mode 1
Timer 0 Mode 2
Timer 0 Mode 3
Interrupts
An interrupt is an external or internal event that interrupts the
microcontroller to inform it that a device needs its service.
72
Main program (base level, foreground)
Interrupt ISR
ISR ISR
level execution
Starts to execute the interrupt service routine until RETI (return from
interrupt)
Upon executing the RETI the microcontroller returns to the place where
it was interrupted. Get pop PC from stack
Interrupt Priorities
What 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. External interrupt 0 (INT0)
2. Timer interrupt0 (TF0)
3. External interrupt 1 (INT1)
4. Timer interrupt1 (TF1)
5. Serial communication (RI+TI)
Priority can also be set to “high” or “low” by IP reg.
Registers associated with interrupts
EA : Global enable/disable.
--- : Undefined.
ET2 :Enable Timer 2 interrupt. (in 8052)
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.
7/23/2019
Interrupt Priority Register :
7/23/2019
Basics of serial communication
Parallel: expensive - short distance – fast
Serial :cheaper– long (two different cities by modem)-slow
Basics of serial communication
Start and stop bits
When there is no transfer the signal is high
Transmission begins with a start (low) bit
LSB first
Finally 1 stop bit (high)
Data transfer rate (baud rate) is stated in bps
bps: bit per second
Registers associated with serial
communication
Serial Port Control (SCON)
Power Mode Control (PCON)
SBUF
Serial Communication & SFR
SM0 & SM1 : Mode bits : Mode 0: Shift Register; baud =f/12
SM0 Mode
SM12: 9 SM2
bit UART;REN
baud =f/32
TB8 or RB8
f/64 TI RI
Mode 3: 9 bit UART; baud=variable
SM2: Multiprocessor communication bit, set/cleared by program
REN: Receive enable bit
TB8: Transmitted bit in mode 2 and 3
RB8: Received bit in mode 2 and 3, stop bit in mode 1,
TI: Transmit interrupt flag, set by hardware. To be cleared by program
RI: Receive interrupt flag
7/23/2019
Power Control SFR
PCON SFR:
SMOD -- -- -- GF1 GF0 PD IDL
7/23/2019