7-Segment Display Interfacing with MSP-EXP430G2 TI Launchpad

Overview of 7-Segment Display

7-Segment Display
7-Segment Display

 

7-segment displays are made up of 8 LED segments. They are used to display Numbers (0-9) and certain Alphabets (like c, A, H, P, etc.).

  • 7 of these LED segments are in the shape of a line, whereas 1 segment is circular.
  • Each of the 8 elements has a pin associated with it which can be driven HIGH or LOW.
  • To display a number or alphabet, we need to turn on specific LED segments of the display.

For more information about 7-segment LED display and how to use it, refer to the topic 7-segment LED Display in the sensors and modules section.

 

Interfacing 7-Segment Display with MSP-EXP430G2 TI Launchpad

Interfacing 7-Segment Display with MSP-EXP430G2 TI Launchpad
Interfacing 7-Segment Display with MSP-EXP430G2 TI Launchpad

 

Here, the 7-Segment display is driven directly by MSP-EXP430G2 TI Launchpad. Resistors need to be connected between the display and MSP-EXP430G2 TI Launchpad board. Depending on which number or alphabet is to be displayed, control signals are applied.

Note: We have used a common anode display, hence the common pin is connected to 5V. If a common cathode display is used, the common pin needs to be connected to the ground.

For common anode display, drive pin LOW to turn on the corresponding LED segment.

For common cathode display, drive pin HIGH to turn on the corresponding LED segment.

 

Interfacing 7-Segment Display Using SN7446AN Driver with MSP-EXP430G2 TI Launchpad

Interfacing 7-Segment Display Using SN7446AN Driver with MSP-EXP430G2 TI Launchpad
Interfacing 7-Segment Display Using SN7446AN Driver with MSP-EXP430G2 TI Launchpad

 

Here, the 7-segment display is driven by the SN7446AN IC. It is a BCD to 7-segment driver/decoder IC. This reduces the number of pins required to drive the 7-segment display.

 

Tread Carefully: MSP-EXP430G2 TI Launchpad board has a RAM of 512 bytes which is easily filled, especially while using different libraries. There are times when you need the Serial buffer to be large enough to contain the data you want and you will have to modify the buffer size for the Serial library. While doing such things, we must ensure that the code does not utilize more than 70% RAM. This could lead to the code working in an erratic manner, working well at times, and failing miserably at others. 

There are times when the RAM usage may exceed 70% and the codes will work absolutely fine, and times when the code will not work even when the RAM usage is 65%. 

In such cases, a bit of trial and error with the buffer size and/or variables may be necessary.

 

7-Segment Display Code for MSP-EXP430G2 TI Launchpad


int disp_pin[7];	/* array for a-g pins of 7-Segment display */

void define_segment_pins(int a, int b, int c, int d, int e, int f, int g)	/* Assigns 7-segment display pins to board */
{  
  disp_pin[0] = a;
  disp_pin[1] = b;
  disp_pin[2] = c;
  disp_pin[3] = d;
  disp_pin[4] = e;
  disp_pin[5] = f;
  disp_pin[6] = g;
}

void display_number(int num)	/* Function for displaying number (0-9) */
{
  switch(num)
  {
    case 0:
    digitalWrite(disp_pin[0], LOW);	/* Drive disp_pin[0] to LOW */
    digitalWrite(disp_pin[1], LOW);	/* Driving LOW turns on LED segment for common anode display */
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], LOW);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], HIGH); 
    break;
    case 1:
    digitalWrite(disp_pin[0], HIGH);	/* Drive disp_pin[7] to HIGH */
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], HIGH);	/* Driving HIGH turns off LED segment for common anode display */
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], HIGH);
    digitalWrite(disp_pin[6], HIGH);
    break;
    case 2:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], HIGH);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], LOW);
    digitalWrite(disp_pin[5], HIGH);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 3:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], HIGH);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 4:
    digitalWrite(disp_pin[0], HIGH);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], HIGH);
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 5:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], HIGH);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 6:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], HIGH);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], LOW);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 7:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], HIGH);
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], HIGH);
    digitalWrite(disp_pin[6], HIGH);
    break;
    case 8:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], LOW);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 9:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], LOW);
    break;
    default:
    digitalWrite(disp_pin[0], HIGH);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], LOW);
    digitalWrite(disp_pin[5], HIGH);
    digitalWrite(disp_pin[6], LOW);
    break;
  }
}

