COMSATS
UNIVERSITY ISLAMABAD
MICROPROCESSOR SYSTEMS AND INTERFACING
LAB REPORT 2
SUBMITTED TO:
SIR KHIYAM
IFTIKHAR
SUBMITTED BY:
JUNAID AHMAD
Ibrar ahmad
Jarrar malik
REGISTRATION NO:
CIIT/FA19-BEE-089/ISB
Ciit/fa19-bee-083/isb
Ciit/fa19-bee-087/isb
DATE:
01-10-2021
Ø 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
·
Ø 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:
#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
unsigned char
seven_seg_array[10]={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; //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;
}
·
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 segments. 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.
Ø 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.
/*
* 7SEG2TRY.c
*
* Created: 10/3/2021 7:30:41 PM
* Author : junaid
*/
#include <avr/io.h>
#define F_CPU 1600000UL
#include<util/delay.h>
int main(void)
{
char seven_seg_array[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; // here is the hexa code for
first 7 seg
char seven_seg_array1[] = {0x1F,0x06,0x1B,0x0F,0x06,0x0D,0x1D,0x07,0x1F,0x0F}; //sir here we select (2nd)7
seg input from a,b,c,d,e from port B
char seven_seg_array2[] = {0x01,0x00,0x02,0x02,0x03,0x03,0x03,0x00,0x03,0x03}; //and here is we write array for (2nd)7 seg F and G as
output on port C
int i,j;
DDRB=0xFF;
DDRD=0xFF;
DDRC=0XFF;
while(1)
{
for(i=0;i<=9;i++)
{
PORTB=~seven_seg_array1[i]; //
for(j=0;j<=9;j++)
PORTC=~seven_seg_array2[i];
for(j=0;j<=9;j++)
{
PORTD=~seven_seg_array[j];
_delay_ms(7000);
}
}
}
}
CRITICAL ANALYSIS/CONCLUSION:
In this lab
experiment I got to know about 7 Segment Display, its important features and
pins configurations. We connected common Anode 7-Segment with PORT D, PORT C and
Port B. AVR code was written and implemented.
Firstly, if we wanted to use Tx and Rx pins as output we had to
disable them by 2 lines code provided to us in lab manual(BUT SIR AS YOU SAID
IT WORK WITHOUT IT SO WE DIDN’T USE IT ). While displaying the counter we
were provided with an array which we had to modify by filling the look up
table given above. In Proteus simulation we observed counter changing upon
which resultant segment displayed the digits. Hardware was implemented using
ATmega328P by burning code in Arduino uno. 7 segment was connected to by 5 Volts and connect the 7 seg two display
to respectively pin of port A,B and Port D of Arduino UNO. |
Post a Comment