NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Support Forum » Problem with LCD
April 27, 2012 by HexManiac |
I've been playing with realtimeclock1.c and I'm having a few problems displaying numbers on the screen. What it boils down to is this... I added this to the original code to give me time in hours, minutes and seconds:
Then I tried displaying the result on the LCD like this:
This caused all sorts of problems, the numbers were really screwed up. But when I did this:
... it all works perfectly. Can anyone explain please? |
---|---|
April 27, 2012 by pcbolt |
Hex - That's pretty strange. I'd have to test the code to see what's going on...like trying %02d maybe, or using a "uint32_t" for totalseconds. |
April 28, 2012 by HexManiac |
Actually, I started out with %02d (signed decimal) but changed to %02u (unsigned decimal) when I first encountered problems, but it made no difference. I tried dumping (int32_t) the_time to the display (right-justified so I don't need to clear the old value)...
... the number displayed seems always to be between 32767 and -32768 (I'm guessing cos the numbers change too quick) although I know the actual value goes between 0 and 8639999. Displaying 8 and 16 bit numbers is not a problem, only 32 bit numbers, so it would seem to be an issue with your lcd library. Heh, I've only been a nerdkitter for a few weeks and already I'm helping! Wicked! |
April 29, 2012 by pcbolt |
Hex - The NK LCD library doesn't define the "fprintf" type functions, that's done in the AVR library inside "stdio.h". Your 2nd to last paragraph gave me a clue what was wrong. To print out "long" variables (i.e. 32-bit), you need to prefix either %d or %u with "l" (lower case "L"). So try this out...
Why it worked when you separated the statement out is still a mystery. |
April 29, 2012 by HexManiac |
Magic! All problems gone away now, thanks! |
Please log in to post a reply.
Did you know that a NerdKit can be used to build an iPhone-controlled R/C car? Learn more...
|