Sei sulla pagina 1di 3

Experiment​ ​5

Interfacing​ ​Pushbutton,​ ​LED,​ ​and


Seven​ ​Segment​ ​LED​ ​Display​ ​with
Atmega328P​ ​MCU
Objectives
● To​ ​interface​ ​a​ ​pushbutton​ ​and​ ​an​ ​LED​ ​with​ ​Atmega328P​ ​MCU​ ​and​ ​execute​ ​some
assembly​ ​language​ ​and/or​ ​C​ ​programs​ ​to​ ​use​ ​these​ ​devices.
● To​ ​interface​ ​a​ ​pushbutton​ ​and​ ​a​ ​seven​ ​segment​ ​LED​ ​display​ ​with​ ​Atmega328​ ​MCU
and​ ​execute​ ​some​ ​assembly​ ​language​ ​and/or​ ​C​ ​programs​ ​to​ ​use​ ​these​ ​devices.

Mapped​ ​Course​ ​Outcomes


CO-3 Develop​ ​assembly​ ​language​ ​programs​ ​for​ ​the​ ​selected​ ​MCU​ ​using​ ​available​ ​tools.
CO-4 Develop​ C ​ /C++​ ​language​ ​programs​ ​for​ ​the​ ​selected​ ​MCU​ ​using​ ​available​ ​tools.
CO-5 Interface​ A​ tmega328P​ ​MCU​ ​to​ ​a​ ​variety​ ​of​ ​analog​ ​and​ ​digital​ ​input​ ​and​ ​output
devices​ ​to​ ​perform​ ​meaningful​ ​tasks.

Introduction
In this experiment we have to interface a pushbutton and an LED to Atmega328P as shown
in Figure 1 and interface a pushbutton and a common cathode LED display as shown in
Figure 2. We should note that whenever a pushbutton is interfaced to the Atmega328P
MCU, the internal pull-up resistor in the MCU should be enabled for that input line by
appropriate​ ​instruction​ ​sequence​ ​in​ ​the​ ​program.

Figure​ ​1:​ ​Interfacing​ ​pushbutton​ ​and​ ​an​ ​LED.


JSS​ ​S&TU,​ ​SJCE,​ ​Dept.​ ​of​ ​E&EE,​ ​V​ ​Semester​ ​B.E.​ ​in​ ​E&EE

Figure​ ​2​ ​:​ ​Interfacing​ ​a​ ​pushbutton​ ​and​ ​a​ ​7-segment​ ​LED​ ​display.

Using the hardware shown in Figure 1, it is required to perform the following tasks by writing
appropriate​ ​programs​ ​in​ ​both​ ​assembly​ ​language​ ​and​ ​in​ ​C:

1. Write a program to monitor the status of the pushbutton in Figure 1. As long as the
pushbutton is not pressed, the LED should be OFF. As long as the pushbutton is
pressed​ ​the​ ​LED​ ​should​ ​be​ ​turned​ ​ON.
2. For the hardware shown in Figure 1, write a program to monitor the status of
pushbutton. As long as the pushbutton is not pressed, the LED should be OFF. Once
the pushbutton is pressed, the LED should glow for one minute and then turn OFF.
Realize​ ​time​ ​delay​ ​by​ ​software.​ ​Check​ ​the​ ​timing​ ​using​ ​a​ ​stopwatch.

To understand how to develop programs in C for Atmega328P refer to the slides given in the
theory class. On the hardware shown in Figure 2, we have to perform the following tasks by
writing​ ​appropriate​ ​programs​ ​in​ ​both​ ​assembly​ ​language​ ​and​ ​in​ ​C:

1. For the hardware shown in Figure 2, write a assembly language program and also a
C program to count the number of times the pushbutton is pressed and display it on
the seven segment display. For eg., initially the display should be 0. Whenever
pushbutton is pressed and released, the display should increment by 1. After 9, the
counting​ ​should​ ​reset​ ​to​ ​0​ ​and​ ​repeat.
2. In Figure 2, let a high-to-low logic change on INT0/PD2 pin cause an INT0 interrupt.
Write an assembly language program and also a C program to display on the LED
display any integer in the range 1 to 6, both inclusive, whenever the pushbutton is
pressed, thus simulating throwing of a dice. Sketch a flowchart to show the logic.
Note​ ​that​ ​here​ ​we​ ​have​ ​enable​ ​INT0​ ​interrupt.

Materials​ ​Required
● The​ ​latest​ ​version​ ​of​ ​Atmel​ ​Studio​ ​installed​ ​on​ ​a​ ​computer.
● Atmel-ICE​ ​Basic​ ​Programmer.
● Common​ ​Cathode​ ​Type​ ​7-segment​ ​LED​ ​Display​ ​--​ ​1​ ​No.
● 220​ ​Ω,​ ​0.25​ ​W​ ​resistor​ ​--​ ​9​ ​Nos.
● 3​ ​mm​ ​LED​ ​--​ ​1​ ​No.
● Pushbutton​ ​which​ ​can​ ​be​ ​mounted​ ​on​ ​a​ ​breadboard​ ​--​ ​1​ ​No.
● Atmega328P​ ​MCU​ ​--​ ​1​ ​No.
● Breadboard​ ​with​ ​regulated​ ​power​ ​supply​ ​built​ ​in​ ​Experiment​ ​1​ ​and​ ​patch​ ​cords.

EE540​ ​Microcontroller​ ​Lab​ ​Experiment​ ​5 3​ ​of​ ​3


JSS​ ​S&TU,​ ​SJCE,​ ​Dept.​ ​of​ ​E&EE,​ ​V​ ​Semester​ ​B.E.​ ​in​ ​E&EE

Procedure
First the hardware is built as per Figures 1 and 2. After this, the projects are created in Atmel
Studio as explained in earlier experiments. While creating C programs, C/C++ is selected as
project type in Atmel Studio. Rest of the procedure for building the project is same as
explained​ ​in​ ​earlier​ ​experiments.

After the project is built, the MCU is programmed by following the same procedure explained
in​ ​Experiment​ ​4.

Program​ ​is​ ​verified​ ​by​ ​checking​ ​the​ ​output​ ​after​ ​operating​ ​the​ ​pushbutton.

Conclusion
Pushbutton, LED and seven segment LED display have been interfaced to Atmega328P
MCU. Programs have been written to perform the specified tasks on the hardware and
verified.

EE540​ ​Microcontroller​ ​Lab​ ​Experiment​ ​5 3​ ​of​ ​3

Potrebbero piacerti anche