Afaq Khaliq (FA16-BCE-093) : Language Programming
Afaq Khaliq (FA16-BCE-093) : Language Programming
LAB # 1 : To interface input and output devices with 8051 MCU using Assembly
Language programming
Objectives
• To explain the interfacing of input devices (e.g. pushbuttons, switches) and output devices
(e.g. LEDs, buzzers) with the AT89C51 MCU using breadboard
• To modify the program and observe its behavior using I/O devices and assembly language
programming
Pre-Lab Theory
Read the details given below in order to comprehend the basic operation of LED, Piezo buzzer and
pushbutton.
Components Required
Item Quantity (minimum)
AT89C51 1
12 MHz crystal 1
33 pF capacitors 2
10 KΩ resistor 4
16V-10 µF capacitor 2
10 kΩ 9-line SIP 1
Male-to-female connectors 15
Male-to-male connectors 15
DIP switch 1
Pushbuttons 2
BD139 transistor 1
Piezo buzzer 1
Digital multimeter 1
To interface input and output devices with 8051 MCU using Assembly Language programming
Afaq Khaliq (FA16-BCE-093)
1.1 Introduction
In this section, we shall learn about the basic working principle of LED, pushbutton and Piezo buzzer. LEDs
are very common these days and are being used for lighting and display applications. LEDs are available in
different colors and give the light of medium to high brightness. They have become very cheap nowadays and
are widely used in many embedded systems applications. When forward biased, they consume very little
power (around 30 to 50 mW) and hence can be operated with microcontrollers.
Pushbuttons are devices that are used to make or break the electric connection. When pushed, its both
terminals get electrically connected and when released, they get apart automatically.
Piezo buzzers work on the principle of piezoelectric effect. Piezoelectric effect is a physical phenomenon
which describes that when voltage is applied across certain naturally occurring crystals, they vibrate at a fix
rate. This vibration produces sound if the vibration rate falls in the audible frequency range of humans. These
buzzers are commonly used output devices in embedded systems and many other electronic equipment to give
off sound.
Figure 10-1 shows a common LED used in many electronic circuits. Like any other diode, it has two
terminals, anode and cathode. When forward biased, LED gives off the light of particular wavelength (or
color). A typical LED requires 2 V for fully turn on and draws approximately 20 mA. Current sourcing
capability of a typical CMOS microcontroller output pin is 10 mA. Therefore, it cannot drive the LED directly
and an LED driver circuit is needed to be used when an LED is to be interfaced with MCU.
1.3 Pushbutton
Pushbuttons provide and easy way to input the 1-bit binary value to the MCU. When a pushbutton is
connected with the input pin of MCU, the voltage levels provided by the pushbutton must be stable to be To
interface input and output devices with 8051 MCU using Assembly Language programming
precisely identified by the MCU as either logic 0 or logic 1. Generally, a pushbutton is integrated with a
resistor to generate either logic 0 or logic 1 under ‘normally open condition’. The ‘normally open condition’ is
the state of the pushbutton when it is not pushed.
Due to the comparatively large amount of current drawn by the buzzer, a transistor-based driver circuit is used
to interface it with MCU.
Afaq Khaliq (FA16-BCE-093)
In-Lab Tasks
1.1 Draw the flow chart of the program that will turn on an LED connected
with an output pin of MCU if a pushbutton is pressed.
Draw the flow chart of the program that will turn on an LED connected with an output pin of the MCU if and
only if a pushbutton is pressed. Modify this program such that LED should normally remain ON and should
turn OFF when pushbutton is pressed.
Program
SWITCH EQU P1.0
LED EQU P1.1
ORG 0000H
LJMP MAIN
ORG 0030H
AGAIN:
JNB SWITCH,OUT ;JUMP TO OUT IF SWITCH = 0
JMP AGAIN
OUT:
CLR LED ;TURN ON LED
CALL DELAY
SETB LED ;TURN OFF LED
To interface input and output devices with 8051 MCU using Assembly Language programming
Afaq Khaliq (FA16-BCE-093)
JMP AGAIN
END
1.2 Write a complete assembly language program to blink all the LEDs on a
bar display
Code:
ORG 0000H
LJMP MAIN
ORG 0030H
DELAY:
LOOP1:
DJNZ R0, $
DJNZ R0, $
DJNZ R0, $
DJNZ R0, $
RET
MAIN:
AGAIN:
CALL DELAY
CALL DELAY
SJMP AGAIN
END
Schematic:
Afaq Khaliq (FA16-BCE-093)
1.3 Write a complete assembly language program that reads the DIP switch
and displays its contents on LED bar display
Code:
LED EQU P1
Switch EQU P2
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:
mov A,P2
MOV P1,A
JMP MAIN
End
Proteus result:
Afaq Khaliq (FA16-BCE-093)
1.4 Write a complete assembly language program that alternately operates the
LED and buzzer.
Code:
LED EQU P1
Switch EQU P2
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:
mov A,P2
MOV P1,A
JMP MAIN
End
Proteus result:
Afaq Khaliq (FA16-BCE-093)
The student performance for the assigned task during the lab session was:
Excellent The student completed assigned tasks without any help from the 4
instructor and showed the results appropriately.
Good The student completed assigned tasks with minimal help from the 3
instructor and showed the results appropriately.
Average The student could not complete all assigned tasks and showed 2
partial results.