Displays Given Frequency Using Timer0 As Counter.
/**************************************
Project Name: Frequency Counter.
Developer: Tahir Ahmed.B
Contact: tahir2469@gmail.com
**************************************/
/*
This Program uses timer0 as counter and timer1 for sampling the given pulse for 1 second duration.
Since frequency is the no of pulses per second, the counter value for one second can be considered as the frequency.
*/
#include<reg51.h>
#include<stdio.h>
#include<math.h>
#include<lcd.h>//awailable as attachment
void timer();
void main()
{
unsigned int a=0;
float v,i,p,re,rr,root;
char idata b[10],s[10],q[10],r[10];
command_write(x);
v=230;
i=2;
p=v*i;
re=p*1.3856;
root=((re*re)-(p*p));
rr=sqrt(root);
while(1)
{
TMOD=0x15; //Select Counter0 and Timer1 both in 16 bit mode.
TR0=1; //Start Counter
timer(); //Sampling Time
TR0=0; //Stop Counter
a=(TH0<<8)|TL0; //Get the two 8 bit values from TH0 and TL0 and load it as a 16 bit
single_command(0x80);
sprintf(b,"F=%3dHz",a); //Display Frequency.
data_write(b);
single_command(0x88);
sprintf(s,"V=%3.1fV",v);
data_write(s);
single_command(0xc0);
sprintf(q,"I=%1.2fA",i);
data_write(q);
single_command(0xc8);
sprintf(r,"P=%3.1fW",p);
data_write(r);
TH0=0;
TL0=0;
}
}
void timer() //Timer1 for sampling.
{
int i;
for(i=0;i<108;i++)
{
TH1=0xdb;
TL1=0xff;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;
}
}
Code Available Here: Click Here
Project Name: Frequency Counter.
Developer: Tahir Ahmed.B
Contact: tahir2469@gmail.com
**************************************/
/*
This Program uses timer0 as counter and timer1 for sampling the given pulse for 1 second duration.
Since frequency is the no of pulses per second, the counter value for one second can be considered as the frequency.
*/
#include<reg51.h>
#include<stdio.h>
#include<math.h>
#include<lcd.h>//awailable as attachment
void timer();
void main()
{
unsigned int a=0;
float v,i,p,re,rr,root;
char idata b[10],s[10],q[10],r[10];
command_write(x);
v=230;
i=2;
p=v*i;
re=p*1.3856;
root=((re*re)-(p*p));
rr=sqrt(root);
while(1)
{
TMOD=0x15; //Select Counter0 and Timer1 both in 16 bit mode.
TR0=1; //Start Counter
timer(); //Sampling Time
TR0=0; //Stop Counter
a=(TH0<<8)|TL0; //Get the two 8 bit values from TH0 and TL0 and load it as a 16 bit
single_command(0x80);
sprintf(b,"F=%3dHz",a); //Display Frequency.
data_write(b);
single_command(0x88);
sprintf(s,"V=%3.1fV",v);
data_write(s);
single_command(0xc0);
sprintf(q,"I=%1.2fA",i);
data_write(q);
single_command(0xc8);
sprintf(r,"P=%3.1fW",p);
data_write(r);
TH0=0;
TL0=0;
}
}
void timer() //Timer1 for sampling.
{
int i;
for(i=0;i<108;i++)
{
TH1=0xdb;
TL1=0xff;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;
}
}
Code Available Here: Click Here
Comments
Post a Comment