找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1802|回復(fù): 5
收起左側(cè)

這個單片機頻率計,為什么無法實現(xiàn)功能呢?

[復(fù)制鏈接]
ID:513931 發(fā)表于 2019-4-16 19:41 | 顯示全部樓層 |閱讀模式
T14BCLF_MUO5B}WFAS7}O%1.png
#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,0xa1,0x86,0x8e,0x00,0xbf};
uint a=0;
uint b=0;
uint c=0;
uchar day=0;
uchar ch=0;
uchar ch1=0;
uchar ch2=0;
uchar shi=0;
uchar shi1=0;
uchar shi2=0;
uchar fen=0;
uchar fen1=0;
uchar fen2=0;
uchar miao=0;
uchar miao1=0;
uchar miao2=0;
//延時
void DelayMS(uint x)
{
        uchar i;
        while(x--) for(i=0;i<120;i++);
}
void xianshi()
{
   while(1)                                 
   {  
   ch=ch%10;
   ch=ch/10;
   shi1=shi%10;
   shi2=shi/10;
   fen1=fen%10;
   fen2=fen/10;        
   miao1=miao%10;
   miao2=miao/10;
   P2=0x80;
   P0=DSY_CODE[miao1];
   DelayMS(5);
   P2=0x00;
   P2=0x40;
   P0=DSY_CODE[miao2];
   DelayMS(5);
   P2=0x00;
   P2=0x20;
   P0=DSY_CODE[fen1];
   DelayMS(5);
   P2=0x00;
   P2=0x10;
   P0=DSY_CODE[fen2];
   DelayMS(5);
   P2=0x00;
   P2=0x08;
   P0=DSY_CODE[shi1];
   DelayMS(5);
   P2=0x00;
   P2=0x04;
   P0=DSY_CODE[shi2];
   DelayMS(5);
   P2=0x00;                                
   P2=0x02;
   P0=DSY_CODE[ch1];
   DelayMS(5);
   P2=0x00;
   P2=0x01;
   P0=DSY_CODE[ch2];  
   DelayMS(5);
   P2=0x00;
   }
}
void main()
{
   TMOD=0x51;
   EA=1;
   ET0=1;
   ET1=1;
   TH0=(65536-50000)/256;
   TL0=(65536-50000)%256;
   TH1=0x00;
   TL1=0x00;

   TR0=1;
   TR1=1;
   while(1)
   {                 
          xianshi();
   }
}

void zhongduan1() interrupt 1
{   
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    b++;  
        if(b==20)
        {  
           c=(day*65536+TH1*256+TL1);
           miao=c%100;
           fen=(c/100)%100;
           shi=(c/10000)%100;
           ch=c/1000000;
           b=0;
           TH1=0;
           TL1=0;
           TR1=0;
        }
               
}
void zhongduan2() interrupt 3
{
    day++;
}

回復(fù)

使用道具 舉報

ID:337069 發(fā)表于 2019-4-17 10:06 | 顯示全部樓層
0X51 T1脈沖計數(shù)器 要接到P3.5,
回復(fù)

使用道具 舉報

ID:213173 發(fā)表于 2019-4-17 15:33 | 顯示全部樓層
給你修改好了,你試試。
無標(biāo)題.jpg

頻率表+仿真.zip (60.32 KB, 下載次數(shù): 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[]={//共陽數(shù)碼管段碼"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;        //計數(shù)變量
  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;                //設(shè)置定時器模式
  36.         TL0 = 0x06;                //設(shè)置定時初值,晶振12MHz
  37.         TH0 = 0x06;                //設(shè)置定時重載值
  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++)//分解數(shù)據(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. }
復(fù)制代碼




回復(fù)

使用道具 舉報

ID:513931 發(fā)表于 2019-4-24 11:30 來自手機 | 顯示全部樓層
wulin 發(fā)表于 2019-4-17 15:33
給你修改好了,你試試。

可以了 感謝
回復(fù)

使用道具 舉報

ID:513931 發(fā)表于 2019-4-24 11:30 來自手機 | 顯示全部樓層
chtyise 發(fā)表于 2019-4-17 10:06
0X51 T1脈沖計數(shù)器 要接到P3.5,

弄好啦 感謝
回復(fù)

使用道具 舉報

ID:149799 發(fā)表于 2019-5-19 11:16 | 顯示全部樓層
這個頻率計,上限頻率是多少。
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表