Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] source code for msp430

Status
Not open for further replies.

sapna.dudani@gmail.com

Member level 4
Joined
Feb 14, 2011
Messages
78
Helped
23
Reputation
46
Reaction score
23
Trophy points
1,288
Activity points
1,890
hey friends... can any one please help me to write a source code for driving a 4 digit seven segment led display using msp430g2xx series and also i have to scroll the digits automatically......
 

grieblm

Member level 4
Joined
May 7, 2011
Messages
75
Helped
18
Reputation
36
Reaction score
18
Trophy points
1,308
Location
Georgetown, Canada
Activity points
1,734
First step is to drive the displays without scrolling:

Code:
const unsigned char Lookup[10] = {} // Make a table with segments for each digit
unsigned char Values[4] = {1, 2, 3, 4};  // Digit display values

// set up one port as a output connected to the segments
P1DIR = 0xFF;

// set up a second port as a output connected to the LED commons -- you'll need to buffer the pin with a transistor or FET.  Lowest 4 bits drive the LED common pins
P2DIR = 0xFF;

for (i=0; i<4; i++) {
   P2OUT = 1 << i;                   // Enable digit drive i
   P1OUT = Lookup[Values[i]];    // Display segments for digit i
   // add a delay to slow the refresh
}

Once the LED outputs are working, you can change the Values[] array contents to simulate a scrolling display.
 

Iuri

Member level 2
Joined
May 14, 2011
Messages
50
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,630
do you have the schematics or a block diagram?
 

sapna.dudani@gmail.com

Member level 4
Joined
Feb 14, 2011
Messages
78
Helped
23
Reputation
46
Reaction score
23
Trophy points
1,288
Activity points
1,890
no i dont have any schematic .....

i am a beginner in c i have tried to write a program to drive a 4 digit seven segment led display using msp430g2231 and display BALL now i want to scroll the digits , the program i have written just to display the four digits is


#include<msp430g2231.h>
void delay_ms(unsigned int i)
{
int j,a;
for(a=0; a<=i; a++)
for(j=0; j<=100; j++);
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0XFF;
P2SEL = 0X3F;
P2DIR = 0XC0;
for(;;)
{
P2OUT = 0X00;
P1OUT = 0XFF;
delay_ms(5);
P2OUT = 0X40;
P1OUT = 0XFD;
delay_ms(5);
P2OUT = 0X80;
P1OUT = 0X43;
delay_ms(5);
P2OUT = 0XC0;
P1OUT = 0X43;
delay_ms(5);
}
}

now how do ii scroll these digits....
 

Iuri

Member level 2
Joined
May 14, 2011
Messages
50
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,630
sorry my friend, I'm little bit confused about how you are connecting the mcu with the four 7 segment display, if you can draw a simple figure of how this is connected perhaps i can help you figure this out.

Iuri~
 

sapna.dudani@gmail.com

Member level 4
Joined
Feb 14, 2011
Messages
78
Helped
23
Reputation
46
Reaction score
23
Trophy points
1,288
Activity points
1,890
the 4 digit led has 12 pins out of which 8 are data lines that are connected using resister to port 1 i.e. P1.0 to P1.7 of msp430g2xx and the 4 enable pins are connected to multiplexer with transistor in between and port 2.6 and 2.7 are the select lines dat are connected to multiplexer givin combination 0x00, 0x40, 0x80, 0xc0 i.e. 00,01,10,11 rest pins are connected to ground and vcc as required...

---------- Post added at 08:00 ---------- Previous post was at 07:56 ----------

i have modified my above program to drive the led and display ball now m having a problem in scrolling as in i displayed BALL now i want to display in the pattern below
BALL
ALL
LL B
L BA
BAL
BALL
 

grieblm

Member level 4
Joined
May 7, 2011
Messages
75
Helped
18
Reputation
36
Reaction score
18
Trophy points
1,308
Location
Georgetown, Canada
Activity points
1,734
no i dont have any schematic .....

i am a beginner in c i have tried to write a program to drive a 4 digit seven segment led display using msp430g2231 and display BALL now i want to scroll the digits , the program i have written just to display the four digits is


#include<msp430g2231.h>
void delay_ms(unsigned int i)
{
int j,a;
for(a=0; a<=i; a++)
for(j=0; j<=100; j++);
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0XFF;
P2SEL = 0X3F;
P2DIR = 0XC0;
for(;;)
{
P2OUT = 0X00;
P1OUT = 0XFF;
delay_ms(5);
P2OUT = 0X40;
P1OUT = 0XFD;
delay_ms(5);
P2OUT = 0X80;
P1OUT = 0X43;
delay_ms(5);
P2OUT = 0XC0;
P1OUT = 0X43;
delay_ms(5);
}
}

now how do ii scroll these digits....

Here try this:

Code:
unsigned char digits[5] = {0xFF, 0xFD, 0x43, 0x43, BLANK};  // BLANK is pattern for all segments off
unsigned char temp;

for (;;) {
    // adjust the n delay (multiple of 20mS) for scrolling speed
    for (i=0; i<n; i++) {
        P2OUT = 0X00;
        P1OUT = digits[0];
        delay_ms(5);
        P2OUT = 0X40;
        P1OUT = digits[1];
        delay_ms(5);
        P2OUT = 0X80;
        P1OUT = digits[2];
        delay_ms(5);
        P2OUT = 0XC0;
        P1OUT = digits[3];
        delay_ms(5);
    }

    // scroll the digits
    temp = digits[0];
    digits[0] = digits[1];
    digits[1] = digits[2];
    digits[3] = digits[4];
    digits[4] = temp;
}
 
Last edited:

sapna.dudani@gmail.com

Member level 4
Joined
Feb 14, 2011
Messages
78
Helped
23
Reputation
46
Reaction score
23
Trophy points
1,288
Activity points
1,890
grieblm thanx a lot thecode worked out very well.........

now with the same microcontroller i m want to make a real time clock using the same msp430g2231 with the same connections as before only the difference will be playing with ports as in using the first two digits of led to display hour and the last two digits as minutes and the dot of second digit to blink after each second... can any one please help me to start with it or what logic can i use here......
 

grieblm

Member level 4
Joined
May 7, 2011
Messages
75
Helped
18
Reputation
36
Reaction score
18
Trophy points
1,308
Location
Georgetown, Canada
Activity points
1,734
You'll need to give some background. Do you have a 32.768KHz crystal or oscillator? You'll need this or a high frequency external oscillator to get any sort of clock accuracy. The internal RC oscillator is extremely inaccurate.

Assuming you have an external 32.768KHz clock source:
  1. Use Timer1 to divide down the oscillator to as close to 1Hz as possible (use the prescaler as well);
  2. Hook an interrupt to the timer to be activated every second;
  3. Increment a counter in the interrupt routine to count the seconds, minutes, and hours. If you use BCD math, it makes it simpler to display.

This app note from TI gives an example of a real-time clock.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top