Vous êtes sur la page 1sur 9

Lab # 03 Interfacing 7-Segment Display Using Digital I/O Ports

Lab # 03 Interfacing 7-Segment Display Using Digital


I/O Ports

Objectives:
 Learn to interface components like seven-segment display using digital I/O ports.

Required Tools:

Software Tools:
 AVR Studio/ Atmel Studio
 Proteus ISIS
 AVRDUDESS

Hardware Tools:

Name Value Quantity

Arduino Nano - 1

7-Segment Display - 1

Resistors 470 Ω 8

LED - 1

Wires - -

Table 3.1 List of Components

Pre-Lab

Seven Segment Display:


A seven-segment display is a set of seven bar-shaped LEDs (light-emitting diodes) arranged to
form a squared-off figure 8. If all LEDs are activated, the display shows a numeral 8. When some
of the elements are activated but not others, any single-digit numeral from 0 to 9 is shown,

Every LED is assigned a name from 'a' to 'h' and is identified by its name. Seven LEDs 'a' to 'g'
are used to display the numerals while eighth LED 'h' is used to display the dot/decimal.

Seven-segment displays are commonly used in digital clocks, clock radios, timers, wristwatches,
and calculators. They can also be found in motor-vehicle odometers, speedometers, radio
Lab # 03 Interfacing 7-Segment Display Using Digital I/O Ports

frequency indicators, and practically any other display that makes use
of alphanumeric characters alone.

Figure 3.1: Seven Segment Display

Types of Seven segment display:


There are two types of LED 7-segment displays:
 Common Cathode
 Common Anode

Figure 3.2: Common Cathode and Common anode 7- Segment

In Common Cathode configuration, the negative terminals of all LEDs are connected to the
common pin. The common is connected to ground and a particular LED glows when its
corresponding pin is given high.

In Common anode arrangement, the positive terminals of all LEDs are connected to common
pin .The common pin is given a high logic and the LED pins are given low logic to display a
number.
Lab # 03 Interfacing 7-Segment Display Using Digital I/O Ports

Pin configuration of seven segment display:

The figure below shows Pin diagram of a 7- segment display. For common anode, COM pins
are given Vcc and for common cathode, COM pins are given ground.

Figure 3.3 Pin Configuration of different types of 7-Segment Display

Pre-Lab Task:
A seven segment display is connected with Port D. Write a code to toggle all the segments
simultaneously with some delay.

Disabling Tx and Rx on Port D:

The pins PD0 and PD1 are connected to the receiver and transmitter of of USART respectively.
To use these pins for digital I/O, we have to disable the transmitter and receiver. This can be
done by disabling TXEN0 and RXEN0 bits in UCSR0B register.

Disable Tx and Rx in your code as follows:


UCSR0B&=~(1<<TXEN0);

UCSR0B&=~(1<<RXEN0);

Simulate the code on Proteus (Proteus schematic is shown below).

Figure 3.4 Simulation for Pre-Lab Task


Lab # 03 Interfacing 7-Segment Display Using Digital I/O Ports

In Lab:
Task 1:
a. Implement Pre-lab task on hardware to test all segments of a 7-Segment display.
b. Use DMM to test the 7-segment display and identify whether it is common cathode or
common anode (Lab instructor should explain the method of testing a 7-segment with
DMM).

Task 2:

Interfacing of Seven Segment Display with AVR Microcontroller:


In this task a seven segment display is connected to Port D. On Port B a 4 inputs 7-segment
display is connected which takes BCD number and displays it on seven segment. An array is
created which is currently zero. This array will be filled with hexa-decimal numbers after
creating a Look-up table for 7-segment display.

Task 2a: Look-up Table:

Fill the following table.

Digit to Seven Segment Pin


be
displayed h g f e d c b a Hexadecimal
Value
Atmega 328P Pin

0 0 0 1 1 1 1 1 1 0x3F

Table 3.2: 7-Segment Look-Up Table


Lab # 03 Interfacing 7-Segment Display Using Digital I/O Ports

Task 1b- Code:

#include <avr/io.h> /*This header file includes the apropriate

I/O definitions for the device */

#define F_CPU 16000000UL //XTAL Frequency =16MHz

#include <util/delay.h> /*This header file is required for

generating delays*/

int main(void)

//Write code to declare PORT B and PORT D as output

/* Write code to Disable Tx and Rx to use PD0 and PD1 as digital

I/O*/

unsigned char
seven_seg_array[10]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

//Fill this array according to LUT

unsigned char counter= 0;

while(1) { // Infinite loop

PORTB=counter; //send value of counter on PORT B

PORTD=~seven_seg_array[counter]; /*Send the array of 7

segment LUT on PORTD. Remove negation sign in case of

Common cathode 7 segment*/

_delay_ms(500);

counter++; //Increment counter till 10

if(counter==10)

counter=0;

return 0;

}
Lab # 03 Interfacing 7-Segment Display Using Digital I/O Ports

Task 1c-Simulation:

Figure 3.5: Simulation of Lab Task

Simulation using Arduino Nano:

Figure 3.6: Simulation of lab task using Arduino Nano

Task 1d-Hardware Implementation:

Download the hex file of your project in Atmega328P microcontroller using AVRDUDESS and
implement this task on hardware.
Lab # 03 Interfacing 7-Segment Display Using Digital I/O Ports

In Lab Task 2:
(To be specified by lab instructor)

Switches are connected to Port B for input and a seven segment display is connected to PORT
D of ATmega328p for output. Using these, perform a task assigned by your lab instructor.

Post lab task:


Connect 2 seven segments with Atmega 328P (As shown in schematic below). Write a code to
count from 0-99 on these 7- segments.

Figure 3.7 Simulation for Post Lab Task

Code:
Lab # 03 Interfacing 7-Segment Display Using Digital I/O Ports

Critical Analysis / Conclusion


(By Student about Learning from the Lab)

Lab Assessment

Pre Lab /1

In Lab /5

Data Analysis /4 /10

Data
Post Lab /4 /4
Presentation

Writing Style /4

Instructor Signature and Comments


Lab # 03 Interfacing 7-Segment Display Using Digital I/O Ports

Vous aimerez peut-être aussi