• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

humble request...,,,,shall be very thankful.

Status
Not open for further replies.

arsal.javaid

New Member
How to calculate frequency of square wave with unknown frquency coming on P3.5 of 8051 controller in c?
my effort is as follows.plz help by modifying it.
i am not sure ,will the following program keep on counting or will calculate the pulses in one second..?
#include <AT89X51.H>
void msdelay(unsigned int);
void main()
{
unsigned char value;
T1=1; //make t1 an input
TMOD=0x06; //counter 1,mode 2 ,8 bit auto reload mode
TH1=0; //set count to 0
while(1) //repeat forever
{
do
{
TR1=1; //start timer
value=TL1; //store tL1 in value
P1=value; //place value on pins of p1
}

while(TF1==0); //wait here
TR1=0; //stop timer
TF1=0; //clear flag
}
}
void msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
 

edeca

Active Member
Disclaimer first, I do not know anything about Amtel. However, I will do my best.

You need to look up what "mode 2" means for the timer. Does it count up? Count down?

The timer appears to be set to auto-reload, that probably means it will keep going after the first overflow (or underflow). It will output the value on the pins of p1 (port one?). However, I do not know what the delay will be. It does not appear that there is any delay in the timer steps, so it will probably run at full speed and count faster than you can see.

The function msdelay() is never called, so it is quite redundant.

Do not forget code tags around your program next time, it makes it easier to read.
 
  • Like
Reactions: 3v0
Status
Not open for further replies.

EE World Online Articles

Loading
Top