Interface 16f887 with SHT11

General discussion on mikroC.
Post Reply
Author
Message
ananth.antony
Posts: 46
Joined: 21 Jan 2011 09:37
Location: United Arab emirates

Interface 16f887 with SHT11

#1 Post by ananth.antony » 18 Mar 2011 20:24

Hi all

i would like to interface PIC16f887 with SH11 Humidity& Temperature sensor and output the temperature reading on 2 X 16 LCD Display.
I wrote a source code and it displays the value "-37.44999" always.
Can anyone please check the code attached and advise.

Regards

Ananth

Code: Select all

#define SHT_READ   0b11111011;
#define SHT_WRITE  0b11111001;
                           //adr  command  r/w
#define STATUS_REG_W 0x06   //000   0011    0
#define STATUS_REG_R 0x07   //000   0011    1
#define MEASURE_TEMP 0x03   //000   0001    1
#define MEASURE_HUMI 0x05   //000   0010    1
#define RESET        0x1e   //000   1111    0
#define ACK 1
#define N0_ACK 0

const float C1=  -4.0 ;           // constant use for SHT1x Humidity Measurement
const float C2 = 0.0405 ;
const float C3 = -0.0000028 ;
const float d1 = -40.00;          // constant use for SHT1x Temperature Measurement
const float d2 = 0.01;
const float t1 = 0.01 ;           // constant use for SHT1x True Humidity Measurement
const float t2= 0.00008 ;

float tempt, humi;
float RH_linear, RH_true;

   //calculate temperature in Celsius from value
     //formula t = d1 + d2*SOt
         // tempt = d1C + (tempt * d2C);
         
         //calculate humidity %RH from value
     //formula RHlinear = C1 + C2*SOrh + C3*SOrh*SOrh  %RH
        //  RH_linear = C1 + (C2*humi) + (C3*humi*humi);
     //formula RHtrue = (Tc-25)*(t1+t2*SOrh)+RHlinear
        //  RH_true = (tempt-25)*(t1+(t2*humi))+ RH_linear;
        
//SHT11 connections
sbit SDA at RC4_bit;                     // Serial data pin
sbit SCL at RC3_bit;                     // Serial clock pin

sbit SDA_Direction at TRISC4_bit;        // Serial data direction pin
sbit SCL_Direction at TRISC3_bit;        // Serial clock direction pin  

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections



char *text;                          //
char temp[10];

void temp_read() {
I2C1_Start();
I2C1_Wr(0x03);
delay_ms(350);
tempt = I2C1_Rd(1);
delay_ms(10);
I2C1_Stop();


}
void temp_meas() {
tempt = d1 + (tempt * d2);
FloatToStr(tempt, temp);
}

void temp_disp() {
Lcd_Out(2,1,temp);               // Define the first message
Lcd_Out(2, 11, "C");

}

void main() {
ANSEL  = 0;                // Configure AN pins as digital I/O
  ANSELH = 0;

  I2C1_Init(100000);         // initialize I2C communication



Lcd_Init();                      // LCD display initialization
    Lcd_Cmd(_LCD_CURSOR_OFF);        // LCD command (cursor off)
    Lcd_Cmd(_LCD_CLEAR);             // LCD command (clear LCD)
    text = "Initializing...";       // Define the first message
    Lcd_Out(1,1,text);
    Delay_ms(1000);
    Lcd_Cmd(_LCD_CLEAR);
    text = "Temp&Humidity";       // Define the first message
    Lcd_Out(1,1,text);               // Write the first message in the first line
    Delay_ms(1000);
    text = "Proj by ANANTH";            // Define the second message
    Lcd_Out(2,1,text);               // Define the first message
    Delay_ms(1000);
    Lcd_Cmd(_LCD_CLEAR);



 while (1) {

 temp_read();
 temp_meas();
 temp_disp();
 delay_ms(500);
 Lcd_Cmd(_LCD_CLEAR);

 
}
}

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: Interface 16f887 with SHT11

#2 Post by tihomir.losic » 21 Mar 2011 16:35

Hello Ananth,

SHT1X Board is a development tool provided with a temperature and humidity sensor SHT11.
From this link you can download our examples for SHT1x board:
http://www.mikroe.com/eng/downloads/get ... c_v100.zip

I hope that it will help you.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

ananth.antony
Posts: 46
Joined: 21 Jan 2011 09:37
Location: United Arab emirates

Re: Interface 16f887 with SHT11

#3 Post by ananth.antony » 21 Mar 2011 20:29

Dear Losic

Thank you very much for the code. Why don't we write the code with MIKROC built in i2c Libraries. You haven't used any of the library. Can you please assist me writing this code with i2c library.

Thanks and Regards

Ananth

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: Interface 16f887 with SHT11

#4 Post by tihomir.losic » 22 Mar 2011 09:56

Hello Ananth,

Unfortunately, we do not have enough resources to help our users by writing them custom projects.
We are planning to expand our support by having a mikroE Workshop, as a kind of project section, that will develop
all kinds of useful projects, along with source codes and documentations, but it will take some time until we can go into realization of this idea.
In the meantime, we will do our best to expand our collection of examples, so you will have a better staring reference for coding.
You can, however, search throughout Forum where some pieces of our libraries are posted for viewing, so you could maybe find what you are looking for.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

Post Reply

Return to “mikroC General”