【问题标题】:I need to know how to read frequency我需要知道如何阅读频率
【发布时间】: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 也有问题。 我该如何解决?

感谢所有阅读此处输入代码的人! 我真的很感激任何帮助! 谢谢大家!

【问题讨论】:

  • 任何答案?请问?!

标签: frequency atmel 8051


【解决方案1】:

它们是测量频率的逻辑。 8051有2个定时器/计数器,将一个配置为定时器,另一个配置为计数器,并将频率输入给计数器引脚,然后同时启动计数器和定时器(无论如何它们在激活定时器时会延迟1个机器周期,但你可以补偿它通过计算),在此负载计数器之前具有合适的值,以便您的模块可以测量低频。当计数器溢出时停止计时器并且知道没有。计数和经过的时间,您可以计算频率。 希望这个逻辑有效。

【讨论】:

    猜你喜欢
    • 2018-06-14
    • 1970-01-01
    • 2016-07-06
    • 1970-01-01
    • 2010-12-29
    • 2010-12-30
    • 2014-02-19
    • 1970-01-01
    • 2018-02-05
    相关资源
    最近更新 更多