我有電子卡上的端口(Atmel卡與8051微控制器)。該端口名爲p3_0。端口得到'1'或'0'邏輯。我需要知道如何讀取頻率
1 0 1 0
''''''' ''''''''
' ' ' '
' ''''''' '''''' And so on....
我需要使用C爲8051(這實際上是原始的C),並編寫一個代碼,將知道頻率是什麼。最後我需要在字符數組中的頻率,因爲我需要將它打印到僅知道打印char array[];
的LCD上。我使用「itoa」函數將int數字「count」轉換爲char array [];
。頻率可以在16Hz到90Hz之間。
這是我做過什麼:
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);}
}
}
的想法是我檢查端口和我算每一次的「1」。最後,我會決定一個時間,每'1'計數和(做頻率計算)
問題是:我怎麼知道究竟是如何在頻率上,我怎麼能?
在計數「從頻率取」的時候也有與達賴有關係的東西。 我該如何解決這個問題?
感謝所有誰閱讀輸入代碼herethis! 我真的很感謝任何幫助!, 謝謝大家!
任何答案?請?! –