找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

这个单片机频率计,为什么无法实现功能呢?

查看数: 1830 | 评论数: 5 | 收藏 1
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2019-4-16 19:41

正文摘要:

#include<reg51.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int uchar code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90, 0x88,0x83,0xc6, ...

回复

ID:149799 发表于 2019-5-19 11:16
这个频率计,上限频率是多少。
ID:513931 发表于 2019-4-24 11:30
chtyise 发表于 2019-4-17 10:06
0X51 T1脉冲计数器 要接到P3.5,

弄好啦 感谢
ID:513931 发表于 2019-4-24 11:30
wulin 发表于 2019-4-17 15:33
给你修改好了,你试试。

可以了 感谢
ID:213173 发表于 2019-4-17 15:33
给你修改好了,你试试。


频率表+仿真.zip (60.32 KB, 下载次数: 6)


  1. #include<reg51.h>
  2. #include<intrins.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. #define ulong unsigned long
  6. uchar code DSY_CODE[]={//共阳数码管段码"0~f-."
  7.                 0xc0,0xf9,0xa4,0xb0,
  8.                 0x99,0x92,0x82,0xf8,
  9.                 0x80,0x90,0x88,0x83,
  10.                 0xc6,0xa1,0x86,0x8e,0xbf,0x7f};
  11. uchar code wei[]={0x01,0x02,0x04,0x08};
  12. uchar buf[4];//缓存
  13. uint bb=0;
  14. uint count=0;
  15. bit sign=0;

  16. void xianshi()
  17. {
  18.         static uchar i=0,j=0;        //计数变量
  19.         if(++j>=8)
  20.         {
  21.                 j=0;
  22.                 P0=0xff;                                        //消隐
  23.                 switch(i)
  24.                 {
  25.                         case 0: P2=wei[i];P0=DSY_CODE[buf[3]];i++;break;
  26.                         case 1: P2=wei[i];P0=DSY_CODE[buf[2]];i++;break;
  27.                         case 2: P2=wei[i];P0=DSY_CODE[buf[1]];i++;break;
  28.                         case 3: P2=wei[i];P0=DSY_CODE[buf[0]];i=0;break;
  29.            }
  30.         }
  31. }
  32. void main()
  33. {
  34.         uchar j;
  35.         TMOD= 0x52;                //设置定时器模式
  36.         TL0 = 0x06;                //设置定时初值,晶振12MHz
  37.         TH0 = 0x06;                //设置定时重载值
  38.         TH1=0x00;
  39.         TL1=0x00;
  40.         TR0=1;
  41.         TR1=1;
  42.         EA=1;
  43.         ET0=1;
  44.         while(1)
  45.         {                 
  46.                 if(sign==1)
  47.                 {
  48.                         sign=0;
  49.                         for(j=0;j<4;j++)//分解数据
  50.                         {
  51.                                 buf[j]=count%10;//按位保存
  52.                                 count/=10;
  53.                         }
  54.                 }
  55.         }
  56. }

  57. void zhongduan1() interrupt 1
  58. {   
  59.         bb++;  
  60.         if(bb==4000)
  61.         {  
  62.                 bb=0;
  63.                 sign=1;
  64.                 count=TH1;
  65.                 count=(count<<8)+TL1;
  66.                 TH1=0;
  67.                 TL1=0;
  68.         }
  69.         xianshi();
  70. }
复制代码




ID:337069 发表于 2019-4-17 10:06
0X51 T1脉冲计数器 要接到P3.5,

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表