free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Rickey's World :: Discussion Forums :: Discuss and Learn :: 8051 Discussion Forum
 
<< Previous thread | Next thread >>
Help with HUMIDITY SENSOR"HOPE RF HH10D"
Go to page   <<      
Moderators: Ajay Bhargav, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph, ExperimenterUK, DavesGarage
Author Post
firoz3321
Sun Feb 28 2010, 08:29PM
 User Offline
Registered Member #24995
Joined: Thu Jan 07 2010, 03:12AM

Posts: 59
Thanked 0 times in 0 posts
I BOUGHT HH10D sensor from here :
http://www.sunrom.com/index.php?main_page=product_info&products_id=758

It cost me Rs.650 INR. I googled for HIH-4000-001 and the price was Rs.2000 INR so opted for HH10D.

As for the CODE, YES i managed to get it to work. But its not the RIGHT way of using the sensor. The RIGHT way is to use the I2C Bus and read the values from EEPROM on the sensor.

But i never succeeded in the MENTIONED formula usage.

So i finally managed in getting the OUTPUT by i technique.

This is my code, written in C :

CODE:
#include<reg51.h>
sbit freqOut = P2^1;
sfr ldata=0x90;
bit timeout;
unsigned int timeCount;
void lcdcmd(unsigned char value);
void msdelay(unsigned int value);
void lcddata(unsigned char value1);
sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^2;
void timer0_isr(void) interrupt 3
{
    timeCount= timeCount+1;
    if(timeCount==10000)    // 0.1m*10000=1sec
    {              
        timeCount=0;            // Reset the TimeCount after every 1 Second
        timeout=1;                      // Set the timeout=1 ( variable to start the Pulse count in the While loop)
                ET1 = 0;
     }    
}

void main()
{  
    unsigned char comm[] = {0x38,0x0E,0x01,0x06,0x80,0};
        unsigned char DTa[30]="RH% = @";
        unsigned char DTb[30]="Err @";
        unsigned int count=0;                       //count=0x00;
        bit c=0,flag=0;
        unsigned int  i,d,y,z;
        P1=0xff;
        timeout=0;
        timeCount=0;
        TMOD = 0x20;                                    // Set Mode (8-bit timer0 with reload)     (.1m/1.085u)=92.16=256-n =>n= 163.83=164d= A4
        TH1 = 0xA4;                     // Reload TL1 to count 100 clocks
        TL1 = TH1;
        ET1 = 1;                                // Enable Timer 1 Interrupts
        TR1 = 1;                        // Start Timer 1 Running
        EA  = 1;

//Counting the Pulses:

while(timeout!=1)
{
  c=freqOut;
  if(c==1)
    {
      if(flag==0)
        {
         count = count+1;
         flag=1;
        }
    }

  else flag=0;
}

//Initialising the LCD:

for(i=0;comm[i]!=0;i++)
   {     
     lcdcmd(comm[i]);
   }


//Checking the Humidity Limits:
//LOGIC:
//RH% ranges from 0 to 100 through 5k to 10k freq.. So change in freq = 5K.
//5K/100 = 50. So for every increment of freq count by 50, there is one increment in RH value in %


if (count>4999 && count<10001)  // Limiting the calculations to the desired limits of 5k to 10k)
{
d=count-5000;           // Obtaining the Difference in the Freq.
d=d/50;                         // Divide with 50 to get the RH value  

y=d/10;                         // obtaining the tens position integer and assigning to variable y
z=d%10;                         // Modulo Division to obtain the Remainder value (the ONEs place) and Assigning the value to variable z
                               
y=y+48;                         // converting the integer to its equivalent ASCII code
z=z+48;                         // converting the integer to its equivalent ASCII code



for(i=0;DTa[i]!='@';i++)      
  {
   lcddata(DTa[i]);             // passing the data "RH% =" to the LCD
  }    

lcddata(y);                             // passing the value of y to the LCD
lcddata(z);                             // passing the value of z to the LCD
lcddata(37);                    // passing the symbol "%" using its ASCII code (37) to the LCD
}


if(count<5000 || count>10000)   // If the Freq. is below 5k or greater than 10k ERROR message is displayed
  {
        for(i=0;DTa[i]!='@';i++)      
                {
                 lcddata(DTa[i]);               // passing the data "RH% =" to the LCD
                }

        for(i=0;DTb[i]!='@'; i++)
                {
                 lcddata(DTb[i]);               // passing the data "Err" to the LCD
                }                                                                                                                        
  }

}


