Tuesday 15 September 2015

floating point - How to display float value on LCD 16x2 -



floating point - How to display float value on LCD 16x2 -

i want display float value on lcd. have using avr5.1 compiler , using function snprintf convert float value ascii. gives output on proteus "?".

here code using; have include library of printf_flt:

temp1=adch; // measuring voltage temp=(temp1*19.53)*2.51; lcd_goto(1,1); snprintf(buffer,6, "%2.2f", temp); lcd_data1(buffer); lcd_data1("mv"); percent=(temp-11500); lcd_goto(2,2); snprintf(buffer1,4, "%2.2f", percent); lcd_data1(" "); lcd_data1(buffer1); lcd_data1("%");

here image of output:

many development tools have multiple versions of printf , related functions, back upwards differing levels of capabilities. floating-point math code bulky , complicated, including features aren't used waste lot of code space.

some tools automatically seek figure out options need included, aren't , require programmer explicitly select appropriate printf version using command-line arguments, configuration files, or other such means. may necessary create compiler include version of printf-related functions supports %f specifier, or else utilize other means of formatting output. own preferred approach convert value scaled integer (e.g. 100x desired value) , write method output digits, least-significant first, , insert period after outputting number of digits. like:

uint32_t acc; uint8_t divmod10() { uint8_t result = acc % 10; acc /= 10; } // output value in acc using 'digits' digits, decimal point shown after dp. // if dp greater 128, don't show decimal point or leading zeroes // if dp less 128 greater digits, show leading zeroes void out_number(uint8_t digits, uint8_t dp) { acc = num; while(digits-- > 0) { uint8_t ch = divmod10(); if (ch != 0 || (dp & 128) == 0) out_lcd(ch + '0'); else out_lcd(ch); if (--dp == 0) out_lcd('.'); } }

since lcd modules can configured receive info right-to-left, outputting numbers in form can useful simplification. note seldom utilize "printf"-family functions on little microcontrollers, since code above much more compact.

floating-point digital floating-point-conversion circuit circuit-diagram

No comments:

Post a Comment