DS18B20, atmega644p zobrazení na LCD

Zdravím,
mám následující problém, avr mi na LCD vypíše pouze tuto hodnotu: t1=3f°C. Bohužel nevím, co ještě vyzkoušet. ds18b20_temperature je v knihovně definován jako float. Věděl by někdo, co s tím? Díky…

[code]
#include <mega644p.h>

// 1 Wire Bus interface functions
#include <1wire.h>

// DS1820 Temperature Sensor functions
#include <ds18b20.h>

#include <delay.h>
#include <stdio.h>

// maximum number of DS1820 devices
// connected to the 1 Wire bus
#define MAX_DS18B20 8
// number of DS1820 devices
// connected to the 1 Wire bus
unsigned char ds18b20_devices;
// DS1820 devices ROM code storage area,
// 9 bytes are used for each device
// (see the w1_search function description in the help)
unsigned char ds1820_rom_codes[MAX_DS18B20][9];

// Alphanumeric LCD Module functions
#include <alcd.h>

// Declare your global variables here
char lcd_buffer[33];

void main(void)
{
unsigned char i,j;

lcd_init(16);
lcd_putsf(“CodeVisionAVR\n1 Wire Bus Demo”);
delay_ms(2000);
lcd_clear();

/* detect how many DS18B20 devices
are connected to the 1 Wire bus */
ds18b20_devices=w1_search(0xf0,ds1820_rom_codes);
sprintf(lcd_buffer,"%u DS18B20\nDevice detected",ds18b20_devices);
lcd_puts(lcd_buffer);
delay_ms(2000);

/* display the ROM codes for each device /
if (ds18b20_devices)
{
for (i=0;i<ds18b20_devices;i++)
{
sprintf(lcd_buffer,“Device #%u ROM\nCode is:”,i+1);
lcd_clear();
lcd_puts(lcd_buffer);
delay_ms(2000);
lcd_clear();
for (j=0;j<8;j++)
{
sprintf(lcd_buffer,"%02X ",ds1820_rom_codes
[j]);
lcd_puts(lcd_buffer);
if (j==3) lcd_gotoxy(0,1);
};
delay_ms(5000);
};
}
else
while (1); /* stop here if no devices were found */

/* configure each DS18B20 device for 12 bit temperature
measurement resolution /
for (i=0;i<ds18b20_devices;)
if (!ds18b20_init(&ds1820_rom_codes
[0],20,30,DS18B20_12BIT_RES))
{
sprintf(lcd_buffer,“Init error for\ndevice #%u”,i);
lcd_clear();
lcd_puts(lcd_buffer);
while (1); /* stop here if init error */
};

/* measure and display the temperature(s) /
while (1)
{
j=1;
for (i=0;i<ds18b20_devices;i++)
{
sprintf(lcd_buffer,“t%u=%+.3f\xdfC”,j++,ds18b20_temperature(&ds1820_rom_codes
[0]));
lcd_clear();
lcd_puts(lcd_buffer);
delay_ms(500);
};
};
}
[/code]***

Bude potřeba nějak přesvědčit překladač aby vložil plnotučnou sprintf. Ovšem s CV neporadim.
Tady https://forum.mcontrollers.com/t/multiplexovany-vystup-na-displej/167/1 jsme s johnnem nakonec dobili modul pro DS18B20 do celočíselný podoby pokud bys měl zájem. Není to tam sice v jednom místě ke stažení, ale dá se to z diskuze poskládat.

takže je problém v tom přeložení výpisu hodnoty ve floatu? Z té vaší debaty s johnnem nejsu moc moudré… :-/ co přesně kde bych měl upravit?

Pokud zůstaneme ve floatu, dá se tam najít toto:

[code]#include <math.h> // pro funkci trunc()
#include <stdio.h> // pro funkci sprintf()volatile char str[10];
volatile float adc_read = 27.325;

int d1 = (int)adc_read;
int d2 = (int)trunc((adc_read - d1) * 10);

sprintf ((char *)str, “%d.%01d%”, d1, d2);[/code]
“adc_read” si přejmenuj a načti do ní hodnotu z teploměru.

Ha!!! Tak problém vyřešen. Opravdu byl problém v tom překladu. Kdyby to někdo řešil, tak je to v Project-Configure-C Compiler a tam je potřeba nastavit printf() na float. Obrázek snad řekne vše:

img819.imageshack.us/img819/1011 … ttings.jpg

:arrow_right: administrator: příspěvek byl upraven

:arrow_right: administrator: přiloženy externí soubory

ok, díky. Nějak sem to přehlídl. Taky zkusím. Ještě jednou díkec za pomoc :wink:

přesně tohle jsem řešil před 14 dny a celý den, pak jsem ze zoufalosti zabrousil do toho Configure C Compiler…

Ahoj, můžeš, prosím poslat schéma, při kterém ti to funguje? řeším nedetekci čidel na ATMega32 a už jse zkusil snad vše:( Dík.

viz tadyk:
https://forum.mcontrollers.com/t/atmega32-a-ds18x20-shanim-funkcni-priklad-vcetne-zapojeni/1808/2