0% found this document useful (0 votes)
38 views

Afaq Khaliq (FA16-BCE-093) : Language Programming

- The document describes objectives for a lab to interface input and output devices with an 8051 MCU using assembly language programming. - The objectives are to explain interfacing of input devices like pushbuttons and switches, and output devices like LEDs and buzzers with an AT89C51 MCU. - The document provides details on the working principles of LEDs, pushbuttons, and piezo buzzers. It also lists the components required for the lab and gives in-lab tasks to write assembly language programs.

Uploaded by

Afaq Khaliq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Afaq Khaliq (FA16-BCE-093) : Language Programming

- The document describes objectives for a lab to interface input and output devices with an 8051 MCU using assembly language programming. - The objectives are to explain interfacing of input devices like pushbuttons and switches, and output devices like LEDs and buzzers with an AT89C51 MCU. - The document provides details on the working principles of LEDs, pushbuttons, and piezo buzzers. It also lists the components required for the lab and gives in-lab tasks to write assembly language programs.

Uploaded by

Afaq Khaliq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Afaq Khaliq (FA16-BCE-093)

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

150 Ω 9-line SIP 1

10 kΩ 9-line SIP 1

Male-to-female connectors 15

Male-to-male connectors 15

DIP switch 1

LED bar display 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.

1.2 LED Operation

Figure 1-1 A through-hole LED

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

Figure 1-2 Single-push buttons


Afaq Khaliq (FA16-BCE-093)

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.

1.4 Piezo Buzzer

A Piezo buzzer, also simply called ‘buzzer’,


Figure 1-3 Piezo buzzer
is an electronic device that produces sound upon powering up. It operates on DC 5V and takes current around
30 mA to 40 mA. Therefore, it cannot be driven by the MCU pins directly.

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

;SUBROUTINE GENERATES SOME DELAY


DELAY:
MOV R1, 250
LOOP1:
MOV R0, #0FFH DJNZ R0, $
MOV R0, #0FFH DJNZ R0, $
MOV R0, #0FFH DJNZ R0, $
MOV R0, #0FFH DJNZ R0, $
DJNZ R1, LOOP1
RET
;MAIN PROGRAM STARTS FROM HERE
MAIN:
SETB LED ;LED IS OFF INITIALLY

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:

LED EQU P1.1

ORG 0000H

LJMP MAIN

ORG 0030H

;SUBROUTINE GENERATES SOME DELAY

DELAY:

MOV R1, 250

LOOP1:

MOV R0, #0FFH

DJNZ R0, $

MOV R0, #0FFH

DJNZ R0, $

MOV R0, #0FFH

DJNZ R0, $

MOV R0, #0FFH

DJNZ R0, $

DJNZ R1, LOOP1

RET

;MAIN PROGRAM STARTS FROM HERE

MAIN:

AGAIN:

SETB LED ;LED IS OFF INITIALLY

CALL DELAY

CLR LED ;TURN ON LED

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.

Worst The student did not complete assigned tasks. 1


Afaq Khaliq (FA16-BCE-093)

Instructor Signature: ______________________________ Date: ____________________

You might also like