### 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 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 else interval = 884955; // 15 min return interval; . . a bunch of other junk . . . // write message to LCD lcd_home(); lcd_write_string(PSTR("Interval Mode: ")); lcd_line_two(); lcd_write_int16(x); lcd_write_string(PSTR(" of 1024 ")); lcd_line_three(); fprintf_P(&lcd_stream, PSTR("Delay: ")); lcd_write_int16(interval); 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? 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 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. Thanks, Chris! It works perfect now!