找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5156|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

藍橋杯板子51單片機的頻率測量程序(測量555定時器脈沖)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:312929 發(fā)表于 2018-4-21 11:58 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
測量555定時器脈沖。

用藍橋杯板子寫的程序,大家自行下載,看一下

單片機源程序如下:
  1. #include <reg52.h>
  2. #include <intrins.h>

  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. sfr AUXR=0x8e;
  6. uchar code  tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};
  7. void smg_xianshi(uchar yi,er,san,si,wu,liu,qi,ba);
  8. uchar yi,er,san,si,wu,liu,qi,ba;       
  9. void delay(uint x);
  10. void close ();
  11. void Timer0Init(void);
  12. void zd_t1();       
  13. void Timer1Init(void);
  14. uint time,fre;


  15.                 void main()
  16.                 {
  17.                         Timer1Init();
  18.                         Timer0Init();
  19.                         EA=1;
  20.                         ET1=1;
  21.                
  22.                         while(1)
  23.                         {
  24.                                 yi=11;er=11;san=11;
  25.                                 si=fre/10000;
  26.                             wu=(fre%10000)/1000;
  27.                                 liu=(fre%1000)/100;
  28.                                 qi=(fre%100)/10;
  29.                             ba=(fre%100)%10;
  30.                            smg_xianshi(yi,er,san,si,wu,liu,qi,ba);               
  31.                         }
  32.                 }



  33.                   void zd_t1()        interrupt 3
  34.                 {
  35.                         time++;
  36.                         if(time==1000)
  37.                         {
  38.                                 TR0=0;       
  39.                                 time=0;
  40.                                 fre=TH0*256+TL0;
  41.                                 TH0=0;
  42.                                 TL0=0;
  43.                                 TR0=1;
  44.                         }       
  45.                 }



  46.                 void Timer1Init(void)                //1毫秒@11.0592MHz
  47.                 {
  48.                     AUXR &= 0xBF;                //定時器時鐘12T模式
  49.                         TMOD &= 0x0F;                //設(shè)置定時器為定時模式
  50.                         TL1 = 0x66;                    //設(shè)置定時初值
  51.                         TH1 = 0xFC;                    //設(shè)置定時初值
  52.                         TF1 = 0;                    //清除TF1標志
  53.                         TR1 = 1        ;                //定時器1開始計時
  54.                 }
  55.                
  56.                
  57.                 void Timer0Init(void)       
  58.                 {
  59.                     AUXR &= 0x7F;                //定時器時鐘12T模式
  60.                         TMOD |= 0x05;                //設(shè)置定時器為計數(shù)模式
  61.                         TL0 = 0x00;                    //設(shè)置定時初值
  62.                         TH0 = 0x00;                    //設(shè)置定時初值
  63.                         TF0 = 0;                    //清除TF0標志
  64.                         TR0 = 1;                    //定時器0開始計時
  65.                 }


  66.                         void delay(uint x)
  67.                         {
  68.                         uchar i;
  69.                                 while(x--)
  70.                                 {
  71.                                     for(i=0;i<120;i++);
  72.                                 }
  73.                        
  74.                         }
  75.                        
  76.                         void close ()
  77.                         {
  78.                             P2=0x80;
  79.                                 P0=0xff;
  80.                                 P2=0x1f;
  81.                                 P2=0xa0;
  82.                                 P0=0x00;
  83.                                 P2=0x1f;
  84.                        
  85.                         }
  86.                        
  87.                         void  smg_xianshi(uchar yi,er,san,si,wu,liu,qi,ba)
  88.                         {
  89.                             P2=0xc0;
  90.                                 P0=0x01;
  91.                                 P2=0xe0;
  92.                                 P0=tab[yi];
  93.                                 delay(5);
  94.                                
  95.                             P2=0xc0;
  96.                                 P0=0x02;
  97.                                 P2=0xe0;
  98.                                 P0=tab[er];
  99.                                 delay(5);
  100.                                
  101.                                 P2=0xc0;
  102.                                 P0=0x04;
  103.                                 P2=0xe0;
  104.                                 P0=tab[san];
  105.                                 delay(5);
  106.                                
  107.                                 P2=0xc0;
  108.                                 P0=0x08;
  109.                                 P2=0xe0;
  110.                                 P0=tab[si];
  111.                                 delay(5);
  112.                                
  113.                                 P2=0xc0;
  114.                                 P0=0x10;
  115.                                 P2=0xe0;
  116.                                 P0=tab[wu];
  117.                                 delay(5);       
  118.                                
  119.                                 P2=0xc0;
  120.                                 P0=0x20;
  121.                                 P2=0xe0;
  122.                                 P0=tab[liu];
  123.                                 delay(5);
  124.                                
  125.                                 P2=0xc0;
  126.                                 P0=0x40;
  127.                                 P2=0xe0;
  128.                                 P0=tab[qi];
  129.                                 delay(5);
  130.                                
  131.                                 P2=0xc0;
  132.                                 P0=0x80;
  133.                                 P2=0xe0;
  134.                                 P0=tab[ba];
  135.                                 delay(5);       
  136.                         }
復(fù)制代碼

所有資料51hei提供下載:
555.zip (197 Bytes, 下載次數(shù): 45)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

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

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