[HELP] c code to count frequency pulses and display on LCD [8051/52]
Fri Feb 12 2010, 07:35 pm
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
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 ]
Sat Feb 13 2010, 01:43 am
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.
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
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
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, 04:17 pm
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
I made changes like this:
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
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:52 pm
To display the "RH%=" on the display.
And i EDITED the above post, please read it once
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
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 !
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 ]
Powered by e107 Forum System