I wrote this program, but compiling it gives the following warning: Implicit declaration of function dtostrf. If I ignore the warning, the display always shows zero after decimal, even if I put an arbitrary value.
For example, when it should be showing 15.2, it shows 15.0.
Please advise. Thank you!
#include <avr/io.h> // special function registers #include <stdio.h> // sprintf() #define F_CPU 4000000 // 4MHz RC #include <util/delay.h> // _delay_xx() #include "lcd.h" // Fleury LCD library int readADC(char channel) { ADMUX = (3 << REFS0)|(1<<ADLAR)|(channel << MUX0); // VREF=2.56V, 8-bit, PA0. PA1 _delay_us(10); // allow multiplexer to settle ADCSRA |= (1<<ADSC); // Start Conversion while (ADCSRA & (1<<ADSC)); // wait for completion return ADCH; // 8-bit result because we use ADLAR } int main(void) { char channel, din[16], dout[16], finalTIN[5], finalTOUT[5], degree = 0xDF; int k, m, ind = 0, oud = 0, find = 0, foud = 0; float tempIN, tempOUT; ADCSRA = (1<<ADEN)|(7 << ADPS0); //div128 lcd_init(LCD_DISP_ON); lcd_clrscr(); lcd_puts("READING..."); while (1) { ind = 0, oud = 0, find = 0, foud = 0; for (k=1; k<11; k++) { channel = 0; ind = readADC(channel); _delay_ms(500); find = find + ind; } for (m=1; m<11; m++) { channel = 1; oud = readADC(channel); _delay_ms(500); foud = foud + oud; } lcd_clrscr(); tempIN = find/10; dtostrf(tempIN, 4, 1, finalTIN); sprintf(din, "ROOM TEMP:%s%cC", finalTIN, degree); lcd_gotoxy(0,0); lcd_puts(din); tempOUT = foud/10 //even if I write foud = 152, the output is 15.0 always. dtostrf(tempOUT, 4, 1, finalTOUT); sprintf(dout,"AQUARIUM:%s%cC", finalTOUT, degree); lcd_gotoxy(0,1); lcd_puts(dout); } }