[電腦討論]

(vb6.0)關於程式的時脈問題

本帖最後由 boy212322 於 2009-5-4 21:35 編輯

請問下面這程式時脈小弟設的正確嗎~~為何程式不理我
還是根本就是錯的~~請大大們幫幫忙

Private Declare Function OpenDecPort Lib "DecLib.dll" Alias _
"_OpenDecPort@0" () As Boolean

Private Declare Sub ClosePort Lib "DecLib.dll" Alias _
"_CloseDecPort@0" ()

Private Declare Function outportb Lib "DecLib.dll" Alias _
"_outportb@8" (ByVal PortAddress As Long, _
ByVal state As Byte) As Boolean

Private Declare Function outport Lib "DecLib.dll" Alias _
"_outport@8" (ByVal PortAddress As Long, _
ByVal state As Long) As Boolean


Private Declare Function inportb Lib "DecLib.dll" Alias _
"_inportb@4" (ByVal PortAddress As Long) As Byte

Private Declare Function inport Lib "DecLib.dll" Alias _
"_inport@4" (ByVal PortAddress As Long) As Long

Private Declare Function GetDevicePortAddressEx Lib _
"DecLib.dll" Alias "_GetDevicePortAddressEx@4" ( _
Address As Long) As Boolean

Private Declare Function GetDevicePortAddress Lib _
"DecLib.dll" Alias "_GetDevicePortAddress@8" ( _
ByVal CardID As Integer, Address As Long) As Boolean

Dim counter As Integer
Dim adr As Long
Dim IO_ch As Boolean, Run As Boolean
Dim porta(23) As Boolean, portb(23) As Boolean

Private Sub End_BT_Click()
End
End Sub

Private Sub Form_Load()

If OpenDecPort() Then
If GetDevicePortAddress(2, adr) Then
   Label3.Caption = "PCI8255卡位址正確!!!"
Else
   Label3.Caption = "PCI8255卡位址錯誤!!!"
End If
Else
   Label3.Caption = "找不到端口!!!"
End If

IO_ch = True
Run = True
counter = 0
End Sub


Private Sub Strat_BT_Click()

Dim A1 As Byte, A2 As Byte, A3 As Byte
Dim B As Long
Dim TorF As Boolean

If Run Then
  Strat_BT.Caption = "終止"
  Label7.Caption = " 輸出O/p"
    B = Val(InputBox("請輸入輸出位元組數值(10進制)"))
    TorF = outportb(adr + 3, &H80)
    TorF = outportb(adr + 7, &H9B)
    A1 = B And &HFF
    A2 = B \ (2 ^ 8) And &HFF
    A3 = B \ (2 ^ 16) And &HFF
    TorF = outportb(adr, A1)
    TorF = outportb(adr + 1, A2)
    TorF = outportb(adr + 2, A3)
    TorF = DisplayPortSignal(B, False)
    OutP.Caption = Hex(B)
   
Else
Strat_BT.Caption = "執行"
End If
Run = Not Run
End Sub

Function DisplayPortSignal(ByVal signal As Long, ByVal io As Boolean)

  Dim i, j As Integer
  Dim TorF As Boolean

  If (io = False) Then
    For j = 0 To 23
      Shape1(j).FillColor = RGB(0, 0, 0)
    Next

    For i = 0 To 23

      If (signal Mod 2 = 1) Then
        TorF = True
      Else
        TorF = False
      End If
      signal = signal \ 2

      If (TorF) Then
        Shape1(i).FillColor = RGB(0, 255, 0)
      End If
    Next
  


  End If
End Function

Private Sub Timer1_Timer()
Dim A1 As Byte, A2 As Byte, A3 As Byte
  Dim X, Z As Long
Dim TorF As Boolean
  If (IO_ch = True) Then
    Label7.Caption = " Output"

    TorF = outportb(adr + 3, &H80)
    TorF = outportb(adr + 7, &H9B)
    Timer1.Interval = Speed.Value
  
    X = 1 * (2 ^ counter)
    A1 = X And &HFF
    A2 = X \ (2 ^ 8) And &HFF
    A3 = X \ (2 ^ 16) And &HFF
    TorF = outportb(adr, A1)
    TorF = outportb(adr + 1, A2)
    TorF = outportb(adr + 2, A3)
    TorF = DisplayPortSignal(X, False)
    OutP.Caption = Hex(X)
   
   
    If counter = 24 Then
    IO_ch = False
    counter = 0
    End If
     Else
   Label7.Caption = "  Input"
  
   TorF = outportb(adr + 7, &H80)
   TorF = outportb(adr + 3, &H9B)
   Timer1.Interval = Speed.Value
   X = 1 * (2 ^ counter)
   x1 = X And &HFF
   x2 = X \ (2 ^ 8) And &HFF
   x3 = X \ (2 ^ 16) And &HFF
   TorF = outportb(adr + 4, x1)
   TorF = outportb(adr + 5, x2)
   TorF = outportb(adr + 6, x3)
   TorF = DisplayPortSignal(X, True)
   OutP.Caption = Hex(X)
   
   If counter = 24 Then
   IO_ch = True
   counter = 0
   End If
   
   End If
End Sub
喜歡這篇文章嗎?
回覆 0
您需要登入後才可以回帖 登入 | 註冊會員

本版積分規則 回覆 15 個字以上可拿獎勵,
規則詳見此

精選熱門商品

提示訊息
go_top