⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freqen.c

📁 此程序可以显示输入波形
💻 C
字号:
//--------------------------------------------------------------------

//模块:Freqen.C

//功能:频率计模块

//晶振:24.000MHz

//芯片: STC12C5412AD
#include "stc12c5412ad.h"
//#ifndef  lcd12864_driver_new
//#include "lcd12864_driver_new.h"
//#endif

#define uchar unsigned char                  

#define uint unsigned int

extern uchar keyfuncindex;

void dis_cls(void);

extern void d0(void);

extern void lcd_init(void);

extern void dis_one_char(uchar x,uchar y,uchar asc_num,bit b_flag);

extern void dis_one_zi(uchar x_add,uchar y_add,uchar code *po,bit back_flag,bit char_moudle);

extern void delay(uint time);

extern uchar bdata gate;

extern void beep(uint time);

void sel_x(uchar x);      //74HC390 分频系数选择1,10,100

void delay_1(uchar time);

extern uchar temp_l,temp_h;

extern uchar i;

extern unsigned char code x43[];// 量

extern unsigned char code x44[];// 程

extern unsigned char code x45[];// 切

extern unsigned char code x46[];// 换

extern unsigned char code x47[];// 请

extern unsigned char code x48[];// 稍

extern unsigned char code x49[];// 候

extern unsigned char code x50[];// …

extern unsigned char code x51[];// 周

extern unsigned char code x52[];// 期

extern unsigned char code x7[]; // 频

extern unsigned char code x8[]; // 率

extern uint temp0,temp1,temp2,temp3,temp4;

uchar a1,a2;

sbit sel_1=P1^6;

sbit sel_10=P1^4;

sbit sel_100=P3^4;

sbit p3_5=P3^5;

bit clr_flag0=0;

bit clr_flag1=0;

bit clr_flag2=0;

bit clr_flag3=0;

bit clr_flag4=0;

sbit key0=P3^0;

sbit key1=P3^1;

//--------------------------------------------------------------------

void timer_init()

{

      TMOD=0xd1; //T1 做门控计数

      TH1=0;

      TL1=0;

      TH0=0x3c;

      TL0=0xb0;

      ET0=1;

      EA=1;

      TR0=1;

      TR1=1;

      p3_5=1;

}

//--------------------------------------------------------------------

void time_up() interrupt 1 using 3

{

      TH0=0x3c;

      TL0=0xb0;

      if(++i==gate)

      {

              TR1=0;

              temp_l=TL1;

              temp_h=TH1;

              TH1=0;

              TL1=0;

              i=0;

              TR1=1;

      }

}

//--------------------------------------------------------------------

void sel_x(uchar x) //74HC390 分频系数选择1,10,100

{

      switch(x)

      {

              case 1:

              {

                    sel_1=1;

                    sel_10=0;

                    sel_100=0;

                    break;

              }



              case 10:

              {

                    sel_1=0;

                    sel_10=1;

                    sel_100=0;

                    break;

              }



              case 100:

              {

                    sel_1=0;

                    sel_10=0;

                    sel_100=1;

                    break;

              }

              default:

              break;

      }

}

//--------------------------------------------------------------------

void temp_to_tempx(uint temp)

{

      temp0=temp/10000;

      temp1=(temp-(temp0*10000))/1000;

      temp2=(temp-(temp0*10000)-(temp1*1000))/100;

      temp3=(temp-(temp0*10000)-(temp1*1000)-(temp2*100))/10;

      temp4=temp%10;

}            

//--------------------------------------------------------------------

void dis_mod(unsigned long temp,uchar point,uchar danwei)

