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

📄 nt_8255.frm

📁 《Verilog-HDL实践与应用系统设计》一书中的光盘源文件
💻 FRM
📖 第 1 页 / 共 2 页
字号:
         Appearance      =   0  'Flat
         BackColor       =   &H0000FFFF&
         BorderStyle     =   1  'Fixed Single
         Caption         =   "1"
         ForeColor       =   &H80000008&
         Height          =   255
         Index           =   2
         Left            =   5880
         TabIndex        =   3
         Top             =   3840
         Width           =   375
      End
      Begin VB.Label Label5 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H0000FFFF&
         BorderStyle     =   1  'Fixed Single
         Caption         =   "1"
         ForeColor       =   &H80000008&
         Height          =   255
         Index           =   1
         Left            =   5880
         TabIndex        =   2
         Top             =   4080
         Width           =   375
      End
      Begin VB.Label Label5 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H0000FFFF&
         BorderStyle     =   1  'Fixed Single
         Caption         =   "1"
         ForeColor       =   &H80000008&
         Height          =   255
         Index           =   0
         Left            =   5880
         TabIndex        =   1
         Top             =   4320
         Width           =   375
      End
   End
   Begin PicClip.PictureClip PictureClip2 
      Left            =   0
      Top             =   120
      _ExtentX        =   3942
      _ExtentY        =   1402
      _Version        =   393216
      Cols            =   2
      Picture         =   "NT_8255.frx":6133
   End
   Begin VB.Label Label4 
      Alignment       =   2  'Center
      BackColor       =   &H00C0FFC0&
      Caption         =   "并行接口板测试程序"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   18
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2160
      TabIndex        =   35
      Top             =   240
      Width           =   3975
   End
   Begin VB.Image Image1 
      Height          =   495
      Left            =   5040
      Top             =   3600
      Width           =   1215
   End
End
Attribute VB_Name = "Test_8255"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False



Dim A_flg As Integer
Dim B_flg As Integer
Dim C_flg As Integer

Dim A_dec As Integer
Dim B_dec As Integer
Dim C_dec As Integer


Dim A_data As Integer
Dim B_data As Integer
Dim C_l_data As Integer
Dim C_H_data As Integer

Function d_to_h(ByVal ddat As String) As String
    d_to_h = Hex$(Val(ddat))
End Function

Function h_to_d(ByVal hdat As String) As String
    Dim dval As Long
    Dim hexchar As String
    Dim hexval As String
    Dim i As Integer
    Dim power As Long
    Dim tempval As Integer
    hexchar = "123456789ABCDEF"
    hexval = UCase$(hdat)
    dval = 0
    For i = 1 To Len(hexval)
        power = 16 ^ (Len(hexval) - i)
        tempval = InStr(hexchar, Mid$(hexval, i, 1))
        dval = dval + (tempval * power)
    Next i
    h_to_d = Str$(dval)
End Function

Sub Init_ptrans_port()
    If t8255_flg = False Then
        t8255_sts = Set_8255_sts()
        P8255B_init_8255 (t8255_sts)
        End If
    t8255_flg = True
End Sub

Sub Input_port_datas()
    Dim datas  As Integer
    Dim data_c As Integer
    
    If A_data = 1 Then
        datas = P8255B_read_data(A_port)
        Text1.Text = Hex(datas)
        End If
    If B_data = 1 Then
        datas = P8255B_read_data(B_port)
        Text2.Text = Hex(datas)
        End If
        
    If C_l_data = 1 Then
        data_c = P8255B_read_data(C_port)
        datas = data_c And &HF
        datas = datas Or (C_dec And &HF0)
        C_dec = datas
        Text3.Text = Hex(C_dec)
        End If
    If C_H_data = 1 Then
        data_c = P8255B_read_data(C_port)
        datas = data_c And &HF0
        datas = datas Or (C_dec And &HF)
        C_dec = datas
        Text3.Text = Hex(C_dec)
        End If
End Sub




