EDABOSS电子论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 703|回复: 1

[资料共享] 单片机频率计proteus仿真(源程序+原理图 lcd1602液晶显示)

[复制链接]

26

主题

0

回帖

197

E币

技术员

Rank: 2

积分
52
发表于 2017-5-10 15:16:24 | 显示全部楼层 |阅读模式
51单片机做的频率计,可以测到16M.另外还有AD0832模数转换芯片采集峰值,使用lcd1602液晶屏显示
024752t2nvjxmu87j982nx.png
单片机频率计的源程序如下:
  1. //*******************************
  2. //**********设计者:陈仲奇********
  3. //**********欢迎交流指导**************
  4. //********************************
  5. #include <REGX52.H>
  6. #include<stdio.h>
  7. #include<math.h>
  8. #include"adc0832.h"
  9. #include "LCD1602.h"
  10. #define uchar unsigned char
  11. #define uint unsigned int
  12. sbit  clr=P3^0;
  13. sbit  gate=P3^1;
  14. sbit  turn=P3^7;
  15. sbit  U_turn=P3^2;
  16. uint  num=0;
  17. uint  peak_value=0;
  18. float Upp=0;
  19. uchar wave=1,pulse=1;
  20. uint j=0,counter=0;
  21. unsigned long int Hight_byte=0,Low_byte=0;
  22. //ms延时------------------------------        
  23. void delay_ms(uint z)
  24. {
  25.   uint x;
  26.   uchar y;
  27.   for(x=0;x<z;x++)
  28.       for(y=0;y<110;y++) ;
  29. }
  30. //1s延时------------------------------
  31. void delay_1s(void)            
  32. {
  33.     uchar h,i,j,k;
  34.     for(h=5;h>0;h--)
  35.     for(i=4;i>0;i--)
  36.     for(j=116;j>0;j--)
  37.     for(k=214;k>0;k--);
  38. }


  39. //定时计数        初始化----------------------------------
  40. void CT_init()              
  41. {

  42.         TMOD = 0x25;                                // T0计数,T1定时
  43.            TH0 = 0x00;        
  44.         TL0 = 0x00;
  45.         TH1 = 0x06;
  46.         TL1 = 0x06;
  47.         clr=1;
  48.         clr=0;
  49.         gate=0;
  50.         gate=1;
  51.     ET0 = 1;
  52.         ET1 = 1;
  53.         EA  = 1;
  54.     TR0 = 1;
  55.         TR1 = 1;
  56. }

  57. //主函数--------------------------------------
  58. void main()
  59. {         
  60.      
  61.          unsigned long fre=0;
  62.      bit mode=0;
  63.             uchar buff[10];
  64.           uint temp=0;
  65.          LCD_Initial();
  66.          CT_init();
  67.          GotoXY(0,0);
  68.          Print("Welcome to use ") ;
  69.          GotoXY(0,1);
  70.          Print("Please Wating...");
  71.      delay_1s();
  72.          LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN);
  73.          while(1){

  74.            if(turn==0){        
  75.                  delay_ms(5);
  76.                 if(turn==0)        {
  77.                            while(turn==0);
  78.                     mode=~mode;LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN);
  79.                                 }
  80.                                  }
  81.                          temp=vollage(0);
  82.                                 if(temp>peak_value)
  83.                           peak_value=temp;
  84.                            if(temp>peak_value>>3&&temp<peak_value>>1) pulse=0;
  85.                            
  86.                                  if(mode==0){
  87.                                 fre=(Hight_byte*256)+Low_byte;
  88.                                 if(fre==0){        GotoXY(0,0);Print("F= 0000000000 Hz");        GotoXY(0,1);Print("F= 0000000000 Hz");         }
  89.                                 else{               
  90.                                  GotoXY(0,0);Print("F=            Hz");sprintf(buff,"%ld",fre);GotoXY(2,0);Print(buff);
  91.                                 GotoXY(0,1);Print("P=            ms");sprintf(buff,"%0.6f",1000.0/fre);GotoXY(2,1);Print(buff);        }
  92.                           }
  93.                

  94.            else{   
  95.                    sprintf(buff,"%bd",wave);
  96.            GotoXY(0,0);
  97.        Print(buff);
  98.            sprintf(buff,"Upp=%0.3fV",Upp);
  99.            GotoXY(0,1);
  100.        Print(buff);
  101.               
  102.            }
  103.             
  104.          }
  105.                  
  106. }

  107. /*--------------------------------------------------------------*/
  108. //计数器T0中断服务程序
  109. void T0_counter(void) interrupt 1 using 1
  110. {

  111. }


  112. /*--------------------------------------------------------------*/
  113. //定时器T1中断服务程序
  114. void T1_timer(void) interrupt 3 using 3
  115. {         
  116.          
  117.       if(num==3999){
  118.            gate=0;
  119.            TR0=0;TR1=0;
  120.            Hight_byte=TH0*256+TL0;
  121.            Low_byte=P1;
  122.            Upp=peak_value/100.0;
  123.            peak_value=0;
  124.            wave=pulse;
  125.            pulse=1;
  126.            clr=1;
  127.            clr=0;
  128.               TH0 = 0x00;        
  129.            TL0 = 0x00;
  130.            TH1 = 0x06;
  131.            TL1 = 0x06;
  132.            num=0;
  133.            gate=1;
  134.            TR0=1;TR1=1;
  135.           }
  136.            else num++;
  137. }
复制代码


捕获.PNG

频率计.rar (75.77 KB, 下载次数: 0)
积分规则
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|EDABOSS电子论坛

GMT+8, 2024-4-19 13:57 , Processed in 0.044259 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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