//LCD Functions:

void lcdcmd(unsigned char value)  // LCD Commands
{
ldata=value;
rs=0;
rw=0;
en=1;
msdelay(1);
en=0;
return;
}
void lcddata(unsigned char value1) // Data to CLD
{
ldata=value1;
rs=1;
rw=0;
en=1;
msdelay(1);
en=0;
return;
}
void msdelay(unsigned int itime ) // Delay
{
unsigned int i, j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}



This code is written to test it on the LCD



[ Edited Mon Mar 01 2010, 06:03AM ]

Regards,
Feroze
Back to top

ExperimenterUK
Sun Feb 28 2010, 10:31PM
 User Offline
Registered Member #9602
Joined: Tue Aug 05 2008, 04:15PM

Posts: 1251
Thanked 199 times in 198 posts
firoz3321 wrote ...

As for the CODE, YES i managed to get it to work. But its not the RIGHT way of using the sensor. The RIGHT way is to use the I2C Bus and read the values from EEPROM on the sensor.

Measuring the frequency is the right way to use this sensor.
The EEPROM only contains calibration data and is only for that one device.
They could, perhaps should, have written it on a lable.

firoz3321 wrote ...

// code to count number of pulses at port p1.1 when input p1.2 is enabled

Why does pin p1.2 have to be enabled ?.
Back to top

firoz3321
Mon Mar 01 2010, 06:07AM
 User Offline
Registered Member #24995
Joined: Thu Jan 07 2010, 03:12AM

Posts: 59
Thanked 0 times in 0 posts
ExperimenterUK wrote ...

Measuring the frequency is the right way to use this sensor.
The EEPROM only contains calibration data and is only for that one device.
They could, perhaps should, have written it on a lable.


Well there is a HUGE formula. And i suppose its the proper way of getting it done.

ExperimenterUK wrote ...

Why does pin p1.2 have to be enabled ?.




Well i removed the comment now

Actually i was using that pin for a toggle switch so that i can start the count.
Now i removed it ( Later realised there was no use of it ).

Regards,
Feroze
Back to top

firoz3321
Mon Mar 01 2010, 06:17AM
 User Offline
Registered Member #24995
Joined: Thu Jan 07 2010, 03:12AM

Posts: 59
Thanked 0 times in 0 posts
is there any easy way of converting the C code to ASM ?

I'm not able to make it done. How to count 10000 ? it doesn't take it
CODE:


#include<reg52.h>
sbit freqOut = P3^6;
bit timeout;
unsigned int timeCount;

void timer0_isr(void) interrupt 3
{
    timeCount= timeCount+1;

    if(timeCount==10000)    
    {              
        timeCount=0;           
        timeout=1;                     
        ET1 = 0;
     }    

}

void main()
{  
        unsigned int count=0;                       //count=0x00;
        bit c=0,flag=0;
        unsigned int  d,y,z;
        timeout=0;
        timeCount=0;
        TMOD = 0x20;           
        TH1 = 0xA4;        
        TL1 = TH1;
        ET1 = 1;            
        TR1 = 1;            
        EA  = 1;

//Counting the Pulses:

while(timeout!=1)
{
c=freqOut;

if(c==1)
  {
     if(flag==0)
        {
          count = count+1;
          flag=1;
        }
  }

else flag=0;

}


if (count>4999 && count<10001)
        {
          d=count-5000;                
          d=d/50;                              
          y=d/10;                              
          z=d%10;                              
        }
                                                                                               
}
 


Please help me to code this to ASM !!

I want to embed this code in to the original GreenBee Code !!

Time is very less


[ Edited Mon Mar 01 2010, 06:20AM ]

Regards,
Feroze
Back to top

ExperimenterUK
Mon Mar 01 2010, 10:35AM
 User Offline
Registered Member #9602
Joined: Tue Aug 05 2008, 04:15PM

Posts: 1251
Thanked 199 times in 198 posts
firoz3321 wrote ...

is there any easy way of converting the C code to ASM ?

I doubt it, but this code is not complicated so someone used to ASM could do it
quite quickly.
You can simplify it by counting for 20 milliseconds rather than 1000 milliseconds.
This will save dividing by 50 later.

firoz3321 wrote ...

I'm not able to make it done. How to count 10000 ? it doesn't take it

Does it work at 9000,9999... ? where does it go wrong ?

Can you attach a copy of the full Greenbee program you are trying to patch into.


Back to top

Go to page   <<       

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems