Lab 5
Lab 5
Objective:
Background Knowledge:
• Pins 1 to 8 − These pins are collectively known as Port 1. This port is internally pulled up, bi-
directional I/O port and doesn’t serve any other function.
• Pin 9 − It is a RESET pin, which is used to reset the microcontroller to its initial values. The 8051
is reset by holding the rst high for at least two machine cycles and then returning it low. However,
content of on-chip ram is not affected by reset.
• Pins 10 to 17 − These pins are known as Port 3. This port serves some functions like interrupts,
timer input, control signals, serial communication signals RxD and TxD, etc.
• Pins 18 & 19 − These pins are used for interfacing an external crystal to provide system clock.
• Pin 20 − This pin is ground.
• Pins 21 to 28 − These pins are known as Port 2. It serves as I/O port. Higher order address bus
signals are also multiplexed using this port.
• Pin 29 − This is PSEN pin which stands for Program Store Enable. It is used to read a signal from
the external program memory.
• Pin 30 − This is EA pin which stands for External Access input. It is used to enable/disable the
external memory interfacing.
• Pin 31 − This is ALE pin which stands for Address Latch Enable. It is used to demultiplex the
address-data signal of port.
• Pins 32 to 39 − These pins are known as Port 0. It serves as I/O port. Lower order address and data
bus signals are multiplexed using this port.
• Pin 40 − This pin is used to provide power supply to the circuit. The operating voltage of 8051
microcontroller is 5V.
Oscillator circuit:
The 8051 microcontroller uses the crystal to synchronize its operation. Effectively, the 8051 operates using
machine cycles, where a single machine cycle is the minimum amount of time in which a single 8051
instruction can be executed. 8051 has an on-chip oscillator. It needs an external crystal that decides the
operating frequency of the 8051. The crystal is connected to pins 18 and 19 with stabilizing capacitors. 12
MHz (11.0592 MHz) crystal is often used and the capacitance ranges from 20 pF to 40 pF.
Using Ports for I/O Operation:
8051 is TTL logic device and has two levels: logic "high" (1) and logic "low" (0). The voltage and current
involved for the two levels are as follows:
Port functions:
Ports Function
Dual-Purpose Port
Port 0 (Pin 32-39) • General purpose I/O port.
• Multiplexed address & data bus open drain outputs.
Dedicated I/O Port
Port 1 (Pin 1-8)
This port is used solely for interfacing to external devices (internal pull-ups).
Dual-purpose port
Port 2 (Pin 21-28)
• General purpose I/Oport.
• A multiplexed address & data bus (internal pull-ups).
Dual-purpose port
Port 3 (Pin 10-17)
• General purpose I/O port.
• Pins have alternate purpose related to special features of the 8051 (internal
pull-ups).
When power is on all ports are output ports by default. To configure any port for input, write all 1’s (0xff)
to the port. Any port can be used for output but for input, the FET must be off. Otherwise, the IC will be
reading the latch values rather than the external signal. Therefore, a "1" should be written to the pin if you
want to use it as input, especially when you have used it for output before. If you don't do this input high
voltage will get grounded through FET so you will read pin as low and not as high. It is best to use a resistor
while driving a port high otherwise the FET would burn.
Keil development tools for the 8051 microcontroller architecture support every level of software developer
from the professional applications engineer to the student just learning about embedded software
development, the industry-standard Keil c compilers, macro assemblers, debuggers, real-time kernels,
single-board computers, and emulators support all 8051 derivatives and help you get your projects
completed on schedule.
• When starting a new project, simply select the microcontroller you use from the device database
and the µvision IDE sets all compiler, assembler, linker, and memory options for you.
• Numerous example programs are included to help you get started with the most popular embedded
8051 devices.
• The Keil µvision debugger accurately simulates on-chip peripherals (i²c, CN, UART, SPI,
interrupts, I/O ports, A/D converter, D/A converter, and PWM modules) of your 8051 device.
Simulation helps you understand hardware configurations and avoids time wasted on setup
problems. Additionally, with simulation, you can write and test applications before target hardware
is available.
Procedure:
• Now in program file option browse for desired hex file and load it on the controller.
• For output visualization you have an option “visual instruments” in left window, you can choose
oscilloscope from there.
• For voltage sources you can select any generator from the left toolbar option “generators”.
• For connecting different components use left click at the pin of one component it will start making
a wire, hold left click till you connect it to the other terminal of connection.
Lab Task:
Write a code to continuously turn an LED on and off in Keil µVision. Burn this code on 8051
microcontroller chip and obtain the results. Verify the results in Proteus.
Conclusion: