找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

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

使用AT89C4051單片機(jī)+CD4069的簡(jiǎn)易LC測(cè)試儀源程序電路原理圖

[復(fù)制鏈接]
ID:1136941 發(fā)表于 2024-11-20 14:32 | 顯示全部樓層 |閱讀模式
電路原理圖如下:
51hei.gif

單片機(jī)源程序如下:
#include <reg51.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
/**********1602************/
sbit RS=P1^7;
sbit EN=P1^6;
sbit LCD_D4=P1^3;
sbit LCD_D5=P1^2;
sbit LCD_D6=P1^1;
sbit LCD_D7=P1^0;
sbit L_C=P3^0;
//---------------------------
bit Lc=1;
uchar cnt=0;
float counter=0;
float F1=0;
float F2=0;
float C1=0;
float L1=0;
ulong temp1=0;
ulong temp2=0;
unsigned char Data[8];
unsigned char Table[]="0123456789";
/********以下是函數(shù)聲明********/
void LCD_en_write(void);//液晶使能
void LCD_by(uchar abc);//寫字節(jié)
void LCD_set_xy(uchar x, uchar y);//寫地址
void LCD_write_str(uchar X,uchar Y,uchar *s);//寫字符串
void LCD_init(void);//液晶初始化
void del_ms(uint n);//ms延時(shí)函數(shù)
void delay_5us(void);//5us延時(shí)函數(shù)
void delay_nus(uint n);//N us延時(shí)函數(shù)
void T0_T1_ini(void);//定時(shí)器初始化
void process_8(unsigned long i,unsigned char *p) ;
void display_8C(unsigned char x, unsigned char y, unsigned char *p);
ulong calc_Cx(float cl);//計(jì)算被測(cè)電容Cx
float calc_Lx(float cl);//計(jì)算被測(cè)電感Lx
void display_8L(unsigned char x, unsigned char y, uchar *p);
//-----------------------------------------
void process_8(unsigned long i,uchar *p)
{
  p[0]=i/10000000%10;
  p[1]=i/1000000%10;
  p[2]=i/100000%10;
  p[3]=i/10000%10;
  p[4]=i/1000%10;
  p[5]=i/100%10;
  p[6]=i/10%10;
  p[7]=i%10;
}
//-------------------------------------------------------
void display_8C(unsigned char x, unsigned char y, uchar *p)
{
  unsigned char i;
  LCD_set_xy( x, y );
  RS=1;            
  for(i=0;i<8;i++)
  {
    LCD_by(Table[p[ i]]);
  }
}
//--------------------------------------------------------
void display_8L(unsigned char x, unsigned char y, uchar *p)
{
  unsigned char i;
  LCD_set_xy( x, y );
  RS=1;         
  for(i=0;i<8;i++)
  {
    if(i==6)
    {
      LCD_write_str(10,1,".");
    }
      LCD_by(Table[p[ i]]);
  }
}
//---------------------------------------------
void LCD_en_write(void)
{
     delay_5us();
     EN=1;        
     delay_5us();
     EN=0;        
}
//---------------------------------------
void LCD_by(uchar abc)
{
    delay_nus(500);
    if(((abc<<0)&0x80)==0)     
     LCD_D7=0;            
     else LCD_D7=1;         
    if(((abc<<1)&0x80)==0)     
     LCD_D6=0;              
     else LCD_D6=1;        
    if(((abc<<2)&0x80)==0)     
     LCD_D5=0;              
     else LCD_D5=1;        
    if(((abc<<3)&0x80)==0)     
     LCD_D4=0;              
     else LCD_D4=1;        
    LCD_en_write();

    if(((abc<<4)&0x80)==0)     
     LCD_D7=0;              
     else LCD_D7=1;         
    if(((abc<<5)&0x80)==0)     
     LCD_D6=0;              
     else LCD_D6=1;         
    if(((abc<<6)&0x80)==0)     
     LCD_D5=0;              
     else LCD_D5=1;         
    if(((abc<<7)&0x80)==0)     
     LCD_D4=0;              
     else LCD_D4=1;         
    LCD_en_write();
}
//----------------------------------------------
void LCD_set_xy( uchar x, uchar y )
  {
    uchar address;
    if (y == 0) address = 0x80 + x;
    else
    address = 0xc0 + x;
    RS=0;           
    LCD_by(address);
  }
//---------------------------------------------
void LCD_write_str(uchar X,uchar Y,uchar *s)
  {
    LCD_set_xy(X,Y);
    RS=1;
    while(*s)
    {
       LCD_by(*s);
       s++;
    }
  }
