Segment Display Interfacing with AVR ATmega16/ATmega32

-Segment Display Interfacing with AVR ATmega16/ATmega32

Introduction

7-segment display
7-Segment LED Display
7-segment displays are made up of 8 LED segments. 7 of these LED segments are in the shape of a line, whereas 1 segment is circular.
The 7 line shaped LED segments are used for displaying numbers 0 to 9 and a few letters like A, c, d, e, F, H, L, O, P, U, etc. The circular segment is used for displaying decimal point.
Each of the 8 elements has a pin associated with it which can be driven HIGH or LOW according to type of display and the number or alphabet to be displayed.
Common anode and common cathode types are available in 7-segment display. Depending on which type is used, the control signal required to light up a segment in the display changes. Common anode requires a LOW signal whereas common cathode requires a HIGH signal to light up a segment.
For more information about 7-segment LED display and how to use it, refer the topic 7-segment LED Display in the sensors and modules section.

Circuit diagram

7-segment display interfacing
Interfacing 7-Segment LED Display With AVR ATmega16/ATmega32

Program 

/*
 * ATmega16_7_Segment_Project_File.c
 * http://www.electronicwings.com
 */ 

#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#define LED_Direction DDRA  /* define LED Direction */
#define LED_PORT PORTA   /* define LED port */

int main(void)
{
 LED_Direction |= 0xff;  /* define LED port direction is output */
 LED_PORT = 0xff;
 
 char array[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; 
     /* write hex value for CA display from 0 to 9 */ 
   
    while(1)
    {
  for(int i=0;i<10;i++)
  {
   LED_PORT = array[i]; /* write data on to the LED port */
   _delay_ms(1000); /* wait for 1 second */ 
  }
    }
}

Interfacing diagram of 7-segment using driver IC SN7446AN

7-segment display interfacing using driver
Interfacing 7-Segment LED Display With ATmega16/ATmega32  Using SN7446AN Driver IC

Programming of 7-segment LED Display using driver IC SN7446AN

/*
 * ATmega16_BCD_to_7_Segment.c
 *
 * http://www.electronicwings.com
 */ 

#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#define LED_direction DDRA  /* define LED Direction */
#define LED_PORT PORTA   /* define LED PORT */

int main(void)
{
 LED_direction |= 0xff;  /* define LED port direction is output */
 LED_PORT = 0xff;
 char array[]={0,1,2,3,4,5,6,7,8,9};
     /* write BCD value for CA display from 0 to 9 */
 while(1)
 {
  for(int i=0;i<10;i++)
  {
   LED_PORT = array[i];/* write data on to the LED port */
   _delay_ms(1000); /* wait for 1 second */
  }
 }
}

Multiplexing Method 

Interfacing Diagram
Multiplexing

Interfacing Three 7-Segment LED Displays With ATmega16/ATmega32 Using SN7446AN Driver IC And Multiplexing
  • We can connect more than one displays by using Multiplexing method. In this method, at a time one display is driven by controller and rest are OFF. It keeps switching the displays using transistors. Due to the persistence of vision it appears as normal display. 
/*
 * ATmega16_7seg_multiple.c
 *
 * http://www.electronicwings.com
 */ 


#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdio.h>

#define LED_Directions DDRA   /* define LED Direction */
#define LED_Direction DDRB   /* define LED Direction */
#define LED_PORT1 PORTA    /* define LED port */
#define LED_PORT2 PORTB    /* define LED port */

char array[]={0,1,2,3,4,5,6,7,8,9};
int k,j,i,factor;
int brightvalue=0;


void set_brightness()
{
 int brightness = brightvalue;
 while (0 < brightness)
 {
  _delay_us(1);
  --brightness;
 }
}

ISR(TIMER0_OVF_vect)
{
 LED_PORT2 = 0x01;
 LED_PORT1 = array[k];
 set_brightness();

 LED_PORT2 = 0x02;
 LED_PORT1 = array[j];
 set_brightness();
    
 LED_PORT2 = 0x04;
 LED_PORT1 = array[i];
 set_brightness();
}

void SevenSeg_SetNumber(int num)
{
 k=num%10;
 num = num/10;
  
 j=num%10;
 num = num/10;
    
 i=num%10;
 num = num/10;
}

void sevseg_refreshDisplay(char refvalue)
{
 TIMSK=(1<<TOIE0);  /* Enable Timer0 overflow interrupts */
 TCNT0 = refvalue;  /* load TCNT0, count for 10ms*/
 TCCR0 = (1<<CS02) | (1<<CS00);  /* start timer0 with /1024 prescaler*/
}



int main(void)
{
 sei();
 LED_Directions = 0xff;  /* define port direction is output */
 LED_Direction = 0xff;  /* define port direction is output */
 LED_PORT1 = 0xff;
 LED_PORT2 = 0xff;
 sevseg_refreshDisplay(0xC2); /* set refresh rate of display (for 10ms set 0xC2) */
 brightvalue=1000;  /* set brightness level of 7 segment display */
 
 while(1)
 {
  SevenSeg_SetNumber(456);/* set value to display */
  _delay_ms(1000); /* wait for 1 second */
  SevenSeg_SetNumber(789);
   _delay_ms(1000);
 }
}

No comments:

Post a Comment