This code works ok:
Code: Select all
{Copyright Notice
This library for the SHT temperature and humidity sensors is based on the
application datasheet Sample Code humidity sensor SHTxx from Sensirion.
MikroPascal program for SHTxx sensor By Medrea Florin Andrei.
}
program SHT75_P16;
uses sensirion_lib_p16;
var NoError : boolean;
temperature, humidity,setpoint : real;
lcd_txt : string[20];
str:string[7];
temp: real; Absolute 0x60;
raw_array:array [0..3] of byte; absolute 0x60;
count: byte;
str_raw: string[17];
procedure init;
Begin
delay_ms(1000);
setpoint:= 60.0;
TRISA:=0;
Porta:=0;
CMCON := 7;
ADCON1 := 15;
Glcd_Init(PORTB, 2, 3, 4, 5, 7, 6, PORTD); //EasyPIC3
Glcd_Fill(0xAA);
Glcd_Set_Font(@FontSystem5x8, 5, 8, 32);
Glcd_Fill(0x00);
For count:= 0 to 3 do raw_array[count]:= Eeprom_read(count); //load min value from Eeprom
end;
begin
init;
sensirion_init(PORTC,0,1); //sensirion_init(port,data,clock);
while true do
begin
NoError := sensirion_get_temp_hum(temperature, humidity);
if NoError then
begin
If setpoint<humidity then Porta.0:=1 //Activate relay
else
Porta.0:=0;
lcd_txt := 'Temperature ';
Glcd_Write_Text(lcd_txt, 0, 0, 1);
FloatToStr(temperature, lcd_txt);
str:='';
Strncat(str,lcd_txt,5);
str:= str+'C';
Glcd_Write_Text(str, 0, 1, 1);
lcd_txt := 'Humidity ';
Glcd_Write_Text(lcd_txt, 0, 2, 1);
FloatToStr(humidity, lcd_txt);
str:='';
Strncat(str,lcd_txt,5);
str:=str + '%';
Glcd_Write_Text(str, 0, 3, 1);
if temperature<temp then //check for min Value
begin
temp:=temperature;
For count:= 0 to 3 Do Eeprom_write(count,raw_array[count]); //save value to Eeprom
FloatToStr(temp,str_raw);
str:='';
Strncat(str,str_raw,5);
Glcd_write_text(str,0,6,1);
end;
For count:= 0 to 3 do raw_array[count]:= Eeprom_read(count); //load min Value
FloattoStr(temp,str_raw);
str:='';
Strncat(str,str_raw,5);
Glcd_write_text(str,0,6,1);
end
else
begin
Glcd_Fill(0x00);
lcd_txt := 'ERROR READING SHTxx ';
Glcd_Write_Text(lcd_txt, 0, 4, 1);
end;
delay_ms(10000);
end;
end.
Code: Select all
{Copyright Notice
This library for the SHT temperature and humidity sensors is based on the
application datasheet Sample Code humidity sensor SHTxx from Sensirion.
MikroPascal program for SHTxx sensor By Medrea Florin Andrei.
}
program SHT75_P16;
uses sensirion_lib_p16;
var NoError : boolean;
temperature, humidity,setpoint : real;
lcd_txt : string[20];
str:string[7];
temp: real; Absolute 0x60;
raw_array:array [0..3] of byte; absolute 0x60;
count: byte;
str_raw: string[17];
procedure init;
Begin
delay_ms(1000);
setpoint:= 60.0;
TRISA:=0;
Porta:=0;
CMCON := 7;
ADCON1 := 15;
Glcd_Init(PORTB, 2, 3, 4, 5, 7, 6, PORTD); //EasyPIC3
Glcd_Fill(0xAA);
Glcd_Set_Font(@FontSystem5x8, 5, 8, 32);
Glcd_Fill(0x00);
For count:= 0 to 3 do raw_array[count]:= Eeprom_read(count); //load min value from Eeprom
end;
procedure display_values;
begin
lcd_txt := 'Temperature ';
Glcd_Write_Text(lcd_txt, 0, 0, 1);
FloatToStr(temperature, lcd_txt);
str:='';
Strncat(str,lcd_txt,5);
str:= str+'C';
Glcd_Write_Text(str, 0, 1, 1);
lcd_txt := 'Humidity ';
Glcd_Write_Text(lcd_txt, 0, 2, 1);
FloatToStr(humidity, lcd_txt);
str:='';
Strncat(str,lcd_txt,5);
str:=str + '%';
Glcd_Write_Text(str, 0, 3, 1);
end;
begin
init;
sensirion_init(PORTC,0,1); //sensirion_init(port,data,clock);
while true do
begin
NoError := sensirion_get_temp_hum(temperature, humidity);
if NoError then
begin
If setpoint<humidity then Porta.0:=1 //Activate relay
else
Porta.0:=0;
display_values;
if temperature<temp then //check for min Value
begin
temp:=temperature;
For count:= 0 to 3 Do Eeprom_write(count,raw_array[count]); //save value to Eeprom
FloatToStr(temp,str_raw);
str:='';
Strncat(str,str_raw,5);
Glcd_write_text(str,0,6,1);
end;
For count:= 0 to 3 do raw_array[count]:= Eeprom_read(count); //load min Value
FloattoStr(temp,str_raw);
str:='';
Strncat(str,str_raw,5);
Glcd_write_text(str,0,6,1);
end
else
begin
Glcd_Fill(0x00);
lcd_txt := 'ERROR READING SHTxx ';
Glcd_Write_Text(lcd_txt, 0, 4, 1);
end;
delay_ms(10000);
end;
end.
Does anybody know how to solve this?