Line 1: Line 1:
 +
[[User:Guru|Guru]] ([[User talk:Guru|talk]]) 18:10, 17 November 2015 (IST)
 +
----
 
[[Category:AVR Tutorials]]
 
[[Category:AVR Tutorials]]
 
{{#ev:youtubehd|nVp4j9kCVD0|640}}
 
{{#ev:youtubehd|nVp4j9kCVD0|640}}
Line 12: Line 14:
 
Seven segment are widely used in applications where digits[0-9] are required to be displayed.Although they also display letters A to F as shown in figure(2) simulation.
 
Seven segment are widely used in applications where digits[0-9] are required to be displayed.Although they also display letters A to F as shown in figure(2) simulation.
 
This is a very simple and convenient way to display numbers in a bright fashion.  
 
This is a very simple and convenient way to display numbers in a bright fashion.  
==Form Factor==
+
==Form Factor==  
  
 
*'''Sizes''':They come in various sizes; 0.28”, 0.3”, 0.32”, 0.36”, 0.39”, 0.4”, 0.5”, 0.56”, 0.6”, 0.8”, 1.0”, 1.2”, 1.5”, 1.8”, 2.0”, 2.3”, 3.0”, 4.0”, 5.0”, 7.0”)  
 
*'''Sizes''':They come in various sizes; 0.28”, 0.3”, 0.32”, 0.36”, 0.39”, 0.4”, 0.5”, 0.56”, 0.6”, 0.8”, 1.0”, 1.2”, 1.5”, 1.8”, 2.0”, 2.3”, 3.0”, 4.0”, 5.0”, 7.0”)  
Line 23: Line 25:
 
*'''Common Anode''': This type of 7 segments, requires a negativevoltage(GND) to given to the segments '''a''' to '''g''' in order to glow. This is shown in figure(4). A ground connection to cathode with respect to common anode again forward biases the LED which glows.<br />
 
*'''Common Anode''': This type of 7 segments, requires a negativevoltage(GND) to given to the segments '''a''' to '''g''' in order to glow. This is shown in figure(4). A ground connection to cathode with respect to common anode again forward biases the LED which glows.<br />
  
=Interfacing Single Seven Segment Display=
+
=Hookup=
==Schematic==
+
You may look this up with the simple breadboard as shown in section below or you could use the Ultra AVR dev kit if do not wish to jumble with wires and resistors.
The seven segment is interfaced as shown in the schematic below. Notice that sending a '''logic one''' to segments '''a to g''' will turn them ON. With that we can create a sequence.
+
==Type 1:Breadboard with Explore AVR 40 Pin Breakout Board with Atmega32==
 +
===Components Used===
  
[[File:Schematic AVR Interfacing 7Segment.JPG|680px]]
+
{| class="wikitable"
[http://exploreembedded.com/wiki/images/1/17/Schematic_AVR_Interfacing_7segment4.pdf '''Schematic:4Segments''']
+
|-
 +
| 1||
 +
<html><img src ="https://www.exploreembedded.com/blog/wp-content/uploads/img-collections/avr-mcu-breakout/1-dsc02958.jpg" width="300 px"></html>
  
==Code==
+
|| AVR 40 pin breakout board with Atmega32<br />
 +
[https://www.exploreembedded.com/product/AVR%2040%20Pin%20Breakout%20Board%20with%20Atmega32 Click here to buy from our store]
 +
|-
 +
|2||
 +
<html><img src ="https://www.exploreembedded.com/blog/wp-content/uploads/img-collections/breadboard-large/breadboard_large.jpg" width="300 px"></html>
 +
 
 +
|| Breadboard <br />
 +
[https://www.exploreembedded.com/product/Large%20Breadboard Click here to buy from our store]
 +
|-
 +
| 3||
 +
<html><img src ="https://www.exploreembedded.com/blog/wp-content/uploads/img-collections/male-to-male-jumper-wires-pack-of-40/1-dsc04497.jpg" width="300 px"></html>
 +
 
 +
|| Male to Male Jumper Wires <br />
 +
[https://www.exploreembedded.com/product/Male%20to%20Male%20Jumper%20Wires%20-%20Pack%20of%2040 Click here to buy from our store]
 +
|-
 +
 
 +
| 4||
 +
<html><img src ="https://www.exploreembedded.com/blog/wp-content/uploads/img-collections/7-segment/seven-segment-display.jpg" width="300 px"></html>
 +
|| 7 Segment Display - RED <br />
 +
[https://www.exploreembedded.com/product/7%20Segment%20Display%20-%20RED Click here to buy from our store]
 +
|-
 +
 
 +
| 5||
 +
<html><img src ="https://www.exploreembedded.com/blog/wp-content/uploads/img-collections/resistor/3_resistors.jpg" width="300 px"></html>
 +
|| Resistor <br />
 +
[https://www.exploreembedded.com/product/10K%20ohm%20Resistor Click here to buy from our store]
 +
|-
 +
 
 +
|| 6||
 +
<html><img src ="https://www.exploreembedded.com/blog/wp-content/uploads/img-collections/bc547/bc547.jpg" width="300 px"></html>
 +
|| Transistor - BC547 <br />
 +
[ Click here to buy from our store]
 +
|}
 +
 
 +
 
 +
==Wiring diagram==
 +
<html><img src ="https://www.exploreembedded.com/blog/wp-content/uploads/img-collections/fritzing-tutorials_de69ccc2/7-segment_breadboard_bb.png" width="670 px"></html>
 +
 
 +
==Type 2:Using Explore Ultra AVR Dev Kit==
 +
===Components Used===
 +
The Explore Ultra AVR Kit comes with all the things required, not just for this experiment but for the entire series. And even if you think of migrating to PIC or Arduino, you'll have breakout boards that fit on to this, hence we believe it is a great investment for learning hands on Embedded Systems. The kit is fully open source, you may use the schematics, the design files and all of the source code and build something cool on your own. And when you do that do not forget to share with us what you've done. We would be happy to see you building something cool.
 +
 
 +
<html>
 +
<ul>
 +
<li>Explore Ultra AVR Dev Kit: <a https://www.exploreembedded.com/product/Explore%20Ultra%20AVR%20Dev%20Kit> Buy from EE Store </a></li>
 +
<a href="https://www.exploreembedded.com/product/Explore%20Ultra%20AVR%20Dev%20Kit">
 +
<img src ="https://www.exploreembedded.com/blog/wp-content/uploads/img-collections/explore-avr-pic-kit/1-dsc03897.jpg" width="480 px">
 +
</a>
 +
</ul>
 +
</html>
 +
 
 +
<html><img src ="https://www.exploreembedded.com/blog/wp-content/uploads/img-collections/fritzing-tutorials_de69ccc2/7-segment_bb.png" width="670 px"></html>
 +
 
 +
=Code=
 
<syntaxhighlight>
 
<syntaxhighlight>
  
#include <avr/io.h>
+
/*-----------------------------------------------------------------------------
#include <util/delay.h>
+
  Program to demonstrate 4digit counter on 4-SevenSegment(CommonAnode) display
PORTC = 0XFF;
+
  -----------------------------------------------------------------------------
uint8_t seg_code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
+
  note: Code is for CommonAnode type of segment, seg_code[] must
                                0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
+
  be complemented for CommonCathode
uint8_t cnt =0;
+
------------------------------------------------------------------------------*/
int main(void)
+
 
 +
 +
/*contains the definition of all ports and SFRs */
 +
#include <avr\io.h>
 +
 
 +
#include "delay.h" //User defined delay library which contains the delay routines
 +
 
 +
#define SegmentValue PORTB
 +
#define SegmentSlection PORTC
 +
 
 +
#define SegOne  0x01
 +
#define SegTwo  0x02
 +
#define SegThree 0x04
 +
#define SegFour  0x08
 +
 
 +
 
 +
void display_number(unsigned int number)
 
{
 
{
while(1)
+
    unsigned char seg_code[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,
{
+
0x83,0xC6,0xA1,0x86,0x8E};
for(cnt =0; cnt<16; cnt++)
+
    unsigned char temp,i;
{
+
    unsigned int num;
PORTC = seg_code[cnt];
+
 
_delay_ms(1000);
+
}
+
}
+
}
+
</syntaxhighlight>
+
  
  [[File:Schematic AVR Interfacing 7segment4.JPG|680px]]
+
  for(i=0;i<200;i++)  
'''Code and explanation will be updated soon..'''
+
  {
 +
  num=number;
 +
 
 +
  temp = num/1000;
 +
  num=num%1000;  
 +
  SegmentSlection=SegOne;
 +
  SegmentValue = seg_code[temp];
 +
  DELAY_ms(1);
 +
 
 +
  temp = num/100;
 +
  num=num%100; 
 +
  SegmentSlection=SegTwo;
 +
  SegmentValue = seg_code[temp];
 +
  DELAY_ms(1);
 +
 
 +
          temp = num/10;
 +
  SegmentSlection=SegThree;
 +
  SegmentValue = seg_code[temp];
 +
  DELAY_ms(1);
 +
 
 +
  temp = num%10;
 +
  SegmentSlection=SegFour;
 +
  SegmentValue = seg_code[temp];
 +
  DELAY_ms(1);
 +
  }
 +
}
 +
/* start the main program */
 +
void main()
 +
{
 +
 +
  unsigned int cnt=0;
 +
/* Configure the ports as output */
 +
  DDRB = C_PortOutput_U8;
 +
  DDRC = C_PortOutput_U8;
 +
  while(1)
 +
    {
 +
 
 +
    for(cnt=0;cnt<=9999;cnt++) // loop to display 0000-9999
 +
{
 +
  display_number(cnt); 
 +
}
 +
}  
 +
 +
  }

Revision as of 18:10, 17 November 2015

Guru (talk) 18:10, 17 November 2015 (IST)



In this tutorial we will looking at interfacing a Seven Segment Display to Atmega32 MCU. We will also look at multiplexing 4 seven segment displays and programming them.

Seven Segment Display

fig 1: Basic 7 segment Display
fig 2: Simulation

Well, the name 7 segments implies there are 7 LED segments arranged as shown in figure 1. After LEDs they are the easiest interfaces to a microcontroller. There is also a decimal point or dp. It is used when decimal digits like 5.1 etc are displayed.

Applications

Seven segment are widely used in applications where digits[0-9] are required to be displayed.Although they also display letters A to F as shown in figure(2) simulation. This is a very simple and convenient way to display numbers in a bright fashion.

Form Factor

  • Sizes:They come in various sizes; 0.28”, 0.3”, 0.32”, 0.36”, 0.39”, 0.4”, 0.5”, 0.56”, 0.6”, 0.8”, 1.0”, 1.2”, 1.5”, 1.8”, 2.0”, 2.3”, 3.0”, 4.0”, 5.0”, 7.0”)
  • Colors: and varied colors too; Red, Green, Yellow, Orange, Blue, and White.

Working

fig 3:Common Cathode Display
fig 4: Common Anode 7 segment

Since these are basically LEDs arranged as a group they can either have anode in common or cathode.

  • Common Cathode: This type of 7 segments, requires a positive voltage(5v) to given to the segments a to g in order to glow. This is shown in figure(3). Providing a positive voltage with respect to common cathode makes the LED forward biased.
  • Common Anode: This type of 7 segments, requires a negativevoltage(GND) to given to the segments a to g in order to glow. This is shown in figure(4). A ground connection to cathode with respect to common anode again forward biases the LED which glows.

Hookup

You may look this up with the simple breadboard as shown in section below or you could use the Ultra AVR dev kit if do not wish to jumble with wires and resistors.

Type 1:Breadboard with Explore AVR 40 Pin Breakout Board with Atmega32

Components Used

1

AVR 40 pin breakout board with Atmega32

Click here to buy from our store

2

Breadboard

Click here to buy from our store

3

Male to Male Jumper Wires

Click here to buy from our store

4

7 Segment Display - RED

Click here to buy from our store

5

Resistor

Click here to buy from our store

6

Transistor - BC547

[ Click here to buy from our store]


Wiring diagram

Type 2:Using Explore Ultra AVR Dev Kit

Components Used

The Explore Ultra AVR Kit comes with all the things required, not just for this experiment but for the entire series. And even if you think of migrating to PIC or Arduino, you'll have breakout boards that fit on to this, hence we believe it is a great investment for learning hands on Embedded Systems. The kit is fully open source, you may use the schematics, the design files and all of the source code and build something cool on your own. And when you do that do not forget to share with us what you've done. We would be happy to see you building something cool.

Code

/*-----------------------------------------------------------------------------
   Program to demonstrate 4digit counter on 4-SevenSegment(CommonAnode) display
  -----------------------------------------------------------------------------
  note: Code is for CommonAnode type of segment, seg_code[] must 
  be complemented for CommonCathode
------------------------------------------------------------------------------*/
 
 
/*contains the definition of all ports and SFRs */
#include <avr\io.h>
 
#include "delay.h"	//User defined delay library which contains the delay routines
 
#define SegmentValue PORTB
#define SegmentSlection PORTC
 
#define SegOne   0x01
#define SegTwo   0x02
#define SegThree 0x04
#define SegFour  0x08	 
 
 
void display_number(unsigned int number)
{
    unsigned char seg_code[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,
0x83,0xC6,0xA1,0x86,0x8E};
    unsigned char temp,i;
    unsigned int num;
 
 
 
   for(i=0;i<200;i++)	   
   	 { 
	   num=number;
 
	   temp = num/1000;
	   num=num%1000;  
	   SegmentSlection=SegOne;
	   SegmentValue = seg_code[temp];
	   DELAY_ms(1);
 
	   temp = num/100;
	   num=num%100;  
	   SegmentSlection=SegTwo;
	   SegmentValue = seg_code[temp];
	   DELAY_ms(1);
 
           temp = num/10;
	   SegmentSlection=SegThree;
	   SegmentValue = seg_code[temp];
	   DELAY_ms(1);
 
	   temp = num%10;
	   SegmentSlection=SegFour; 
	   SegmentValue = seg_code[temp];
	   DELAY_ms(1);
	  }
 }
/* start the main program */
void main() 
{
 
   unsigned int cnt=0;
 /* Configure the ports as output */
  DDRB = C_PortOutput_U8;
  DDRC = C_PortOutput_U8;
   while(1)
    {
 
	    for(cnt=0;cnt<=9999;cnt++)	 // loop to display 0000-9999
		 {
		   display_number(cnt);  	
		 }
	}												  
 
  }