Discussion in "General help Guidance and Discussion" started by    firoz3321    Feb 12, 2010.
Tue Feb 16 2010, 06:43 pm
#11
Today, finally and successfully obtained the OUTPUT on the Proteus.

Instead of using the Humidity formula (which didnt give expected values), managed to write the following simple code:

#include<reg51.h>

// code to count number of pulses at port p1.1 when input p1.2 is enabled
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;
     timeout=1;
	 ET1 = 0;
     }    
}
void main()
{   
    unsigned char comm[] = {0x38,0x0E,0x01,0x06,0x80,0};
	unsigned char DTa[30]="RH% = 0";
	unsigned char DTb[30]="Read Error @";
    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;

	   while(timeout!=1)
    {
        c=freqOut;
        if(c==1)
        {
            if(flag==0)
            {
                count = count+1;
                flag=1;
            }
        }
        else flag=0;
    }
for(i=0;comm[i]!=0;i++)
	    {	 
		     lcdcmd(comm[i]);
		} 

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

y=y+48;
z=z+48;



for(i=0;DTa[i]!='0'; i++)
		{
			lcddata(DTa[i]);
		 }

lcddata(y);
lcddata(z);
lcddata(37);
}

if(count<5000||count>
10000)
{
for(i=0;DTb[i]!='@'; i++)
		{
			lcddata(DTb[i]);
		 }
}
}



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++);
}

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ThomasGaxaW
Mon May 13 2024, 05:33 pm
RobertInfup
Mon May 13 2024, 04:28 pm
Joshuatem
Mon May 13 2024, 08:30 am
RaymondPex
Mon May 13 2024, 03:24 am
Kennethbycle
Sun May 12 2024, 03:12 pm
MumerMeags
Sun May 12 2024, 01:47 pm
IsaacZor
Sun May 12 2024, 11:26 am
DavidInomy
Sun May 12 2024, 09:03 am