ds1820 always shows 85 degree

ddewashish

New Member
iam using pic16f877A to controll temperture..
but ds1820 always shows 85 degree. the code is written in mikroc..
code is below....

................................................................................
.......................
.................................................



unsigned short j=0x0045;
unsigned int i=0;
char text_int[7],text_fra[7];
char dis_ch1[]="WARNING",dis_ch2[]="....HOT",dis_ch3[]="COMFORT";
char dis_ch4[]="...COOL",dev_n_p[]=".SENSOR REMOVED.";
int negt,dis2;
unsigned temp=0xffff;
char dflt[]= "TEMP:";
int not_p=0;
void lcd_command(unsigned char );
void lcd_data_dis(unsigned char );
void Display_Temperature();
void lcd_disp();
void lcd_initialise();
void not_present();


void lcd_disp()
{ lcd_command(0x80);
i=0;
while(dflt!='\0' )
{
lcd_data_dis(dflt);
i++;
}

//display text_int and text_fra in 1st row only..
//as temp : "text_int"."text_fra"*c

i=0 ;

lcd_command(0x85);

if(negt==1)
{ lcd_data_dis('-'); }
else
{ lcd_data_dis(' '); }

i=0;
while(text_int!='\0')
{
if(text_int!=' ')
lcd_data_dis(text_int);

i++;
}


lcd_data_dis('.');

i=0;
while(text_fra!='\0')
{
if(text_fra!=' ')
lcd_data_dis(text_fra);
i++;
}

lcd_data_dis(223);
lcd_data_dis('C');


lcd_command(0xc0);
if(PORTD.F4==1)
{

lcd_data_dis('A');
lcd_data_dis('C');
lcd_data_dis(' ');
lcd_data_dis(' ');
lcd_data_dis(' ');
lcd_data_dis(' ');
}
else if(PORTD.F3==1)
{
lcd_data_dis('H');
lcd_data_dis('E');
lcd_data_dis('A');
lcd_data_dis('T');
lcd_data_dis('E');
lcd_data_dis('R');
}

lcd_command(0XC9);

switch(dis2)
{
case 1:
i=0;
while(dis_ch1!='\0')
{
lcd_data_dis(dis_ch1);
i++;
}
break;
case 2:
i=0;
while(dis_ch2!='\0')
{
lcd_data_dis(dis_ch2);
i++;
}
break;
case 3:
i=0;
while(dis_ch3!='\0')
{
lcd_data_dis(dis_ch3);
i++;
}
break;
case 4:
i=0; while(dis_ch4!='\0')
{
lcd_data_dis(dis_ch4);
i++;
}
break;



default :
i=0;
while(dis_ch1!='\0')
{
lcd_data_dis(dis_ch1);
i++;
}
break;


}
}


void lcd_initialise()
{

//initialise lcd with command
lcd_command(0x38);
lcd_command(0x01);
lcd_command(0x06);
lcd_command(0x0E);
lcd_command(0x0C);
}

void lcd_command(unsigned char value)
{
PORTD.F0=0;
PORTD.F1=0;
PORTB=value;
PORTD.F2=1;
delay_ms(10);
PORTD.F2=0;
}

void lcd_data_dis(unsigned char value)
{
PORTD.F0=1;
PORTD.F1=0;
PORTB=value;
PORTD.F2=1;
delay_ms(10);
PORTD.F2=0;
}


void Display_Temperature()
{
unsigned int temp_whole, temp_fraction;



temp_fraction = temp & 0x0001;
temp_fraction = temp_fraction * 5;

temp_whole = temp;

// Is temperature negative?

if ((temp_whole & 0x8000) != 0u)
{ negt=1; }

else
{ negt=0; }

temp_whole=temp_whole & 0x00FF;
temp_whole >>= 1;




//test condition for AC, heater and alarm

if (temp_whole>=40||temp_whole<=8||negt==1)
{dis2=1;
PORTD.F5=1;
if(temp_whole>=40) {PORTD.F4=1;}
else PORTD.F4=0;
}
else if (temp_whole<40&&temp_whole>20)
{dis2=2;
PORTD.F4=1;
PORTD.F5=0;
}
else if (temp_whole<=20&&temp_whole>16)
{dis2=3;
PORTD.F5=0;
PORTD.F4=1;
}
else if (temp_whole<=16&&temp_whole>8)
{dis2=4;
PORTD.F4=0;
PORTD.F5=0;
}

PORTD.F3=~PORTD.F4;

IntToStr(temp_whole, text_int);
IntToStr(temp_fraction, text_fra);
lcd_disp();

}

void not_present()
{

lcd_command(0X80); i=0;
while(dev_n_p!='\0')
{
lcd_data_dis(dev_n_p) ;
i++;
} lcd_command(0X01);
Delay_ms(500);

}

void main()
{
PORTC = 1;
TRISC = 1;
PORTB = 0;
TRISB = 0;
TRISD = 0;
PORTD = 0;


lcd_initialise();



do {

not_p=Ow_Reset(&PORTC,0);
if(not_p){not_present();}


else
{
Ow_Write(&PORTC,0,0xCC);
Ow_Write(&PORTC,0,0x44); // Issue command CONVERT_T
Delay_us(120);

Ow_Reset(&PORTC,0);
Ow_Write(&PORTC,0,0xCC);
Ow_Write(&PORTC,0,0xBE); // Issue command READ_SCRATCHPAD
Delay_ms(400);

j = Ow_Read(&PORTC,0); // Get temperature LSB
temp = Ow_Read(&PORTC,0); // Get temperature MSB
temp<<=8; temp += j;


Display_Temperature();}
Delay_ms(500);

} while (1);

}



................................................................................
..............................
......................................................
 
A reading of 85 is an error condition. I think you are not waiting long enough for the DS18S20 to do a temperature convert, it takes at least 750ms for a convert.

Eric
 
Back
Top