Hi all ,
I 'm Minh .I come from Vietnam .I have just learned AVR for a short time and i ve got a problem ,i dont know how can i get out of this trouble .Can someone help me ?
I use Atmega16,LCD and DS18B20 .I want to send data from DS18B20 to LCD to display but It seems to be wrong in my code .Here is the code :
#asm
.equ __w1_port=0x1b
.equ __w1_bit=6
#endasm
#asm
.equ __lcd_port=0x15
#endasm
#include <lcd.h>
#include <ds18b20.h>
#include <delay.h>
#include <stdio.h>
#include <mega16.h>
char lcd_buffer[33];
#define MAX_DEVICES 8
unsigned char rom_code[MAX_DEVICES][9];
main()
{
unsigned char i,j,t1,devices;
PORTD=0x00;
lcd_init(16);
lcd_putsf("Using DS18B20 :");
delay_ms(1000);
lcd_clear();
devices=w1_search(0xf0,rom_code);
sprintf(lcd_buffer,"There are: \n %u DS18B20",devices);
lcd_puts(lcd_buffer);
delay_ms(2000);
if (devices)
{
for (i=0;i<devices;i++)
{
sprintf(lcd_buffer,"ROM code \nchip #%u :",i+1);
lcd_clear();
lcd_puts(lcd_buffer);
delay_ms(1000);
lcd_clear();
for (j=0;j<8;j++)
{
sprintf(lcd_buffer,"%02X ",rom_code[i][j]);
lcd_puts(lcd_buffer);
if (j==3) lcd_gotoxy(0,1);
};
delay_ms(1000);
};
}
else
while (1);
for (i=0;i<devices;)
if (!ds18b20_init(&rom_code[i++][0],20,30,DS18B20_12BIT_RES))
{
sprintf(lcd_buffer,"The device is\n not working #%u",i);
lcd_clear();
lcd_puts(lcd_buffer);
while (1);
};
while (1)
{
j=1;
for (i=0;i<devices;i++)
{
sprintf(lcd_buffer,"t%u=%+.0f\xdfC",j++,ds18b20_temperature(&rom_code[i][0]));
lcd_clear();
lcd_puts(lcd_buffer);
t1 = ds18b20_temperature(0);
if (t1<35||t1>13)
{
PORTD=0x00;
}
if (t1 >= 35) ;
{
PORTD=0x01;
}
if (t1 <= 13) ;
{
PORTD=0x02;
}
delay_ms(500);
};
};
}
Please help me ! I m so confuse about this .