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.

Simple count display on LCD with MSP430FR4133 LaunchPad

Other Parts Discussed in Thread: MSP430FR4133

I Need an example code to display a count though 200 on the LCD when a button is pressed using the MSP430FR4133 Launchpad.

I have one written that when I press the S2 switch It will count to 10.  But I am using if statements.  This seems too cumbersome.  

Thanks for your help.

  • Show the relevant part of your code.
  • This works, but would like to count in decimal and just convert it to the display.

     

    LCDM0 = 0x21; // L0 = COM0, L1 = COM1

    LCDM1 = 0x84; // L2 = COM2, L3 = COM3

    Ctr=0;

    pos=pos6;

    for (;;) { // Loop forever

     

    if ((P2IN & SW1) == 0) { // Loop while button down

    //LCDMEMCTL |= LCDCLRM; // Clear LCD memory

    LCDMEM[pos] = digit[Ctr];

    Ctr+=1;

    i=50000;

    LCDCTL0 |= LCD4MUX | LCDON; // Turn on LCD, 4-mux selected

    PMMCTL0_H = PMMPW_H; // Open PMM Registers for write

    PMMCTL0_L |= PMMREGOFF_L; // and set PMMREGOFF

    if(Ctr>9)

    {

    Ctr=0;

    LCDMEM[pos] = digit[Ctr];

    LCDCTL0 |= LCD4MUX | LCDON; // Turn on LCD, 4-mux selected

    PMMCTL0_H = PMMPW_H; // Open PMM Registers for write

    PMMCTL0_L |= PMMREGOFF_L; // and set PMMREGOFF

    }

    if(Ctr==0)

    {

    pos=pos5;

    Ctr=1;

    LCDMEM[pos] = digit[Ctr];

    LCDCTL0 |= LCD4MUX | LCDON; // Turn on LCD, 4-mux selected

    PMMCTL0_H = PMMPW_H; // Open PMM Registers for write

    PMMCTL0_L |= PMMREGOFF_L; // and set PMMREGOFF

    pos=pos6;

    }

    while (i!=0)

    {

    i-=1;

    }

    }

    }

  • A more general solution that takes a binary value and shows it as separate decimal digits would be a bit more complex than your code. A simple way would be to 'print' the value into a string using sprintf (include the header file stdio.h).
    unsigned char buffer[6];
    sprintf(buffer,"%5u",Cnt);
    Then you go through buffer[x] and find a space or 0..9 for 5 digits, buffer[0] being the 10000's, buffer[4] being the 1's Cnt may be an unsigned int. If it is a space (32), put a blank into the position, else subtract 48 from the value in buffer[x] for a binary value of 0...9 that you can use to store into the proper position.
    If you use "%05u", then you will get trailing zeros, which spares you checking for space, but looks less nice on the display.

**Attention** This is a public forum