Friday, April 20, 2012
Friday, April 20, 2012
Block Diagram
External interrupts Interrupt Control On-chip ROM for program code
Timer/Counter
On-chip RAM
Timer 1 Timer 0
Counter Inputs
CPU
Serial Port
OSC
Bus Control
4 I/O Ports
P0 P1 P2 P3
TxD RxD
Address/Data
Friday, April 20, 2012
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
8051 (8031)
40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
Vcc P0.0(AD0) P0.1(AD1) P0.2(AD2) P0.3(AD3) P0.4(AD4) P0.5(AD5) P0.6(AD6) P0.7(AD7) EA/VPP ALE/PROG PSEN P2.7(A15) P2.6(A14) P2.5(A13) P2.4(A12) P2.3(A11) P2.2(A10) P2.1(A9) P2.0(A8)
Pins of 80511/4
Vccpin 40 Vcc provides supply voltage to the chip. The voltage source is +5V. GNDpin 20ground XTAL1 and XTAL2pins 19,18 These 2 pins provide external clock. Way 1using a quartz crystal oscillator Way 2using a TTL oscillator Example 4-1 shows the relationship between XTAL and the machine cycle.
Pins of 80512/4
RSTpin 9reset It is an input pin and is active highnormally low. The high pulse must be high at least 2 machine cycles. It is a power-on reset. Upon applying a high pulse to RST, the microcontroller will reset and all values in registers will be lost. Reset values of some 8051 registers Way 1Power-on reset circuit Way 2Power-on reset with debounce
Pins of 80513/4
EApin 31external access There is no on-chip ROM in 8031 and 8032 . The EA pin is connected to GND to indicate the code is stored externally. PSEN ALE are used for external ROM. For 8051, EA pin is connected to Vcc. PSENpin 29program store enable This is an output pin and is connected to the OE pin of the ROM.
Friday, April 20, 2012
Pins of 80514/4
ALEpin 30address latch enable It is an output pin and is active high. 8051 port 0 provides both address and data. The ALE pin is used for de-multiplexing the address and data by connecting to the G pin of the 74LS373 latch. I/O port pins The four ports P0, P1, P2, and P3. Each port uses 8 pins. All I/O pins are bi-directional.
XTAL2
XTAL1
GND
Example :
Find the machine cycle for (a) XTAL = 11.0592 MHz (b) XTAL = 16 MHz. Solution:
(a) 11.0592 MHz / 12 = 921.6 kHz; machine cycle = 1 / 921.6 kHz = 1.085 s (b) 16 MHz / 12 = 1.333 MHz; machine cycle = 1 / 1.333 MHz = 0.75 s
19
31 10 uF 30 pF
EA/VPP X1
X2 RST 9 8.2 K
Port 0
Port 0 occupies a total of 8 pins(32-39) It can be used as input/output port. Each pin must be connected externally to 10 K pull-up resistor. This is due to fact the P0 is an open drain. Port 0 as an output port
With external pull-up resistors connected upon reset, Port 0 is configured as an output port.
Friday, April 20, 2012
Port 0
Port 0 as an input port
With the resistors connected to the port 0, in order to make it an input, the port must be programmed by writing 1 to all the bits. Initialization
MOV A,#0FFh MOV P0, A Or MOV P0,# 0FFh Or SETB P0.1 To make P0.1 as input port.
Friday, April 20, 2012
Port 1
Port 1 occupies a total 8 pins. It can be used as an Input/Output port. This port does not required any external pull-up resistor. Since it has already internal pull-up. Upon reset the Port 1 will be configured as output port. To make it has an input port, It must be programmed as such by writing 1 to all its bits.
MOV A,#0FF H MOV P1,A
Friday, April 20, 2012
Port 2
Port 2 occupies a total of 8 pins (pin 21 thru 28). It can be used as an input or output port. It does not required external pull-up since it has already internal pull-up. Upon reset, Port 2 is configured as an output port. To make port 2 has an input port, it must be programmed by writing 1 to all its bits.
MOV A,#0FF H MOV P2,A
Friday, April 20, 2012
Function
RxD TxD INT0 INT1 T0 T1 WR RD
Pin
10 11 12 13 14 15 16 17
Example: Write a program to get the x value from P1 and send x2 to P2, continuously . Solution: ORG 0 MOV DPTR, #TAB1 MOV A,#0FFH MOV P1,A L01: MOV A,P1 MOVC A,@A+DPTR MOV P2,A SJMP L01 ;---------------------------------------------------ORG 300H TAB1: DB 0,1,4,9,16,25,36,49,64,81 END
Port 1 is denoted by P1. P1.0 ~ P1.7 We use P1 as examples to show the operations on ports. P1 as an output port (i.e., write CPU data to the external pin) P1 as an input port (i.e., read pin data into CPU bus)
A Pin of Port 0
Read latch
TB2
P1.X
Clk Q
P0.X pin M1
P1.x
8051 IC
P0.0 DS5000 P0.1 P0.2 8751 P0.3 P0.4 8951 P0.5 P0.6 P0.7
Port 0
A Pin of Port 1
Read latch
TB2
Vcc
Load(L1)
P1.X
Clk Q
P1.X pin M1
P0.x
8051 IC
2 Tri-state buffer
TB1: controlled by Read pin
Read pin1really read the data present at the pin
A transistor M1 gate
Gate=0: open Gate=1: close
Friday, April 20, 2012
Tri-state Buffer
Output Input
Low
Highimpedance (open-circuit)
Vcc
Load(L1) 2. output pin is
Vcc 1 0
M1
P1.X
Clk Q
P1.X pin
output 1
8051 IC
Vcc
Load(L1) 2. output pin is
ground 0 1
M1
P1.X
Clk Q
P1.X pin
output 0
8051 IC
BACK:
Vcc
Q
P1.X
P1.X pin
Write to latch
Clk
M1
TB1 Read pin 3. Read pin=1 Read latch=0 Write to latch=1 8051 IC Friday, April 20, 2012
Vcc
Q
P1.X
P1.X pin
Write to latch
Clk
M1
TB1 Read pin 3. Read pin=1 Read latch=0 Write to latch=1 8051 IC Friday, April 20, 2012
BACK:
Description Bring into A the data at P2 pins Jump if pin P2.1 is low Jump if pin P1.3 is high Copy status of pin P2.4 to CY