using DS18B20 with ATmega16

Status
Not open for further replies.

motupakhi

New Member
hi,
i am very beginner with micro-controller. i am a student. i have got a project where i have to use DS18B20 temperature sensor with ATmega16 and ring a buzzer for a specific temperature . i want to use MikroC for writing c code for this work. please , help me with this. i don't know how get data from DS18B20 & process it with atmega16... plz... help me with C code ASAP...

-motupakhi
 
You know, the DS18B20 is a 1wire chip.
AVR Controllers doesn't support the 1wire Interface with embedded Hardware.
Only a software solution is possible.
When searching for the term "1wire avr library" You should find some librarys in the Internet for that Chip.
E.g. that one: **broken link removed**
 
Last edited:
hi..
I've got a c code in which DS18B20 is used with ATmega16. but here, they display temperature into a lcd display. but i just want to light a led when the sensor sense a specific temperature... how can i change this code.. please help me...
here is the code:

#include<mega16.h>
#include<delay.h>
#include<stdlib.h>
#include<string.h>

/*#asm
.equ __lcd_port=0x1b //for lcd display
#endasm
#include <lcd.h>
#define uchar unsigned char
//char flash string[]="date:";
//char flash s[]="time:";
char flash s1[]="wendu:" ;
//char flash s2[]="\xdfC" ;
char tempstr[5];
//char s3[]="set tempature";
//char s4[]="temparature is" ;
//char s5[]="too high"; */

#define QD_PORT PORTC
#define QD_DDR DDRC
#define QD_PIN PINC
#define QD_H QD_PORT|=0x01 //PC0??
#define QD_L QD_PORT&=~0x01 //??
#define QD_DDRL QD_DDR&=~0x01
#define QD_DDRH QD_DDR|=0x01
float tempa ;
/*void lcd_xianshiflash(uchar x,uchar y,char flash *string)
{
lcd_gotoxy(x,y);
lcd_putsf(string);
} */
void b20_init(void) //???
{

QD_DDRH;
QD_H;
delay_us(4);
QD_L;
delay_us(500);
QD_H;
QD_DDRL; delay_us(5);
while(QD_PIN&0x01);
while(!QD_PIN&0x01);
QD_DDRH;
QD_H;
delay_us(20);
}
void b20_write_byte(uchar data) //????
{
uchar i;
for(i=0;i<8;i++)
{
if(data&0x01)
{
QD_L;
delay_us(7);
QD_H;
delay_us(55);
}
else
{
QD_L;
delay_us(60);
QD_H;
delay_us(8);
}
data=data>>1;
}
}
uchar b20_read_byte(void) //????
{
uchar data,i;
data=0x00;
for(i=0;i<8;i++)
{
QD_L;
delay_us(5);
QD_H;
delay_us(2);
if(QD_PIN&0x01)
{
data|=(0x01<<i);
}
delay_us(45);
}
return (data);
}
void b20_write_command(uchar command)
{
b20_init();
delay_ms(1);
b20_write_byte(0xCC);
b20_write_byte(command);
}
void b20_read_temparater(void)
{


int temp;
uchar templ,temph;

b20_write_command(0x44);//??????
b20_write_command(0xBE);//??????CRC??
templ=b20_read_byte();
temph=b20_read_byte();//???
lcd_gotoxy(1,1);
lcd_puts(0);
if(temph&0x80)
{
temp=temph;
temp=(temp<<8)|templ;
temp=(-1)*temp;
lcd_gotoxy(9,1);
lcd_putchar('-');
}
else {
temp=temph;
temp=(temp<<8)|templ;
}
tempa=(temp>>4)+(temp&0x0F)/16.0;


}
void main()
{

if(lcd_init(16))
{
lcd_clear();
while(1)
{
b20_read_temparater();
ftoa(tempa,1,tempstr);
lcd_gotoxy(0,0);
lcd_putsf(s1);
lcd_gotoxy(10,0) ;
lcd_puts(tempstr) ; //?????????????????????SRAM?????
delay_ms(1000);
}
}
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…