电感电容电解电容测量仪

'****************************************************
'*               电感电容电解电容测量仪             *
'*  电容:1P-2.5uF                                   *
'*  电感:1uH-2.0H                                   *
'*  电解电容:0.1uF-20000uF                          *
'*                 吕军省   天津大港                *
'*                 junsheng427@126.com              *
'*                            20081217              *
'****************************************************
$regfile = "m8def.dat"
$crystal = 8000000

Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5 , E = Portb.1 , Rs = Portb.0
Config Lcd = 16 * 2

Config Timer1 = Counter , Edge = Falling       '配置T/C1为计数
Config Timer2 = Timer , Prescale = 64       '配置T/C2定时

Config Int0 = Falling
Config Timer0 = Timer , Prescale = 8
On Ovf0 Tim0_isr
On Int0 T1_isr

On Ovf2 Tim2_isr
Enable Ovf2
On Ovf1 Tim1_isr
Enable Ovf1
Enable Interrupts
Tcnt2 = &H83
Start Timer2
Counter1 = 0
Start Counter1

Dim F1 As Long
Dim F2 As Long

Dim C1 As Single
Dim Ca1 As Single
Dim Ca2 As Single
Dim Cx As Single
Dim L1 As Single
Dim Lx As Single
Dim F11 As Single

Dim V1 As String * 11
Dim V2 As String * 11

Dim Vf As String * 6
Dim Vs As String * 8
Dim Z1 As String * 2

Dim J As Bit
Dim I As Byte
Dim K As Bit
Dim M As Bit
Dim Vl As Byte
Dim Tc As Byte
Dim Tc1 As Long
Dim Te As Long

Ddrd.7 = 0       '键初始
Portd.7 = 1
Ddrd.4 = 1       '继电器初始化
Ddrd.3 = 1
Portd.4 = 1
Portd.3 = 1

Ddrd.6 = 1
Portd.6 = 1
J = 1
K = 1
M = 1
I = 1
Tc1 = 0
Cls
Cursor Off

'/主程序/
Do

   '/按键处理/

   If Pind.7 = 0 Then       'S1
      Waitms 40
         If Pind.7 = 0 Then
            Incr I
            Bitwait Pind.7 , Set
         End If
   End If

   '/电感L1,电容C1计算/

   If I = 1 Then
      If J = 1 Then

         Lcd "  L_C_CE meter"
         Lowerline
         Lcd "    20081217"

         Waitms 1500       '等待F1计数
         Portd.3 = 0       '接入标准电容C2
         Waitms 1500       '等待f2计数

         Ca1 = F1 * F1
         Ca2 = F2 * F2
         C1 = Ca1 - Ca2
         C1 = Ca2 / C1
         C1 = C1 * 1800       '1800是标准电容C2 ;单位pF

         L1 = 3.1416 * 3.1416
         L1 = L1 * 4
         L1 = L1 * Ca1
         L1 = L1 * C1
         L1 = 1 / L1
         L1 = L1 * 1000000000000000000       '单位uH

         Portd.3 = 1       '断开标准电容C2
      End If

      J = 0

      Vf = Str(f1)       '显示f1
      Vf = Format(vf , "      ")
      Locate 1 , 7
      Lcd "F=" ; Vf ; "Hz"
      Locate 1 , 1
      Lcd "SetOK "

      V1 = Fusing(c1 , "#.#")
      V2 = Fusing(l1 , "#.#")
      Locate 2 , 1
      Lcd V1 ; "pF " ; V2 ; "uH"

   End If

   '/电容Cx计算/

   If I = 2 Then

      Vf = Str(f1)
      Vf = Format(vf , "      ")
      Locate 1 , 7
      Lcd "F=" ; Vf ; "Hz"

      F11 = F1 * F1
      Cx = Ca1 / F11
      Cx = Cx - 1
      Cx = Cx * C1

      V1 = Fusing(cx , "#.#")

      Vl = Len(v1)
      Z1 = "pF"

      If Vl = 6 Then
         V1 = Mid(v1 , 1 , 4)
         Z1 = "pF"
      End If

      If Vl = 7 Then
         V1 = Mid(v1 , 1 , 4)
         V1 = Format(v1 , "00.00")
         Z1 = "nF"
      End If

      If Vl = 8 Then
         V1 = Mid(v1 , 1 , 4)
         V1 = Format(v1 , "000.0")
         Z1 = "nF"
      End If

      If Vl = 9 Then
         V1 = Mid(v1 , 1 , 4)
         V1 = Format(v1 , "0.000")
         Z1 = "uF"
      End If

      Vs = Space(8)
      Locate 2 , 1
      Lcd "   Cx=" ; V1 ; Z1 ; Vs

      Locate 1 , 1
      Lcd "TestC "

   End If

   '/电感Lx计算/

   If I = 3 Then

      Vf = Str(f1)
      Vf = Format(vf , "      ")
      If F1 < 50 Then
         Vf = "     0"
      End If
      Locate 1 , 7
      Lcd "F=" ; Vf ; "Hz"

      Portd.4 = 0       '输入端切换到测电感

      If F1 > 1000 Then
         F11 = F1 * F1
         Lx = Ca1 / F11
         Lx = Lx - 1
         Lx = Lx * L1
      Else
         Lx = 0
      End If
      V1 = Fusing(lx , "#.##")
      Vl = Len(v1)
      Z1 = "uH"

      If Vl = 6 Then
         V1 = Mid(v1 , 1 , 5)
         Z1 = "uH"
      End If

      If Vl = 7 Then
         V1 = Mid(v1 , 1 , 4)
         V1 = Format(v1 , "0.000")
         Z1 = "mH"
      End If

      If Vl = 8 Then
         V1 = Mid(v1 , 1 , 4)
         V1 = Format(v1 , "00.00")
         Z1 = "mH"
      End If

      If Vl = 9 Then
         V1 = Mid(v1 , 1 , 4)
         V1 = Format(v1 , "000.0")
         Z1 = "mH"
      End If

      If Vl = 10 Then
         V1 = Mid(v1 , 1 , 4)
         V1 = Format(v1 , "0.000")
         Z1 = "H "
      End If

      Vs = Space(8)
      Locate 2 , 1
      Lcd "   Lx=" ; V1 ; Z1 ; Vs

      Locate 1 , 1
      Lcd "TestL "

   End If

   '/电解电容器测量(<500uF) /

   If I = 4 Then
      Portd.4 = 1
      If K = 1 Then

         Disable Ovf1
         Disable Ovf2

         Enable Int0
         Enable Ovf0

         Locate 1 , 1
         Lcd "TestCE  [<500uF]"
         Locate 2 , 1
         Lcd "   CEx=       "

      End If
      K = 0

   Portd.6 = 0       '开始充电
   Start Timer0       '开始计时
   End If

   '/电解电容测量(2) /

   If I = 5 Then

      If M = 1 Then
         Portd.3 = 0
         Locate 1 , 1
         Lcd "TestCE  [>500uF]"
         Locate 2 , 1
         Lcd "   CEx=       "
      End If
      M = 0
      Portd.6 = 0       '开始充电
      Start Timer0       '开始计时
   End If