Sub Put_datas_to_port()
    If A_data = 0 Then
        P8255B_out_data A_port, A_dec
        End If
    If B_data = 0 Then
        P8255B_out_data B_port, B_dec
        End If
    If C_l_data = 0 Then
        P8255B_out_data C_port, C_dec
        End If
    If C_H_data = 0 Then
        P8255B_out_data C_port, C_dec
        End If

End Sub

Function Set_8255_sts() As Integer
    Dim stss As String
    Dim datas As Double
    
    datas = "100" & A_data & C_H_data & "0" & B_data & C_l_data
    'Label17.Caption = datas '二进制显示
    stss = Str$(datas)
    datas = 0
    For i = 2 To 9
        If Val(Mid$(stss, i, 1)) = 1 Then
            datas = datas + 2 ^ (Val(Mid$(stss, i, 1)) * (9 - i))
            End If
        Next i
    Label11.Caption = "8255控制字: " & Hex(datas) & "H"
    Set_8255_sts = datas
    Exit Function
End Function


Sub Set_bit(para As Integer, code As Integer)
    Dim i As Integer
    Dim datas As Byte
    Dim da As Integer
    Select Case para
        Case C_port
             For i = 0 To 7
                datas = (2 ^ i) And code
                Label7(i) = rsft(datas, i)
                Next
       Case B_port
             For i = 0 To 7
                datas = (2 ^ i) And code
                Label5(i) = rsft(datas, i)
                Next

       Case A_port
             For i = 0 To 7
                datas = (2 ^ i) And code
                Label6(i) = rsft(datas, i) And 1  '取值只有一位,这一位有点问题
                Next

        End Select

End Sub

Sub Set_cport_data(port As Integer)
    Dim code As Integer
    Select Case port
        Case A_port
            If Label8.Caption = "DEC" Then
                Label8_Click
                End If
            If Label8.Caption = "HEX" Then
                code = Val(h_to_d(Text1.Text))
                Set_bit A_port, code
                A_dec = code
                End If
        Case B_port
            If Label9.Caption = "DEC" Then
                Label9_Click
                End If
            If Label9.Caption = "HEX" Then
                code = Val(h_to_d(Text2.Text))
                Set_bit B_port, code
                B_dec = code
                End If
        Case C_port
            If Label10.Caption = "DEC" Then
                Label10_Click
                End If
            If Label10.Caption = "HEX" Then
                code = Val(h_to_d(Text3.Text))
                Set_bit C_port, code
                C_dec = code
                End If
        End Select
End Sub


Sub Set_disp_datas()
    Set_cport_data (A_port)
    Set_cport_data (B_port)
    Set_cport_data (C_port)
End Sub







Private Sub AniPushButton1_Click()

End Sub



Private Sub Command1_Click()

End Sub

Private Sub Command10_Click()
     datas = P8255B_read_data(A_port)
     Text1.Text = Hex(datas)

    Put_datas_to_port   'data output
    Set_disp_datas
End Sub

Private Sub Command2_Click()
    Init_ptrans_port
End Sub

Private Sub Command3_Click()
    Unload Me
End Sub








Private Sub Command5_Click()
    t8255_sts = Set_8255_sts()
    P8255B_init_8255 (t8255_sts)

End Sub



Private Sub Command6_Click()
End Sub

Private Sub Command7_Click()
    Set_disp_datas
    Init_ptrans_port
    Input_port_datas      'data input
    Put_datas_to_port   'data output
    Set_disp_datas

End Sub

Private Sub Command8_Click()
    t8255_sts = Set_8255_sts()
    P8255B_init_8255 (t8255_sts)

    Timer1.Enabled = True
    Command8.Enabled = False
    Command9.Enabled = True
    
End Sub

Private Sub Command9_Click()
    Beep
    Timer1.Enabled = False
    Command8.Enabled = True
    Command9.Enabled = False
    
End Sub


Private Sub DAViewerControlWindowed1_Start()

End Sub

