欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 想要搞個簡單單片機頻率計 中斷1秒計算頻率,請幫忙看看 [打印本頁]

作者: wjx111123    時間: 2021-6-25 10:31
標題: 想要搞個簡單單片機頻率計 中斷1秒計算頻率,請幫忙看看
  1. #include"reg51.h"
  2. #include"lcd1602.h"
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. uchar count=0,valueH=0,valueL=0;
  6. uchar str[]={"0123456789"};
  7. uchar str1[]={"FREQUENCE:"};
  8. uint fre=0;
  9. uint num;

  10. void initex0()
  11. {
  12.         IT0=1;
  13.         EX0=1;
  14.         EA=1;
  15. }

  16. void inittimer0()
  17. {
  18.         TMOD=0x01;
  19.         TH0=(65536-10000)/256;
  20.         TL0=(65536-10000)%256;
  21. }
  22. void T0_time()interrupt 1
  23. {
  24.         TH0=(65536-50000)/256;
  25.         TL0=(65536-50000)%256;
  26.         num++;
  27.                 if(num==20)
  28.                 {}
  29. }
  30. void datadeal()
  31. {
  32.         uint value=0;
  33.         value=valueH*256+valueL;
  34.         fre=10000000/value;
  35. }

  36. void display()
  37. {
  38.         uchar temp0=0,temp1=0,temp2=0,temp3=0,temp4=0,temp5=0;
  39.         uchar i=0;
  40.         temp0=(fre%1000000)/100000;
  41.         temp1=(fre%100000)/10000;
  42.         temp2=(fre%10000)/1000;
  43.         temp3=(fre%1000)/100;
  44.         temp4=(fre%100)/10;
  45.         temp5=fre%10;
  46.         writecom(0x80);
  47.         delay(1);
  48.         while(str1[i]!='\0')
  49.         {
  50.                 writedat(str1[i]);
  51.                 delay(1);
  52.                 i++;
  53.         }
  54.         writecom(0x80+0x40+5);
  55.         delay(1);
  56.         writedat(str[temp0]);
  57.         delay(1);
  58.         writedat(str[temp1]);
  59.         delay(1);
  60.         writedat(str[temp2]);
  61.         delay(1);
  62.         writedat(str[temp3]);
  63.         delay(1);
  64.         writedat(str[temp4]);
  65.         delay(1);
  66.         writedat('.');
  67.         delay(1);
  68.         writedat(str[temp5]);
  69.         delay(1);
  70.         writedat('H');
  71.         delay(1);
  72.         writedat('Z');
  73.         delay(1);
  74. }

  75. void main()
  76. {
  77.         initex0();
  78.         inittimer0();
  79.         initlcd();
  80.         while(1)
  81.         {
  82.                  datadeal();
  83.                 display();
  84.         }
  85. }

  86. void ex0_isr() interrupt 0
  87. {
  88.         if(count==0)
  89.         {
  90.                 TH0=0x00;
  91.                 TL0=0x00;
  92.                 TR0=1;
  93.         }
  94.         else if(count==1)
  95.         {
  96.                 TR0=0;
  97.                 valueH=TH0;
  98.                 valueL=TL0;
  99.                 count=0;
  100.         }
  101.          count++;
  102. }
復制代碼

作者: xuyaqi    時間: 2021-6-25 11:28
還是一步步來,你的外中斷計數(shù)就有問題。
作者: yzwzfyz    時間: 2021-6-25 13:44
本帖最后由 yzwzfyz 于 2021-6-26 10:03 編輯

計數(shù)要做如下三件事,你是否同意?
1、何時開始?
2、何時結(jié)束?
3、誰來數(shù)數(shù)?
這三條你是如何做的呢?




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1