'/返回到电容测量//

   If I = 6 Then

      I = 2       '返回到电容测量

      Enable Ovf1
      Enable Ovf2

      Disable Int0
      Disable Ovf0

      Portd.3 = 1
      K = 1
      M = 1
   End If

Loop
End

'/计数中断/

Tim1_isr:

   Incr Tc1       '这么作可使计数分辩率最高到1Hz

Return

'/定时中断/

Tim2_isr:

   Tcnt2 = &H83       '定时器T2初值
   Incr Tc
   If Tc = 250 Then       '定时250mS
      Stop Counter1
      Tc1 = Tc1 * 65535
      If Portd.3 = 1 Then
         F1 = Counter1
         F1 = F1 + Tc1
         F1 = F1 * 4
      End If
      If Portd.3 = 0 Then
         F2 = Counter1
         F2 = F2 + Tc1
         F2 = F2 * 4
      End If
      Counter1 = 0
      Start Counter1
      Tc = 0
      Tc1 = 0
   End If

Return

'/定时中断,测电解电容/

Tim0_isr:

   Incr Te       '定时器0中断次数

Return

'/外部中断,测电解电容/

T1_isr:

   Stop Timer0

   Te = Te * 256
   Te = Te + Tcnt0
   Te = Te / 2       '时间/充电电阻=被测电容

   V1 = Str(te)
   Vl = Len(v1)

   If Portd.3 = 1 Then       '充电电阻R9接入,<500uF

       If Vl = 2 Then
          V1 = "NO"
       End If

       If Vl = 3 Then
          V1 = Mid(v1 , 1 , 3)
          V1 = Format(v1 , "0.000")
       End If

       If Vl = 4 Then
          V1 = Mid(v1 , 1 , 3)
          V1 = Format(v1 , "0.00")
       End If

       If Vl = 5 Then
          V1 = Mid(v1 , 1 , 3)
          V1 = Format(v1 , "0.0")
       End If

       If Vl = 6 Then
          V1 = Mid(v1 , 1 , 3)
       End If

       If Vl = 7 Then
          V1 = "  OL  "
       End If

   End If

   If Portd.3 = 0 Then

      If Vl = 2 Then
         V1 = Mid(v1 , 1 , 2)
         V1 = Format(v1 , "0.00")
      End If

      If Vl = 3 Then
         V1 = Mid(v1 , 1 , 3)
         V1 = Format(v1 , "0.00")
      End If

      If Vl = 4 Then
         V1 = Mid(v1 , 1 , 2)
      End If

      If Vl = 5 Then
         V1 = Mid(v1 , 1 , 3)
      End If

      If Vl = 6 Then
         V1 = Mid(v1 , 1 , 4)
      End If

      If Vl = 7 Then
         V1 = Mid(v1 , 1 , 5)
      End If
   End If

   Vs = Space(7)

   If Te > 1 And Te < 10 Then

      Locate 2 , 1
      Lcd "   CEx=" ; "0" ; "uF" ; Vs

   End If

   If Te > 10 Then

      Locate 2 , 1
      Lcd "   CEx=" ; V1 ; "uF" ; Vs

   End If

   Portd.6 = 1       '开始放电

   If Portd.3 = 1 And Te > 10 Then
      Waitms 100
   End If
   If Portd.3 = 0 And Te > 10 Then
      Waitms 500
   End If

   Tcnt0 = 0       '定时计数器清零
   Te = 0       '定时中断次数清零

Return

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值