NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Writing Big Numbers to the LCD

November 23, 2009
by FWSquatch
FWSquatch's Avatar

I've got a project that I'm trying to debug through the LCD. It is supposed to be writing the interval in ms that the MCU is supposed to wait before going to the next thing. Sometimes this number is pretty big (6 digits) and for some reason, I can't get the LCD to write it out correctly. I suspect it has to do with what type of variable I am using, but I've tried a few different types and I can't figure it out. Here is relevant code:

     long int interval;
     if( x <= 128 )
       interval = 29499; // 30 sec
     else if( x <= 256 )
       interval = 58997; // 1 min
     else if( x <= 384 )
       interval = 117994; // 2 min
     else if( x <= 512 )
       interval = 176991; // 3 min
     else if( x <= 640 )
       interval = 235998; // 4 min
     else if( x <= 768 )
       interval = 294985; // 5 min
     else if( x <= 896 )
       interval = 589970; // 10 min 
       interval = 884955; // 15 min
     return interval;
     a bunch of other junk
      // write message to LCD
      lcd_write_string(PSTR("Interval Mode: "));
      lcd_write_string(PSTR(" of 1024   "));
      fprintf_P(&lcd_stream, PSTR("Delay: "));
      lcd_write_string(PSTR(" ms"));

Here is what I get. As you can see, it's giving me some random negative number when it should be showing 235998. Does anyone know what I'm doing wrong? You can see this closer on my Flickr page:

November 24, 2009
by n3ueaEMTP
n3ueaEMTP's Avatar

FWSquatch, I have been having the same problem. I posed the same question in this other thread, it should answer your question.

Chris B, n3ueaEMTP

November 24, 2009
by tech20
tech20's Avatar

it's a problem with memory i think, the integer is to large to display correctly since the function is for 16 bit integers, unsigned. You may have to make a function to support it, or use smaller numbers :P.

November 24, 2009
by FWSquatch
FWSquatch's Avatar

Thanks, Chris! It works perfect now!

Post a Reply

Please log in to post a reply.

Did you know that multiple microcontrollers can communicate with each other? Learn more...