//------------------------------------
void LCD_init(void)     
{
    RS=0;            
    del_ms(500);

    LCD_by(0x30);
    del_ms(60);
    LCD_by(0x30);
    del_ms(10);
    LCD_by(0x30);
    del_ms(10);
    LCD_by(0x02);
    del_ms(10);
    LCD_by(0x28);
    del_ms(10);
    LCD_by(0x08);
    del_ms(10);
    LCD_by(0x01);
    del_ms(10);
    LCD_by(0x06);
    del_ms(10);
    LCD_by(0x0C);
    del_ms(100);
}
//----------------------------------------------
void delay_nus(uint n)//N us延時(shí)函數(shù)
  {
   uint i=0;
   for (i=0;i<n;i++){;}
  }
//------------------------------
void delay_5us(void)//@12.000MHz//5us延時(shí)函數(shù)
{
   unsigned char data i;

   _nop_();
   _nop_();
   i = 12;
   while (--i);
}

//------------------------------
void del_ms(uint n)//ms延時(shí)函數(shù)
{
   uchar j;
   while(n--)
  {for(j=0;j<125;j++);}
}
//------------------------------
void T0_T1_ini(void)
{
   TMOD=0x15;//T1方式1定時(shí),T0方式1計(jì)數(shù)
   TH1=(65536-50000)/256;//50ms
   TL1=(65536-50000)%256;
   TH0=0x00;
   TL0=0x00;
   TR0=1;
   TR1=1;
   EA=1;
   ET1=1;
}
//-------------------------------
void timer1(void) interrupt 3 using 2//測(cè)頻率
{
   TH1=(65536-50000)/256;//50ms
   TL1=(65536-50000)%256;
   TF1=0;
   cnt++;
   if(cnt==2)//0.1秒閘門
   {
     cnt=0;
     temp1=TL0;
     temp2=TH0;
     TR0=0;
     TL0=0;
     TH0=0;
     TR0=1;
     counter=((temp2*256)+temp1)*10;
     if(Lc==1)//先測(cè)出頻率值F1
     {
       Lc=0;
       F1=counter;
      }
    }
}
//--------------------------------
ulong calc_Cx(float cx)//計(jì)算C
{
  float x;
  float temp1;
  
  temp1=(float)F1/(float)F2;
  x=(float)(((temp1*temp1)-1)*cx);        
  return x;
}
//--------------------------------
float calc_Lx(float lx)//計(jì)算L
{
  float x;
  float temp1;
  
  temp1=(float)F1/(float)F2;
  x=(float)(((temp1*temp1)-1)*lx);
  x=x*100;        
  return x;
}
//--------------------------------
void main(void)
{
  float L2,C2;
        
  del_ms(1000);//等待震蕩穩(wěn)定
  T0_T1_ini();
  LCD_init();
  del_ms(100);
  if(L_C==0)//檔位錯(cuò)誤
  {
    while(1)
    {
      LCD_write_str(4,0,"Error !!!");
    }
}  

  while(1)
  {
    F2=counter;//測(cè)頻率值F2
               
    LCD_write_str(0,0,"fq=");
    process_8(counter,Data);
    display_8C(4,0,Data);
    LCD_write_str(14,0,"Hz");
               
     if(L_C==0)//測(cè)電感
     {
        L1=76.95;//uH
        L2=calc_Lx(L1);
        LCD_write_str(0,1,"Lx=");
        process_8(L2,Data);
        display_8L(4,1,Data);
        LCD_write_str(14,1,"uH");
      }
     if(L_C==1)//測(cè)電容
     {
        LCD_write_str(12,1," ");
        C1=2408;//pF
        C2=calc_Cx(C1);
        LCD_write_str(0,1,"Cx=");
        process_8(C2,Data);
        display_8C(4,1,Data);
        LCD_write_str(14,1,"pF");
      }   
   }
}

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

ID:1136941 發(fā)表于 2024-11-22 11:19 | 顯示全部樓層
電路圖中的電容C8容量應(yīng)該是2200PF
回復(fù)

使用道具 舉報(bào)

ID:1136941 發(fā)表于 2024-11-22 11:21 | 顯示全部樓層
電路圖中的電容C8改為2200PF
回復(fù)

使用道具 舉報(bào)

ID:71955 發(fā)表于 2024-11-24 16:38 來自手機(jī) | 顯示全部樓層
問一下使用cd4069對(duì)比lm393哪一個(gè)頻率穩(wěn),我用lm393做的頻率很不穩(wěn)導(dǎo)致數(shù)字亂跳
回復(fù)

使用道具 舉報(bào)

ID:1136941 發(fā)表于 2024-11-24 17:37 | 顯示全部樓層
用CD4069的震蕩頻率在10HZ位跳動(dòng),測(cè)試值還比較穩(wěn)定。C8用的是2200PF滌綸電容,其它的是獨(dú)石電容。
回復(fù)

使用道具 舉報(bào)

ID:1136941 發(fā)表于 2024-11-25 16:49 | 顯示全部樓層
精度還是可以滿足一般應(yīng)用的 IMG_20241125_164103(1).jpg
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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