Need to display unsigned int on LCD

I am using a RCM3600 with the following section of code;

costate
{
if (state1 == 1 || CHARGE1 == 1)
{
CHARGE1 = 1;
HBlcdSetCursor(10, 0);
CHARGE_TIME_1 = CHARGE_TIME_1 - 1;
HBlcdSetCursor(10, 0);
sprintf(time_string, “#1; %05d”, CHARGE_TIME_1);
HBlcdWrite(time_string);
HBpinOut(HB_BATT_1,1);
if (CHARGE_TIME_1 == 0)
{
CHARGE1 = 0;
CHARGE_TIME_1 = 54000;
HBlcdSetCursor(10, 0);
HBlcdWrite("#1; TC ");
HBpinOut(HB_BATT_1,0);
}
//waitfor(time_changed());
}
}

Charge_Time_1 is unsigned so it can count down from 54000 seconds, but on the display it appears as “*****” until it reaches ~32000 (did not keep an eye on it to see the exact value).

Any ideas as to why this is happening.

sprintf function is taking CHARGE_TIME_1 as a signed value. It tries to print “-11000” (or so). As this string has 6 digits (including “-”) and you specify %5d in sprintf, the function returns five “*”. Try to write %6d, instead.

That is because %d is for signed values, if you want unsigned, use %u instead. You can also use it with the long specifier (%lu) to do unsigned longs.