Discussion in "General help Guidance and Discussion" started by    firoz3321    Feb 12, 2010.
Fri Feb 12 2010, 07:35 pm
#1
Regarding the GreenBee project i'm trying to count the pulses of frequency and and display the HUMIDITY by calculating from the Count.

Please Help.

Our Sir helped with the code. But he is too busy these days.
The LCD shows some random symbols ( i'm simulating on PROTEUS )

Fromula taken from HERE

#include<reg52.h>

// code to count number of pulses at port p1.1 when input p1.2 is enabled
sbit freqOut = P2^1;
sbit hummidityKey = P2^2;
sfr ldata=0x90;
//sfr count=  0xa0;
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)  //10,000    // 0.1m*10000=1sec
    {              
     timeCount=0;
     timeout=1;
	 ET1 = 0;
     }    
}
void main()
{   
    unsigned char comm[] = {0x38,0x0E,0x01,0x06,0x80,0};
	unsigned char DTa[30]="RH% = 0";
    unsigned int count=0;     		    //count=0x00;
    bit c=0,flag=0;
	int Offset = 7709; 	 				// HH10D module 1 calibration constant	
	unsigned int axefactr;		   	    //
    int Sens = 341;					    // HH10D module 1 calibration constant 
	unsigned int RH,diff,Soh,i;				     //
    unsigned int  z,x,d,e;
	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;

	 for(i=0;comm[i]!=0;i++)
	    {	 
		     lcdcmd(comm[i]);
		} 
    // hummidityKey =0;
   ///if(hummidityKey==1)
    while(timeout!=1)
    {
        c=freqOut;
        if(c==1)
        {
            if(flag==0)
            {
                count = count+1;
                flag=1;
            }
        }
        else flag=0;
    }
z=count;	
Soh=count;
diff = Offset - Soh;
axefactr = (diff / 19) + 1;    // a factor to prevent number roll over error (ie >
65535)
RH = 10 * diff / axefactr * Sens ;// intermediate result (multiply by 10 is to enable 0,1 resolution later if required)
axefactr = 4096/axefactr;   // a factor to prevent number roll over error
RH = RH / axefactr;         // final value for RH%
RH = RH / 10; 	               // divide by 10 (for now) as not transmitting fractional part only whole RH

msdelay(50);
lcdcmd(0x01);
lcdcmd(0x80);

for(i=0;DTa[i]!='0'; i++)
		{
			lcddata(DTa[i]);
		}	
												 
 lcdcmd(0x38);
 lcddata(RH);
x=RH/10;
x=x+30;
lcddata(z);
 
 }
void lcdcmd(unsigned char value)
{
ldata=value;
rs=0;
rw=0;
en=1;
msdelay(1);
en=0;
return;
}
void lcddata(unsigned char value1)
{
ldata=value1;
rs=1;
rw=0; 
en=1;
msdelay(1);
en=0;
return;
}
void msdelay(unsigned int itime )
{
unsigned int i, j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}


[ Edited Fri Feb 12 2010, 07:40 pm ]
Fri Feb 12 2010, 08:09 pm
#2
PROTEUS DESIGN Attached
Attachment
Sat Feb 13 2010, 01:43 am
#3
You need to test your code one chunk at a time.
Create programs with fixed values and see if they display correctly.

Send a known value to the display.
If okay, input a known value to the humidity conversion code..does it display correctly ?.

Work back until you find what does not work.
 firoz3321 like this.
Sat Feb 13 2010, 02:30 pm
#4
First of all, I need to know how to pass the Integer to the LCD.

I believe that the PULSE count is more than the OFFSET (7709), so subtracting COUNT from OFFSET must be giving negative value.

Doesn't Keil uVision support the CEIL command ? like C does ?

And if the FINAL RH value is some 3digit or 2 digit value, how do i pass it to the LCD ?

I cant even check the value of COUNT in proteus.

Please HELP
Mon Feb 15 2010, 03:53 pm
#5
why dont you link keil with proteus and then debug it?

you need to get digits one by one,
num = 123

first = num/100;
num = num%100;
second = num/10;
num = num%10;
third = num;

simple?
 firoz3321 like this.
Mon Feb 15 2010, 04:17 pm
#6


why dont you link keil with proteus and then debug it?

Ajay Bhargav



LINK ?

HOW ?

I'm new to both Keil and proteus, please let me know .

And about the Numbers, is it that simple ?
for a 4 digit i need to divide by 1000 ?
Wow, thank you, and did you see the code ?

Does it really suffice the requirement ?

Mon Feb 15 2010, 04:38 pm
#7
I made changes like this:
x=RH/100;
RH=RH%100;
y=RH/10;
RH=RH%10;
z=RH;
for(i=0;DTa[i]!='0'; i++)
		{
			lcddata(DTa[i]);
		}	
x=x+48;
y=y+48;
z=z+48;												 
lcddata(x); 
lcddata(y);
lcddata(z);


Oh K, now i get 3 digits first i added 30 but after changing to 48 i get the digits.
But i need to get only between 0 to 100.

I set the freq to 900Hz and i got 954 on display

As i increase the frequency, the Display value (RH) is decreasing

For 1.17Khz = 031
For 1.19Khz = 000

And beyond 1.19Khz everything is 000

the sensor i'm going to use, gives 5Khz to 10Khz

Please help me


[ Edited Mon Feb 15 2010, 04:49 pm ]
Mon Feb 15 2010, 04:46 pm
#8
what is this for?
for(i=0;DTa[i]!='0'; i++)
                {
                        lcddata(DTa[i]);
                }   
  
Mon Feb 15 2010, 04:52 pm
#9
To display the "RH%=" on the display.
unsigned char DTa[30]="RH% = 0";


And i EDITED the above post, please read it once


[ Edited Mon Feb 15 2010, 04:53 pm ]
Mon Feb 15 2010, 05:01 pm
#10
As i increase the Frequency beyond the KHz, i get Albhabets and symbols.

I think the COUNT value is going beyond the OFFSET (which is set to 7709, i dont know WHY)

So OFFSET-Count is giving a negative value ( i suppose)

Also please let me know what you meant by LINKING KEIL with PROTEUS.

I gave the path of HEX file to PROTEUS, so i compile the code and simulate the proteus without the need of dumping or showing the path all the time.

Is it what you meant by LINKING ?

or any better or simple technique available ?

Help me please !


[ Edited Mon Feb 15 2010, 05:12 pm ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am