This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

msp430g2231 interfacing with 2 seven segment display..!!

Other Parts Discussed in Thread: MSP430G2231

hi every one..!! 

i am making a small project on msp430 launch pad  with help of msp430g2231 ic ,which is simple counter   0 to 99.

 i want to flash both segment together. such as 11 ,12, 13 so on..for individual display it is ok  so what  to do for  flashing both segment  together. ??????

and my code is following..

 

 

 

#include"msp430g2231.h"

void delay();

void delay_short();

void control_pin(void);

void data(void);

void data1(int num);

void data2_dec(int num);

void num_display_unit();

void num_display_dec();

void main()

{

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

  P1DIR|=0xff;

P1OUT|=0xff;

P2SEL&=0x00;

P2DIR|=0xc0;

while(1)

{

unsigned int i,j;

for(i=0;i<10;j++)

{

  

for(j=0;j<10;j++)

{

    

    if(i>0)

    {

      num_display_dec();

          data2_dec(i);

          num_display_unit();

      data1(j);

    }

else

{

 

         

         

num_display_unit();

    data1(j);

}

}

i++;

}

}

}

void delay()

{

unsigned int i=50000;

do 

i--;

while(i!=0)

;

}

 void delay_short()

 {

  unsigned int i=30000;

do 

i--;

while(i!=0)

;

 }

void num_display_unit()

{

P2OUT&=0x00;

P2OUT|=0x40;

}

void num_display_dec()

{

//blink1

P2OUT&=0x00;

P2OUT|=0x80;

}


void data1(int num)

{

switch(num)

{

case 1:

P1OUT=0x7f;

   P1OUT&=0x3e;

   delay();

   delay();

break;

case 2:

P1OUT=0x7f;

   P1OUT&=0x44;

   delay();

   delay();

break;

case 3:

   P1OUT=0x7f;

   P1OUT&=0x14;

   delay();

   delay();

break;

case 4:

   P1OUT=0x7f;

   P1OUT&=0x32;

   delay();

   delay();

break;

case 5:

P1OUT=0x7f;

   P1OUT&=0x11;

   delay();

   delay();

break;

case 6:

P1OUT=0x7f;

   P1OUT&=0x01;

   delay();

   delay();

break;

case 7: 

P1OUT=0x7f;

   P1OUT&=0x3c;

   delay();

   delay();

break;

case 8:

P1OUT=0x7f;

   P1OUT&=0x00;

   delay();

   delay();

break;

case 9:

P1OUT=0x7f;

   P1OUT&=0x10;

   delay();

   delay();

break;

case 0:

P1OUT=0x7f;

   P1OUT&=0x08;

   delay();

   delay();

break;

default :

break;

}

}

void data2_dec(int num)

{

switch(num)

{

case 1:

P1OUT=0x7f;

   P1OUT&=0x3e;

   delay_short();

   

break;

case 2:

P1OUT=0x7f;

   P1OUT&=0x44;

   delay_short();

  

break;

case 3:

   P1OUT=0x7f;

   P1OUT&=0x14;

   delay_short();

  

break;

case 4:

   P1OUT=0x7f;

   P1OUT&=0x32;

   delay_short();

 

break;

case 5:

P1OUT=0x7f;

   P1OUT&=0x11;

   delay_short();

 

break;

case 6:

P1OUT=0x7f;

   P1OUT&=0x01;

   delay_short();

  

break;

case 7: 

P1OUT=0x7f;

   P1OUT&=0x3c;

   delay_short();

   

break;

case 8:

P1OUT=0x7f;

   P1OUT&=0x00;

   delay_short();

 

break;

case 9:

P1OUT=0x7f;

   P1OUT&=0x10;

   delay_short();

  

break;

case 0:

P1OUT=0x7f;

   P1OUT&=0x08;

   delay_short();

  

break;

default :

break;

}

}

 

 

 

  • For jobs like doing things in regular intervals, you normally use a timer and a timer interrupt.

    So the usual way would be: write the values you want to display into a global variable (make it volatile). Then set up a timer that triggers an interrupt every so often. Inside the service routine of the timer, you either clear the display, or copy the two values from the global variable to the display.

    So the counting is independent of the blinking. It doesn't make a difference whether you count 7 steps per blink or only one every 5 blinks.

    Working with a microcontroller requires a different thinking. Use the hardware whereever possible and don't do everything in software. On a PC, things like this are done in a similar way, but there is an OS loaded that handles most of it for you, giving you timer events or threads.

    On a microcontroller, your application is its own OS and needs to handle these things on its own.

    The best microcontroller program is one that just initializes the hardware and then halts the CPU until next reset, lettign the hardware do everything. Of course this is not possible for most projects (but e.g. for an UART-to-SPI converter or a PWM-Pulse-generator this is not too difficult). But the closer you get to it, the better your program. And you'll also get a lower energy consumption too, if you do not try to do everything in software.

  • HI

     i am beginners in this field but i got idea from your post.

    thanks   Jens-Michael Gross

  • ajit singh said:
     i am beginners in this field

    The MSP (or every MCU) has a steep learning curve when you get past a simple LED blinking by a busy loop in the code. All this direct hardware usage is something to swallow at first. But once you got used to it, it makes life much easier.

  • ajit singh said:
     i am beginners in this field

    The MSP (or every MCU) has a steep learning curve when you get past a simple LED blinking by a busy loop in the code. All this direct hardware usage is something to swallow at first. But once you got used to it, it makes life much easier.

**Attention** This is a public forum