Monday 23 July 2018

Interfacing 7-Segment to AVR Microcontroller (Atmega-8)

Aim:

The main aim of this project is how to interface 7-segment and display 0 to 99 values on 7-segments.

Description:

Introduction
Till now you have learn what is an embedded system, basic memory architecture of a microcontroller, how to implement assembly language and use of some softwares like pinnacle 52, keil-C and flash magic; we also have come across how to interface LEDs from a microcontroller and how to generate different pattern through it. now its time to move forward and learn one more step ahead towards the completion of our 6-weak training. so here today we will learn about 7-Segment display; How to interface and program it; and some of the applications of it.
 7-Segment Display
A 7-Segment display is a useful electronic component use to produce numeric, alphabetic and some non-alphabetic symbols using a specific arrangement of LEDs as shown in figure here.
A 7-Segment display has 10-Pins representing each abcbefgand h LEDs respectively along with two extra pins for GND andVSS. following shown an original 7-Segment display device along with its pin diagram. LED h is also denoted by symbol dp.
As we have studied in LED interfacing a 7-segment display is also interfaced in same way as it is also made of LEDs. So we can interface LEDs in three ways bu here difference is that 7-Segment displays comes in two types by manufacturers i.e. “Common Anode” and “Common Cathode“; the logics are shown in figure below.
and thus which logic is o implement is on the bases of these specifications provided by manufacturer.
Digit Drive Pattern:
To display the digits on 7 segment, we need to glow different logic combinations of segments. For example if you want to display the digit 3 on seven segment then you need to glow the segments a, b, c, d and g. The below table show you the Hex decimal values what we need to send from PORTB to Display the digits from 0 to 9.
DIGITDPGFEDCBAHEX VALUE
0001111110x3f
1000001100x06
2010110110x5b
3010011110x4f
4011001100x66
5011011010x6d
6011111010x7d
7000001110x07
8011111110x7f
9011001110x67

Block Diagram

7seg

Schematic


Code

// ******************************************************
// Project: 0 to 99 display in 7-segments using ARM7(LPC2148)
// Author: Hack Projects India
// Module description: Operate two 7-segments
// ******************************************************
#include<lpc214x.h>
int i,j,k,l,a[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67};
void delay_ms(double ms);

void delay_ms(double ms)
{
 unsigned int i,j;
 for(i=0;i<ms;i++)
   for(j=0;j<1000;j++);
}
int main()
{
  
  PINSEL0=0x00000000;   //set all GPIO pins
  PINSEL1=0x00000000;
  PINSEL2=0x00000000;
  IO0DIR |=0xff;
  IO1DIR |=(1<<16)| (1<<17); 
       //set 16,17,18,19,20,21,22 as output pins
  while(1)
  {
   
  for(k=0;k<10;k++)
  {
   for(l=0;l<10;l++)
   {
   IOSET1=0x02<<16;
   IOSET0=a[k];
   delay_ms(100); 
   IOCLR1=0x02<<16;
   IOCLR0=a[k];
   IOSET1=0x01<<16;
   IOSET0=a[l];
   delay_ms(1000); 
   IOCLR1=0x01<<16;
   IOCLR0=a[l];
   }
  }
  }
}

Downloads:

The code was compiled in Keil uvision4 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.

Further Reading suggestions:

No comments:

Post a Comment