Lecture-3 (Microprocessors and Microcontrollers)
Lecture-3 (Microprocessors and Microcontrollers)
Microcontrollers
(EE-231)
Main Objectives
Machine Cycle and Time Delay of 8051
I/O port programming of 8051
Machine Cycle
CPU executing an instruction takes a certain number of
clock cycles which are referred as to as machine cycles.
The length of machine cycle depends on the frequency of
the crystal oscillator connected to 8051
In original 8051, one machine cycle lasts 12 oscillator
periods. 4K
32K
Delay Calculation
Example
4K
32K
Delay Calculation
Example
4K
Solution
32K
4K
32K
4K
32K
32K
32K
Ground
I/O Ports
The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins
All the ports upon RESET are configured as input, ready to be used as
input ports
When the first 0 is written to a port, it becomes an output
To reconfigure it as an input, a 1 must be sent to the port
To use any of these ports as an input port, it must be programmed
32K
I/O port
internal
structure
Port 0
32K
Port 0
32K
Port 1
32K
Port 2
Port 2 can be used as input or output
Just like P1, port 2 does not need any pull-up resistors since
it already has pull-up resistors internally
Upon reset, port 2 is configured as an input port
To make port 2 an input port, it must be programmed as
such by writing 1 to all its bits
In 8031-based systems, port 2 must be used along with P0
to provide the 16-bit address for the external memory
Port 2 is also designated as A8 A15, providing upper
address
Port 0 provides the lower 8 bits via A0 A7
Port 3
Port 3 can be used as input or output and does not need any pull-up
resistors
Port 3 is configured as an input port upon reset
Port 3 provides some extremely important signals
32K
32K
32K
32K
32K
32K
32K
32K
32K
32K