{

      

      uchar danwei_t;

      

      temp_to_tempx(temp);



      dis_one_zi(0,0,x7,1,1);//频

      dis_one_zi(0,1,x8,1,1);//率



      dis_one_char(0,11,0x7f,0);

      dis_one_char(0,12,danwei,1);

      dis_one_char(0,13,'H',1);

      dis_one_char(0,14,'z',1);

      dis_one_char(0,15,0x7f,0);

      dis_one_char(0,4,0x7f,0);

      if(temp0!=0)

      {

              dis_one_char(0,5,temp0+0x30,1);

              clr_flag0=0;

      }

      else

      dis_one_char(0,5,0x7f,0);

      clr_flag0=1;



      dis_one_char(0,10,temp4+0x30,1);

      dis_one_char(0,9,temp3+0x30,1);

      switch (point)

      {

              

              case 0:

              {

                    dis_one_char(0,5,temp0+0x30,1);

                    dis_one_char(0,6,'.',1);

                    dis_one_char(0,7,temp1+0x30,1);

                    dis_one_char(0,8,temp2+0x30,1);

                    break;

              }



              case 1:

              {

                    if(temp1==0 && temp0==0)

                    dis_one_char(0,5,0x7f,0);

                    dis_one_char(0,6,temp1+0x30,1);

                    dis_one_char(0,7,'.',1);

                    dis_one_char(0,8,temp2+0x30,1);

                    break;

              }

              

              case 2:

              {

                    dis_one_char(0,6,temp1+0x30,1);

                    if(temp1==0 && temp0==0)

                    dis_one_char(0,6,0x7f,0);

                    dis_one_char(0,7,temp2+0x30,1);

                    dis_one_char(0,8,'.',1);

                    break;

              }    

              default:

              break;

      }

//--------------------------------------------------------------------

      if(danwei=='K' && point==1)

      {    

              temp=1000000/temp;

              temp&=0x0000ffff;

              temp_to_tempx(temp);

              danwei_t='u';

      }

      if(danwei=='K' && point==2)

      {

              temp=100000000/temp;

              temp&=0x0000ffff;

              temp_to_tempx(temp);

              danwei_t='n';

      }

      if(danwei=='M' && point==0)

      {

              temp=10000000/temp;

              temp&=0x0000ffff;

              temp_to_tempx(temp);

              danwei_t='n';

      }

      if(danwei=='M' && point==1)

      {

              temp=1000000/temp;

              temp&=0x0000ffff;

              temp_to_tempx(temp);

              danwei_t='n';

      }



      dis_one_zi(2,0,x51,1,1);//周

      dis_one_zi(2,1,x52,1,1);//期

      dis_one_char(2,11,0x7f,0);

      dis_one_char(2,12,danwei_t,1);

      dis_one_char(2,13,'S',1);

      dis_one_char(2,14,0x7f,0);

      dis_one_char(2,15,0x7f,0);

      dis_one_char(2,4,0x7f,0);

              if(temp==65535)

              {

                    dis_one_char(2,6,'O',1);

                    dis_one_char(2,7,'V',1);

                    dis_one_char(2,8,'E',1);

                    dis_one_char(2,9,'R',1);

                    dis_one_char(2,10,'!',1);

              }

              else

              {

                    dis_one_char(2,6,temp0+0x30,1);

                    if(temp0==0)

                    dis_one_char(2,6,0x7f,0);

                    

                    dis_one_char(2,7,temp1+0x30,1);

                    if(temp0==0 && temp1==0)

                    dis_one_char(2,7,0x7f,0);

                    

                    dis_one_char(2,8,temp2+0x30,1);

                    if(temp0==0 && temp1==0 && temp2==0)

                    dis_one_char(2,8,0x7f,0);

                    

                    dis_one_char(2,9,temp3+0x30,1);

                    if(temp0==0 && temp1==0 && temp2==0 && temp3==0)

                  dis_one_char(2,9 ,0x7f,0);

                    

                    dis_one_char(2,10,temp4+0x30,1);

              }

}

//--------------------------------------------------------------------

void delay_1(uchar time)

{

      while(--time!=0)

      delay(50000);

}

//--------------------------------------------------------------------                  

void freq()      //频率计子程序

{

      unsigned long temp=0x30;

      uchar del=5;

      timer_init();

reset: gate=4;

      sel_x(100);

      a1=1;

      a2='M';

      while(1)

      {

//---------------------------------------------------

                    key1=1;

                    key0=1;

                    delay_1(5);

                    if(key0==0 || key1==0)

                    goto exit;

                    temp=temp_h*256+temp_l;

                    if(TF1)

                    {

                            TF1=0;

                            TH1=0;

                            TL1=0;

                            dis_cls();

                            dis_one_zi(0,0,x43,1,1);

                            dis_one_zi(0,1,x44,1,1);

                            dis_one_zi(0,2,x45,1,1);

                            dis_one_zi(0,3,x46,1,1);

                            dis_one_zi(0,4,x47,1,1);

                            dis_one_zi(0,5,x48,1,1);

                            dis_one_zi(0,6,x49,1,1);

                            dis_one_zi(0,7,x50,1,1);

                            goto reset;

                            }

                    temp=temp_h*256+temp_l;

                    if(sel_100==1 && temp<=5000 && gate==4)

                    {

                            sel_x(10);

                            a1=0;

                            a2='M';

                            delay_1(del);

                    }

                    temp=temp_h*256+temp_l;

                    if(sel_10==1 && temp<=5000 && gate==4)

                    {

                            sel_x(1);

                            a1=2;

                            a2='K';

                            delay_1(del);

                    }

                    temp=temp_h*256+temp_l;

                    if(sel_1==1 && temp<=5000 && gate==4)

                    {

                            gate=40;

                            a1=1;

                            a2='K';

                            delay_1(del);

                    }

              //---------------------------------------------------

                    temp=temp_h*256+temp_l;

                    if(sel_1==1 && temp>50010 && gate==40)

                    {

                            gate=4;

                            a1=2;

                            a2='K';

                            delay_1(del);

                    }

      

                    temp=temp_h*256+temp_l;

                    if(sel_1==1 && temp>50010 && gate==4)

                    {

                            sel_x(10);

                            a1=0;

                            a2='M';

                            delay_1(del);

                    }

                    temp=temp_h*256+temp_l;

                    if(sel_10==1 && temp>50010 && gate==4)

                    {

                            sel_x(100);

                            a1=1;

                            a2='M';

                            delay_1(del);

                    }

                    if(temp>50000)

                    goto reset;

              

                    dis_mod(temp,a1,a2);

        //---------------------------------------------------

              }

exit: TMOD=0x00; //T1 做门控计数

              ET0=0;

              EA=0;

              TR0=0;

              TR1=0;

              p3_5=0;

              delay_1(10);

              keyfuncindex=0;

              d0();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -