Is it possible to drive 4 seven segment display with MSP430G2231?

I'm trying to teach myself electronics and my goal is to create a digital clock with 4 digits.

I have an MSP430G2231 which has only 8 available ports as far as I can tell.

I saw some methods for driving multiple seven segment displays, like using a multiplexer or transistors. But it doesn't seem possible with MSP430G2231 because of it's lack of ports.

Am I wrong? Or could it be done? If yes, how?

• msp430 14 pin DIPS have 10 ports P1.0 to P1.7 and P2.6 and p2.7 – jsolarski May 26 '11 at 4:49
• @jsolarski - He would at least need 11: 7 for the segments and 4 for the digits. (And maybe a few buttons) – stevenvh May 26 '11 at 11:10
• @stevenh good time to use the new 20 pin msp430g2x52 or msp430g2x12? 16 pins for GPIO +8K programming space and 256b ram – jsolarski May 26 '11 at 11:16

Like Leon says you can use an I/O expander, or even better a LED display driver. In the past I've used the MAX7219, but this is a 5V device, for 3.3V you have to go to MAX6950. This can drive up to five 7-segment digits (the 6951 can do 8), so that may be suitable for your clock. It's controlled via SPI, so you only need 3 I/O pin of your controller. The driver does the multiplexing for you, has a BCD to 7-segment decoder and you can control brightness via software. One minor issue may be the package. The 7219 was available in DIL, but the 6950 only comes in a 0.635 mm pitch TSOP.

You say you don't want a crystal (why not?). For a clock you normally would use a crystal to get the required accuracy. But you can also work with the mains frequency, which over long term like months is even more accurate.

edit
Leon rightly remarks on the high price for the MAX6950. The MAX7219 is more affordable, but like I said it's a 5V device. Since you only need 3 lines to drive it you could easily add a few level shifters. A transistor will suffice, at least if you don't mind bit-banging the SPI (because it inverts the signal). If you want to use the on-chip SPI you need a non-inverting level shifter, like the FXL4T245 (difficult package though).

Alternatively, just buy an MSP430 with more I/O pins :-)

• The MAX6950 costs $13.84 from Digi-Key! – Leon Heller May 25 '11 at 21:23 • So? It's not like he asked for cheap - he asked for possible. – AngryEE May 25 '11 at 23:03 • @Leon - Yes, that's not cheap. I wonder why. It's a rather simple die, 17000 transistors. IIRC I bought the 7219 for 2.50 euros. – stevenvh May 26 '11 at 6:18 • @Leon - I went looking around for other display drivers from Maxim, and I found that the MAX6955 (which you recommended here) costs even twice as much! ($28) – stevenvh May 26 '11 at 6:27
• It looks like Maxim got remarks from customers who found the max7219 too big, so they went from a 24 pin skinny DIP to a 16 pin QSOP (5 mm long vs. 30!). That's too little pins for the usual multiplexing like the max7219 uses, so the max6950 uses charlieplexing. – Federico Russo May 26 '11 at 6:41

I would use 2 x 74HC 595 shift registers I have tried the code example and schematic Here http://www.43oh.com/forum/viewtopic.php?f=9&t=255 and it works with out an issue - I would suggest replacing the uln2003 with a few 2n2222 or 2n3909 npn transistor

    #include <msp430g2231.h>

unsigned int counter = 0;                   // Counter variable
unsigned int digitCounter = 0;            // Digit counter
unsigned char digit = 0;               // Single digit to be displayed
unsigned char bcd7digit[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; // BCD to 7 digit map
unsigned char digitSelector[4] = {0x01, 0x02, 0x04, 0x08}; // Digit selector map

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

P1OUT |= 0x01;                      // Port P1.0 will be used to latch
P1DIR |= 0x01;

USICTL0 |= USIPE6 + USIPE5 + USIMST + USIOE; // Out & clk enable, SPI Master
USICTL1 |= USICKPH + USIIE;               // Counter interrupt, flag remains set
USICKCTL = USIDIV_7 + USISSEL_2;          // /128 SMCLK
USICTL0 &= ~USISWRST;                     // USI released for operation
USICNT = USI16B;                           // Enable 16 bit

CCTL0 = CCIE;                             // CCR0 interrupt enabled
CCR0 = 500;                        //
TACTL = TASSEL_2 + MC_1 + ID_3;           // SMCLK, upmode

_bis_SR_register(LPM0_bits + GIE);        // Enter LPM0 w/ interrupt
}

// Timer A0 interrupt service routine
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
digitCounter++;                       // Increase digit counter
digitCounter &= 0x03;                // Mask, counter range is 0-3
digit = counter>>(4 * digitCounter);       // Shift digits right
digit &= 0x0F;                      // Mask, we need first digit only
USISRL = bcd7digit[digit];             // Get segments from the map
USISRH = digitSelector[digitCounter];    //
if(digitCounter == 0) {
counter = _bcd_add_short(counter, 0x01);// Decimally increase counter's when on first digit
}
USICNT |= 16;                              // Start USI
}

// USI interrupt service routine
#pragma vector = USI_VECTOR
__interrupt void USI_TXRX (void)
{
USICTL1 &= ~USIIFG;                     // Clear pending flag
P1OUT &= ~0x01;                     // Latch data
P1OUT |= 0x01;
}


Another Option would be using 4 x 74HC595 and use one each, for every 7segment you have this cuts the multiplexing and you can just send a serial string through the SPI interface or bit bang it. very similar as above. but uses less pins. Just an Idea

I think it actually has 8 I/O pins (not ports, it has one port) available if you use a crystal, which is plenty for four multiplexed seven-segment displays if you use a suitable port expander. It might be sensible to use a device with more I/Os, though.

A suitable port expander is the PCF8575, which can be interfaced to the MSP430G2231 via I2C. It will give you 16 I/Os. It costs under \$2.

• I don't want to use any external crystal. Can I use the pins XIN, XOUT for my I/O purposes? – frbry May 25 '11 at 19:08
• If you want any sort of accuracy a crystal is essential! Even if you dispense with it, you won't have enough outputs (you need 11). – Leon Heller May 25 '11 at 19:15
• yes you can use xin and xout they are labeled P2.6 and P2.7 – jsolarski May 26 '11 at 4:47
• @Leon - The PCF8575 is not very well suited as a LED driver. Maximum allowed device current is 100 mA, so if you want to drive 16 LEDs simultaneously (2 digits in @frbry's clock) you can only have 6 mA per LED – stevenvh May 26 '11 at 7:44
• It would need some driver transistors. – Leon Heller May 26 '11 at 10:54

You can connect the USI(SPI) output to a 74HC164 shift-register, which can drive one piece of 7-segment display. The final bit from the first 74HC164 can be connected in cascade mode to another 74HC164, and then to another 74HC164... So, with 4 pieces of 74HC164 in series, you just transmit 4 bytes from the USI to display 4 digits.

Please see http://singamicro-30-msp430g2231.blogspot.com/ on the USI.

• A schematic would be useful. Also, blogs and external links go away so please include the main portion of the text in your answer and link to the blog as a reference. That keeps your answer relevant even if the content goes away. – Trygve Laugstøl Nov 9 '12 at 7:59