I got port that is on electronic card (Atmel card with 8051 micro controller) . This port named p3_0. The port get '1' or '0' logic.
1 0 1 0
''''''' ''''''''
' ' ' '
' ''''''' '''''' And so on....
I need to use C for 8051 (that is actually original C) and write a code that will know what the frequency is. finally I need the frequency in array of char cause I need to print it to LCD that only know to print char array[];
. I use "itoa" function that convert the int number, the 'count' to char array [];
. the frequency can be between 16Hz to 90Hz.
This is what I did :
void main(void)
{
init_lcd()///Print command
;print_lcd(1,"The Project"); //Print command
;print_lcd(2,"is starting:"); //Print command
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
while(1)
{
count = 0;
while(P3_0 == 1)
{
count ++;
init_lcd() //Print command
;print_lcd(1,"Counting..."); //Print command
for(i=0; i<1; i++){delay(1000);delay(1000);delay(1000);}//delay...
}
init_lcd()///Print command
;print_lcd(1,"Done Counting!"); //Print command
for(i=0; i<1; i++){delay(1000);delay(1000);delay(1000);}
;print_lcd(2,itoa(count)); //Print command
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
for(i=0; i<20; i++){delay(1000);delay(1000);delay(1000);}
}
}
The idea is I check the port and I count every time its '1'. Finally I will decide of a time that every '1' counted and (doing the calculation of what the frequency is)
THE QUESTION IS: HOW CAN I KNOW EXACTLY HOW MUCH 1 IS ON THE FREQUENCY, HOW CAN I?
Also there is thing with the dalay when counting that "take from the frequency". How can I solve that?
thanks for all who read enter code herethis!! I really appreciate any help!, THANKS ALL!