void setup() {
  pinMode(7, OUTPUT);	
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  define_segment_pins(13,12,11,10,9,8,7);	/* a-g segment pins to TI Launchpad */
}

void loop() {
  int i;
  for(i = 9; i>=0; i--)
  {
    display_number(i);
    delay(1000);
  }
  for(i = 0; i<=9; i++)
  {
    display_number(i);
    delay(1000);
  }
}

 

Video of 7-Segment Display using MSP-EXP430G2 TI Launchpad

 

Code for Control Of 7-Segment Display Using SN7446AN Decoder/Driver


int bcd_pins[4];	/* array for A-D pins of driver IC */

void bcd_control_pins(int a, int b, int c, int d)	/* Assigns A-D pins of deiver IC to TI Launchpad */
{  
  bcd_pins[0] = a;	
  bcd_pins[1] = b;
  bcd_pins[2] = c;
  bcd_pins[3] = d;
}

void display_number(int num)	/* Function for displaying number (0-9) */
{
  switch(num)
  {
    case 0:
    digitalWrite(bcd_pins[0], LOW);	/* Drive bcd_pin[0] to LOW */
    digitalWrite(bcd_pins[1], LOW);	/* Driving LOW turns on LED segment for common anode display */
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], LOW);	
    break;
    case 1:
    digitalWrite(bcd_pins[0], HIGH);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 2:
    digitalWrite(bcd_pins[0], LOW);
    digitalWrite(bcd_pins[1], HIGH);
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 3:
    digitalWrite(bcd_pins[0], HIGH);	/* Drive bcd_pin[3] to HIGH */
    digitalWrite(bcd_pins[1], HIGH);	/* Driving HIGH turns on LED segment for common anode display */
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 4:
    digitalWrite(bcd_pins[0], LOW);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], HIGH);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 5:
    digitalWrite(bcd_pins[0], HIGH);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], HIGH);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 6:
    digitalWrite(bcd_pins[0], LOW);
    digitalWrite(bcd_pins[1], HIGH);
    digitalWrite(bcd_pins[2], HIGH);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 7:
    digitalWrite(bcd_pins[0], HIGH);
    digitalWrite(bcd_pins[1], HIGH);
    digitalWrite(bcd_pins[2], HIGH);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 8:
    digitalWrite(bcd_pins[0], LOW);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], HIGH);
    break;
    case 9:
    digitalWrite(bcd_pins[0], HIGH);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], HIGH);
    break;
    default:
    digitalWrite(bcd_pins[0], LOW);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], LOW);
    break; 
  }
}

void setup() {
  pinMode(11, OUTPUT);		
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(14, OUTPUT);
  bcd_control_pins(14,13,12,11);	/* A-D of driver IC to TI Launchpad */
}

void loop() {
  int i;
  for(i = 9; i>=0; i--)
  {
    display_number(i);
    delay(1000);
  }
  for(i = 0; i<=9; i++)
  {
    display_number(i);
    delay(1000);
  }
}

 

Video 7-Segment Display Driver using MSP-EXP430G2 TI Launchpad


Components Used

TI Launchpad MSP-EXP430G2
TI Launchpad MSP-EXP430G2
1
Seven 7 Segment Display
Seven 7 Segment Display
1
SN7447AN BCD-To-Seven-Segment Driver
SN7447AN BCD-To-Seven-Segment Decoder/Driver
1
Breadboard
Breadboard
1

Downloads

7_Segment_Interfacing_With_TI_Launchpad_INO Download
Ad