📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "MCP320X"
ClientHeight = 1935
ClientLeft = 45
ClientTop = 330
ClientWidth = 7635
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1935
ScaleWidth = 7635
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "Start"
Height = 255
Left = 6840
TabIndex = 26
Top = 120
Width = 615
End
Begin MSCommLib.MSComm MSComm1
Left = 960
Top = 2880
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 1000
Left = 3360
Top = 0
End
Begin VB.TextBox Text1
Alignment = 2 'Center
BeginProperty DataFormat
Type = 1
Format = "0.000"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 1033
SubFormatType = 1
EndProperty
Height = 285
Left = 4800
MaxLength = 5
TabIndex = 15
Text = "5.000"
Top = 1200
Width = 615
End
Begin ComctlLib.Slider Slider1
Height = 375
Left = 4800
TabIndex = 13
Top = 480
Width = 2535
_ExtentX = 4471
_ExtentY = 661
_Version = 327682
LargeChange = 3
Min = 1
SelStart = 1
Value = 1
End
Begin VB.Frame HARDWARE
Caption = "HARDWARE"
Height = 1815
Left = 0
TabIndex = 0
Top = 120
Width = 4695
Begin VB.Frame Frame3
Caption = "Buffer"
Height = 1455
Left = 2760
TabIndex = 9
Top = 240
Width = 1815
Begin VB.CheckBox Check1
Caption = "Supply pulse"
Height = 255
Left = 120
TabIndex = 27
Top = 1080
Width = 1455
End
Begin VB.CheckBox Check6
Caption = "Invert Dout"
Enabled = 0 'False
Height = 255
Left = 120
TabIndex = 12
Top = 720
Width = 1095
End
Begin VB.CheckBox Check5
Caption = "Invert CLK"
Enabled = 0 'False
Height = 255
Left = 120
TabIndex = 11
Top = 480
Width = 1455
End
Begin VB.CheckBox Check4
Caption = "Invert CS"
Enabled = 0 'False
Height = 255
Left = 120
TabIndex = 10
Top = 240
Width = 1455
End
End
Begin VB.Frame Frame2
Caption = "ADC"
Height = 1455
Left = 1200
TabIndex = 5
Top = 240
Width = 1575
Begin VB.OptionButton Option6
Caption = "MCP3202CH1"
Enabled = 0 'False
Height = 315
Left = 120
TabIndex = 8
Top = 1080
Width = 1335
End
Begin VB.OptionButton Option5
Caption = "MCP3202CH0"
Enabled = 0 'False
Height = 255
Left = 120
TabIndex = 7
Top = 720
Width = 1335
End
Begin VB.OptionButton Option4
Caption = "MCP3201"
Height = 255
Left = 120
TabIndex = 6
Top = 360
Value = -1 'True
Width = 1095
End
End
Begin VB.Frame Frame1
Caption = "Port"
Height = 1455
Left = 120
TabIndex = 1
Top = 240
Width = 1095
Begin VB.OptionButton Option3
Caption = "COM3"
Height = 255
Left = 120
TabIndex = 4
Top = 1080
Width = 855
End
Begin VB.OptionButton Option2
Caption = "COM2"
Height = 255
Left = 120
TabIndex = 3
Top = 720
Width = 855
End
Begin VB.OptionButton Option1
Caption = "COM1"
Height = 255
Left = 120
TabIndex = 2
Top = 360
Width = 855
End
End
End
Begin VB.Label Label10
Caption = " 1Hz"
Height = 255
Left = 6000
TabIndex = 25
Top = 120
Width = 495
End
Begin VB.Label Label9
Caption = "Volts"
Height = 255
Left = 6960
TabIndex = 24
Top = 1560
Width = 495
End
Begin VB.Label Label8
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = "4096"
Height = 255
Left = 5280
TabIndex = 23
Top = 1680
Width = 615
End
Begin VB.Line Line1
BorderWidth = 3
X1 = 4800
X2 = 6360
Y1 = 1560
Y2 = 1560
End
Begin VB.Label Label7
Caption = "Messure"
Height = 255
Left = 6960
TabIndex = 22
Top = 960
Width = 615
End
Begin VB.Label Label6
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = "0"
Height = 255
Left = 6840
TabIndex = 21
Top = 1200
Width = 615
End
Begin VB.Label Label3
Caption = "="
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Index = 1
Left = 6480
TabIndex = 20
Top = 1440
Width = 255
End
Begin VB.Label Label5
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = "0"
Height = 255
Left = 5760
TabIndex = 19
Top = 1200
Width = 615
End
Begin VB.Label Label4
Caption = "Code_in"
Height = 255
Left = 5760
TabIndex = 18
Top = 960
Width = 855
End
Begin VB.Label Label3
Caption = "X"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Index = 0
Left = 5520
TabIndex = 17
Top = 1200
Width = 255
End
Begin VB.Label Label2
Alignment = 2 'Center
Caption = "Ref"
Height = 255
Left = 4800
TabIndex = 16
Top = 960
Width = 615
End
Begin VB.Label Label1
Caption = "Fe [Hz]"
Height = 255
Left = 4920
TabIndex = 14
Top = 120
Width = 735
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public comport As Byte
Public adcip As Byte
Private Sub Check4_Click()
Timer1.Enabled = Check4.Value
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
comport = 1
'initializehardware (comport)
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
resetpow
MSComm1.PortOpen = False
End Sub
Private Sub Option1_Click()
comport = 1
initializehardware (comport)
End Sub
Private Sub Option2_Click()
comport = 2
initializehardware (comport)
End Sub
Private Sub Option3_Click()
comport = 3
initializehardware (comport)
End Sub
Private Sub option4_click()
MsgBox "Only MCP3201 is supported", vbInformation, "NOT IMPLEMENTED"
adcip = 2
End Sub
Private Sub Option5_Click()
MsgBox "Only MCP3201 is supported", vbInformation, "NOT IMPLEMENTED"
adcip = 0
End Sub
Private Sub Option6_Click()
MsgBox "Only MCP3201 is supported", vbInformation, "NOT IMPLEMENTED"
adcip = 1
End Sub
Private Sub Slider1_Click()
Label10.Caption = Str(Slider1.Value) + "Hz"
Timer1.Interval = CInt(1000 / Slider1.Value)
End Sub
Private Sub sendclk()
On Error GoTo erorp
Static m(0) As Byte
m(0) = 0
While MSComm1.OutBufferCount <> 0
Sleep (1)
Wend
MSComm1.Output = m
While MSComm1.OutBufferCount <> 0
Sleep (1)
Wend
Exit Sub
erorp:
Timer1.Enabled = False
MsgBox "COM Port error, chose another", vbCritical, "COM_ERROR"
End Sub
Private Sub setpow()
On Error GoTo erorp
MSComm1.RTSEnable = True
Exit Sub
erorp:
Timer1.Enabled = False
MsgBox "COM Port error, chose another", vbCritical, "COM_ERROR"
End Sub
Private Sub resetpow()
On Error GoTo erorp
MSComm1.RTSEnable = False
Exit Sub
erorp:
Timer1.Enabled = False
MsgBox "COM Port error, chose another", vbCritical, "COM_ERROR"
End Sub
Private Sub setcs()
On Error GoTo erorp
MSComm1.DTREnable = True
Exit Sub
erorp:
Timer1.Enabled = False
MsgBox "COM Port error, chose another", vbCritical, "COM_ERROR"
End Sub
Private Sub resetcs()
On Error GoTo erorp
MSComm1.DTREnable = False
Exit Sub
erorp:
Timer1.Enabled = False
MsgBox "COM Port error, chose another", vbCritical, "COM_ERROR"
End Sub
Private Function readbit() As Boolean
On Error GoTo erorp
readbit = MSComm1.CDHolding
Exit Function
erorp:
Timer1.Enabled = False
MsgBox "COM Port error, chose another", vbCritical, "COM_ERROR"
End Function
Private Sub initializehardware(com As Byte)
On Error GoTo erorp
'if succes then timer1.enable, else disable
If MSComm1.PortOpen Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = com
MSComm1.Handshaking = comNone
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
'stupid led blink
setpow
Sleep (100)
resetpow
Sleep (100)
setpow
Sleep (100)
resetpow
Sleep (100)
'Timer1.Enabled = True
Exit Sub
erorp:
Timer1.Enabled = False
MsgBox "COM Port error, chose another", vbCritical, "COM_ERROR"
End Sub
Private Function readanalog() As Integer
Static r As Integer
Static c As Integer
c = 0
setpow
Sleep (50)
resetcs
Sleep (1)
sendclk
sendclk
sendclk
For r = 11 To 0 Step -1
sendclk
If readbit Then c = c + (2 ^ r)
Next
setcs
If Check1.Value Then
resetpow
End If
readanalog = c
End Function
Private Sub disp()
Static v As Boolean
Static s As Integer
s = readanalog
's = 2802
Label5.Caption = Str(s)
If (Val(Text1.Text) < 0) Or (Val(Text1.Text) > 7) Then
v = Timer1.Enabled
MsgBox "0 < Uref < 7 [Volts]", vbCritical, "Uref"
Timer1.Enabled = False
Text1.SelStart = 0
Text1.SelLength = Text1.MaxLength
Text1.SetFocus
End If
Label6.Caption = Format((s * Val(Text1.Text) / 4096), "0.000")
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not (IsNumeric(Chr(KeyAscii))) And (Chr(KeyAscii) <> ".") Then
KeyAscii = 0
End If
End Sub
Private Sub Timer1_Timer()
disp
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -