【发布时间】:2014-12-29 21:31:12
【问题描述】:
我得到了电子卡上的端口(带有 8051 微控制器的 Atmel 卡)。此端口名为 p3_0。端口获取“1”或“0”逻辑。
1 0 1 0
''''''' ''''''''
' ' ' '
' ''''''' '''''' And so on....
我需要将 C 用于 8051(实际上是原始 C)并编写一个知道频率的代码。最后我需要char数组中的频率,因为我需要将它打印到只知道打印char array[];的LCD上。我使用“itoa”函数将 int 数“计数”转换为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”计数的时间和(计算频率)
问题是:我怎样才能知道频率上 1 到底有多少,我怎么知道?
在计算“从频率中获取”时,dalay 也有问题。 我该如何解决?
感谢所有阅读此处输入代码的人! 我真的很感激任何帮助! 谢谢大家!
【问题讨论】:
-
任何答案?请问?!