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.

TM4C123GH6PM: Prepending values written to LCD

Part Number: TM4C123GH6PM

I successfully got characters writing to a Kentec boosterpack display from the TivaLaunchpad.  However, when the values I'm writing drop by an order of magnitude I'm getting lingering digits.  For example, I'll write 1546 just fine.  But if that value changes to 63 then the value read on the screen is: 6346  because it did not write over the '46' portion of the 1546 number.  I tried changing "%" to "%+" but it didn't work and I get errors.

If you have a better idea on how I should be clearing my value's before writing new ones please suggest something.  However, I will still need to right justify the new values so that the 1's place always lines up in my displayed values.  Whether or not the prepend part is blank or 0's doesn't make much of a difference to me at the moment.

As a secondary follow up:  I'll eventually have to write decimal values and the way I'm converting only applies to integers.  If you could suggest a way to write integers to the screen that would be great.  Or if you can point me towards a resource that would be wonderful as well.

Here's how I'm writing to the screen currently:

#include <stdio.h>
#include <inttypes.h>

extern uint32_t Reference;
extern tContext sContext;
extern tRectangle sRect;
char ref_buf[5];
char sample_buf[5];

void screen_update(void){
    TimerIntClear(TIMER5_BASE, TIMER_TIMA_TIMEOUT);

    //from website: stackoverflow.com/.../how-to-convert-uint64-t-value-in-const-char-string
    snprintf(ref_buf,5,"%"PRIu32,Reference);            //convert the integer ADC value to a const char*
    snprintf(sample_buf,5,"%"PRIu32,VelocityFB);            //convert the integer ADC value to a const char*

    //Clear last displayed value by writing in black
    GrContextForegroundSet(&sContext, ClrBlack);
    GrStringDraw(&sContext, ref_buf, 6, 150, 2, 1);
    GrStringDraw(&sContext, sample_buf, 6, 150, 40, 1);

    //Write the new displayed values on the screen
    GrContextForegroundSet(&sContext, ClrRed);
    GrStringDraw(&sContext, ref_buf, 5, 150, 2, 0);
    GrStringDraw(&sContext, sample_buf, 5, 150, 40, 0);
    GrFlush(&sContext);


}

  • Have you considered after the snprintf(), but before calling GrStringDraw(), you do a for loop which reads each character in the string and if that character is '\0' (0x00) replaces it with a space (0x20). Replace every 0x00 with 0x020 except for the last character in your string. The string you now pass to GrStringDraw() will always be the same length and the spaces will over write previous values. You may need to use a font with all characters a fixed size. Maybe not, if the string always has enough spaces on the end to over write the old characters.

    When I want to print floating numbers with "printf" versions that don't support floating point, I just break it into two numbers. I do the calculation as a float. I split the fraction into integer and fractional part with modf(). Then I multiply the fractional part by how many 10 to the number of decimal parts I want to display, such as "ui32_frac = f_frac * 100.0" for display down to hundredths. Then print the integer, a decimal point and then the integer that represents the fractional part.
  • Thanks Bob, good ideas. I'm trying to implement them now.