Private Sub Form_Load()
    form_init
    A_flg = 0
    B_flg = 0
    C_flg = 0
    
    A_data = 0
    B_data = 0
    C_l_data = 0
    C_H_data = 0
    
    t8255_flg = False
    Set_disp_datas
    Timer1.Enabled = False
    Picture1_Click
    Picture2_Click
    Picture3_Click
    Picture4_Click
End Sub

Private Sub form_init()
    Width = 8415
    Height = 8070
    Left = (Screen.Width - Width) / 2
    Top = (Screen.Height - Height) / 2
    'Picture1.Top = 33
    'Picture1.Left = (Width - Picture1.Width) / 2
End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label10_Click()
    If C_flg = 0 Then
        Label10.Caption = "DEC"
        Text3.Text = h_to_d(Text3.Text)
        C_dec = Text3.Text
        Label10.BackColor = &HFFFF&
        C_flg = 1
        Else
        Label10.Caption = "HEX"
        Text3.Text = d_to_h(Text3.Text And &HFF)
        Label10.BackColor = &HFFFF80
        C_flg = 0
        End If
    Set_bit C_port, C_dec
End Sub

Private Sub Label8_Click()
    If A_flg = 0 Then
        Label8.Caption = "DEC"
        Text1.Text = h_to_d(Text1.Text)
        A_dec = Text1.Text
        Label8.BackColor = &HFFFF&
        A_flg = 1
        Else
        Label8.Caption = "HEX"
        Text1.Text = d_to_h(Text1.Text And &HFF)
        Label8.BackColor = &HFFFF80
        A_flg = 0
        End If
    Set_bit A_port, A_dec
End Sub

Private Sub Label9_Click()
    If B_flg = 0 Then
        Label9.Caption = "DEC"
        Text2.Text = h_to_d(Text2.Text)
        B_dec = Text2.Text
        Label9.BackColor = &HFFFF&
        B_flg = 1
        Else
        Label9.Caption = "HEX"
        Text2.Text = d_to_h(Text2.Text And &HFF)
        Label9.BackColor = &HFFFF80
        B_flg = 0
        End If
    Set_bit B_port, B_dec
End Sub



Private Sub SpriteControl1_onplaymarker(ByVal MarkerName As String)

End Sub



Private Sub Picture1_Click()
    Select Case A_data
        Case 0
                 A_data = 1
                GoTo end_f
        Case 1
                 A_data = 0
                GoTo end_f
        End Select
end_f:
    
   Picture1.Picture = PictureClip2.GraphicCell(A_data)
    t8255_flg = False
      Command5_Click   '初始化
End Sub

Private Sub Picture2_Click()

    Select Case B_data
        Case 0
                 B_data = 1
                GoTo end_f
        Case 1
                 B_data = 0
                GoTo end_f
        End Select
end_f:
    
   Picture2.Picture = PictureClip2.GraphicCell(B_data)
    t8255_flg = False
     Command5_Click   '初始化
End Sub


Private Sub Picture3_Click()

    Select Case C_l_data
        Case 0
                C_l_data = 1
                GoTo end_f
        Case 1
                C_l_data = 0
                GoTo end_f
        End Select
end_f:
    
   Picture3.Picture = PictureClip2.GraphicCell(C_l_data)
    t8255_flg = False
      Command5_Click   '初始化
End Sub

Private Sub Picture4_Click()

    Select Case C_H_data
        Case 0
                C_H_data = 1
                GoTo end_f
        Case 1
                C_H_data = 0
                GoTo end_f
        End Select
end_f:
    
   Picture4.Picture = PictureClip2.GraphicCell(C_H_data)
    t8255_flg = False
    Command5_Click   '初始化
End Sub



Private Sub Text4_Click()

Text4.Text = Hex(Set_8255_sts)
End Sub

Private Sub Timer1_Timer()
    Command7_Click
End Sub


Private Sub Timer2_Timer()
Command10_Click
End Sub


⌨️ 快捷键说明

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