Hello.
This is my first post under micro controllers section.
I want to design an LCR meter using 89s52.(because i have that programmer).
I need to measure the frequency generated by the opamp for the specific LC elements. I started writing a code. (attachment 1).
I used timer 0 as counter. initialized TL0 and TH0; started TR0=1;
It is tested with a clock pulse given to the T0 pin.
I am not getting idea that how to stop the counter(TR0=0) for a given interval of time.
for example, i want count a 1KHz pulses / 1millisecond. how to specify the 1 ms in code.
To see the count i used an 16x2 LCD.
code:
This is my first post under micro controllers section.
I want to design an LCR meter using 89s52.(because i have that programmer).
I need to measure the frequency generated by the opamp for the specific LC elements. I started writing a code. (attachment 1).
I used timer 0 as counter. initialized TL0 and TH0; started TR0=1;
It is tested with a clock pulse given to the T0 pin.
I am not getting idea that how to stop the counter(TR0=0) for a given interval of time.
for example, i want count a 1KHz pulses / 1millisecond. how to specify the 1 ms in code.
To see the count i used an 16x2 LCD.
code:
Rich (BB code):
#include<reg51.h>
sbit rs=P3^7;
sbit en=P3^6;
void lcdcmd(char value);
void lcddata(char value);
void delay();
void main()
{
int x,a,b,c,d;
T0=1;
TMOD=0x05;
TL0=0;
TH0=0;
while(1)
{
TR0=1;
x=TL0;
//while(TF0==0);
//TR0=0;
TF0=0;
a=x/100;
b=x%100;
c=b/10;
d=b%10;
lcdcmd(0x38);
lcdcmd(0x0e);
lcdcmd(0x01);
delay();
lcddata(a+0x30);
delay();
lcddata(c+0x30);
delay();
lcddata(d+0x30);
delay();
}
}
void lcdcmd(char value)
{
P2=value;
rs=0;
en=1;
delay();
en=0;
}
void lcddata(char value)
{
P2=value;
rs=1;
en=1;
delay();
en=0;
}
void delay()
{
int i,j;
for(i=0;i<=100;i++)
for(j=0;j<=100;j++);
}
Attachments
-
64.7 KB Views: 67
-
132.9 KB Views: 31
Last edited by a moderator: