microcontroller intel 8051 [i/o ports]. pin out of the 8051 –40 pin package –32 pins are used...

42
Microcontroller Intel 8051 [I/O Ports]

Upload: delilah-stevens

Post on 18-Jan-2016

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Microcontroller Intel 8051

[I/O Ports]

Page 2: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Pin out of the 8051– 40 pin package

– 32 pins are used for the 4 ports.– VCC / VSS

– ALE• Address Latch Enable

– EA / VPP

• External Address• Program Voltage for EPROM

based versions of the 8051.– XTAL1 and XTAL2

• Connections for clock crystal.– PSEN

• “Program Store Enable”– Read signal for external

program memory– RST

• Reset

Page 3: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

I/O Ports

• The 8051 has 4 bidirectional 8-bit I/O ports.– Each port is connected to an 8-bit register in the SFR.

• P0 = 80H, P1 = 90H, P2 = A0H, P3 = B0H– Each port is also connected to an output driver and an input

buffer.– All ports are configured for output at reset.

• Some of the 4 ports have uses in addition to simple I/O.– Ports P0 and P2 double as the 8051’s Address and Data

busses.– Port P3 doubles as the 8051’s external control lines for the

timers and counters.

Page 4: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Port P0

• P0 can be used for input or output.• The pins of P0 are connected internally to an “open

drain” circuit (similar to open collector but using MOS transistors).– Therefore, it must be connected to an external pull-up

resistor (10 K) to operate properly as an output port.

• To operate P0 as aninput port, it must beprogrammed by writing 1’s to all of itsbits

Page 5: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Port 0 with Pull-Up Resistors

Page 6: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Dual Role of P0

• P0 is also designated as AD0 – AD7 which means that it also doubles as the multiplexed lower 8 bits of the address bus and the 8 bits of the data bus.

• P0 will be used in this manner when accessing external memory.

• Program or data.

– ALE is used to differentiate when the pins are carrying an address vs. data.

• ALE = 1 when the pins carry an address and 0 otherwise.

• ALE can be used to enable an external address latch that will hold the address value after it has been removed from the pins.

Page 7: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Programming P0

• Using it as an output port:

MOV A, #55HBACK: MOV P0, A

ACALL DELAYCPL ASJMP BACK

– This will continuously output 01010101 followed by 10101010 on P0 separated by a certain delay.

– Port P0 is initialized as output by default, so no need to configure it.

• Using it as an input port:

MOV A, #0FFHMOV P0, A

BACK: MOV A, P0MOV P1, ASJMP BACK

– This will continuously read from port P0 and write the same value to port P1.

– Port P0 is initialized as output by default, so it needs to be configured for input by writing 1’s to all of its bits.

Page 8: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Port P1

• Can be used both forinput and output.

• Its pins are connected tointernal pull-up resistorsso no external pull-up isneeded.– Therefore, if the external pin is left un-connected, the

matching bit will be read as a logic high.

• Configured for output by default.– To configure it for input a 1 must be written into each

bit.

Page 9: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

All Input or All Output?

• Do these ports operate only as 8-bit input or 8-bit output ports?

• NO.– The individual bits of each port can be

operated as either input or output.• A pin is output by default. It can be made an input

by writing 1 in its corresponding bit in the SFR register.

Page 10: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Dual Role of P1 Pins

• In the 8052, pins P1.0 and P1.1 serve a second function.– They are the external controls for timer T2.

– Since there is no T2 in 8051 and 8031, these pins don’t have any special function in these chips.

Page 11: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Port P2 and its Dual Role

• P2 is very similarto P1 in its basic operation and in the fact that it does not need external pull-up.

• As it was shown for P0, P2 also serves as pins A8 – A15 (the upper 8 bits of he address bus) when accessing external memory.– The upper 8 bits of the address will be kept on the P2 pins for

the duration of the memory cycle.• No need for external latching.

Page 12: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Port P3

• P3 is similar to P1 and P2 in its basic operation and in the fact that it does not need external pull-up.

Page 13: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Functions of the P3 Pins

• All port P3 pins are multifunctional, they are not only I/O port pins but they also serve special functions.

MSB LSB

P3.7 P3.6 P3.5 P3.4 P3.3 P3.2 P3.1 P3.0

RD WR T1 T0 INT1 INT0 TXD RCD

P3.7 Read Signal P3.3 External Interrupt

P3.6 Write Signal P3.2 External Interrupt

P3.5 Timer 1 external input

P3.1 Serial Output

P3.4 Timer 0 external input

P3.0 Serial Input

Page 14: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Read-Modify-Write Instructions

• All of the following instructions read the last value stored in the latch.

ANL ORLXRL JBCCPL INCDEC DJNZMOV PX.Y, C CLR PX.YSETB PX.Y

– All other instructions will read the value from the pin.

Page 15: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Driving Ability

• The pins of ports P1, P2, and P3 have a fan-out of 4 LS TTL inputs only.

• The fan-out of the pins of port P0 depends on the size of the external resistor used for the pull-up.– You should not expect a fan-out for P0 pins of

more than 8 inputs.

Page 16: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Accessing External Memory

• As it has been noted before, the 8051 does not have an address or data bus. Instead, the pins of ports P0 and P2 are used for that purpose.– The pins of port P0 double as AD0 – AD7 (multiplexed).– The pins of port P2 double as A8 – A15.

• During a memory access (read from/write to external data memory or instruction fetch from external program memory):– The pins of port P0 first carry the lower 8-bits of the address,

then switch operation to become the data bus.– The ALE signal is set to 1 during the period when the address is

on the bus.– The pins of port P2 carry the upper 8-bits of the address through

out the memory access cycle.

Page 17: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Accessing External Memory

• What about the values that were on the ports previously?– The values are stored in the latches in the

SFR and are restored after the memory access operation.

– The one exception is P0 where the value stored in the register is always over-written.

• This is due to the use of the P0 pins for the bidirectional data bus.

Page 18: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Accessing External Memory

• Access to external program memory always requires a 16-bit address.– Therefore, ports P0 and P2 are always used during external

instruction fetch operations.

• Access to external data memory may use an 8-bit or 16-bit address depending on the instruction.

• MOVX A, @DPTR– Uses a 16-bit address.

• MOVX A, @R0– Uses an 8-bit address.

– However, using a value placed on P2 before the second MOVX instruction allows us to provide a 16-bit address if necessary.

Page 19: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

The Read and Write Signals

• It has also been noted before that the 8051 has separate program and data memory spaces.– It therefore also has separate external

signals for accessing the two different memories.

• The PSEN signal is used during read cycles from program memory.

• The RD and WR signals are used during read cycles from external data memory.

Page 20: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.1

Page 21: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable
Page 22: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Single-Bit Instructions

Page 23: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.2

Page 24: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.3

Page 25: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.4

Page 26: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.5

Page 27: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.6

Page 28: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.7

Page 29: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.8

Page 30: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.9

Page 31: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.10

Page 32: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.11

Page 33: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.12

Page 34: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.13

Page 35: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.14

Page 36: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.15

Page 37: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Carry-bit related Instruction

Page 38: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Swap Instruction

Page 39: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

ASCII Code for 0-9

Page 40: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.16

Page 41: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable

Example #7.17

Page 42: Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable