想做一藍牙地址自加的界面后寫入藍牙芯片中,寫入成功后界面中的地址自動加一,繼續下一個IC的地址輸入.
打算用VB做界面,將起始地址輸入到界面內,單擊"輸入"按鍵,則藍牙地址通過計算機主機的并口輸出,輸出到并口轉換板(型號為IDS-1309C,淘寶上買的 http://item.taobao.com/item.htm?id=4456008392)上在通過SPI寫入藍牙IC中.
問題1:如何將界面中的資料(既藍牙地址)輸出到并口(即VB如何進行并口通信)?
問題2:估計是要通過計算機并口模擬SPI通信,25PIN并口如何模擬SPI通信?大致思路是怎樣?
uj5u.com熱心網友回復:
比串口麻煩一些,參考。uj5u.com熱心網友回復:
參考這里uj5u.com熱心網友回復:
使用并口一般需要使用驅動級的元件,比如WinIO.dll不過都比較復雜。樓上兩位已經給出了例子,我就不再獻丑了。uj5u.com熱心網友回復:
非常感謝,一定認真參考。uj5u.com熱心網友回復:
WINIO那個貌似WIN9X下面的東東了.uj5u.com熱心網友回復:
比串口麻煩一些uj5u.com熱心網友回復:
XP下是能使用的
http://download.csdn.net/source/2321502
uj5u.com熱心網友回復:
這個事情我干過。
1 到網上下載一個 Dllport.dll 之類的庫。里面有兩個函式
Public Declare Function Inp Lib "DLLPORT.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Byte
Public Declare Sub Out Lib "DLLPORT.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Byte)
2 如下連接并口和 SPI 線:
'并口引腳編號 并口引腳名稱 暫存器地址 資料位 對應SPI引腳
'11 狀態Busy 0x379 Bit 7 MISO
'2 資料Data0 0x378 Bit 0 MOSI
'1 控制Strobe 0x37A Bit 0 SCK
'9 資料Data7 0x378 Bit 7 /SS
'25 地 GND --GND
3 用 VB 控制 /SS 和時鐘線的同時,讀寫資料線。
uj5u.com熱心網友回復:
這個新鮮,能否具體些?
uj5u.com熱心網友回復:
能否具體一點,不會用呢!uj5u.com熱心網友回復:
這么老的帖子能翻出來。下面是兩個主要的模塊代碼:
'Declare Inp and Out for port I/O
Public Declare Function Inp Lib "DLLPORT.dll" _
Alias "Inp32" (ByVal PortAddress As Integer) As Byte
Public Declare Sub Out Lib "DLLPORT.dll" _
Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Byte)
Option Explicit
Public SCKActive As Long
'As Clock, the /Strobe is hardware inverted
Public Const SCKHighActive As Long = 0
Public Const SCKLowActive As Long = 1
Public SCKPhase As Long
Public Const SCKPhase1st As Long = 0
Public Const SCKPhase2nd As Long = 1
Public SCKFrequency As Long
Public BitSequence As Long
Public Const MSBFirst As Long = 0
Public Const LSBFirst As Long = 1
Public SCKHalf As Long
Public SampleFirst As Long
Public SampleDelta As Long
Const SSInactive As Byte = &H80
Const SSActive As Byte = &H0
Const DataPort As Integer = &H378
Const StatePort As Integer = &H379
Const ControlPort As Integer = &H37A
Dim ByteToSend As Byte
Dim Sample1 As Byte
Dim Sample2 As Byte
Dim Sample3 As Byte
Dim ByteReceived As Byte
Dim i As Integer
Public Sub SCKDelay(ByVal X As Long)
QueryPerformanceCounter T1
Do
QueryPerformanceCounter T2
Loop Until (T2.lowpart - T1.lowpart) >= X
End Sub
Public Sub SendByte(ByVal a As Byte)
ByteToSend = a
'set clock to inactive
Out ControlPort, SCKActive Xor 1
Out DataPort, SSActive
'If SCKPHA = 1 then delay a half of a clock cycle
If SCKPhase = SCKPhase2nd Then SCKDelay SCKHalf
For i = 1 To 8
'data bit change
If BitSequence = MSBFirst Then
If (ByteToSend And &H80) > 0 Then
Out DataPort, SSActive Or 1
Else
Out DataPort, SSActive
End If
ByteToSend = ((ByteToSend And &H7F) * 2)
Else
If ByteToSend And &H1 > 0 Then
Out DataPort, SSActive Or 1
Else
Out DataPort, SSActive
End If
ByteToSend = ByteToSend \ 2
End If
'Switching clock
If SCKPhase = SCKPhase2nd Then
Out ControlPort, SCKActive
Else
Out ControlPort, (SCKActive Xor 1)
End If
SCKDelay SCKHalf
'Switching clock
If SCKPhase = SCKPhase1st Then
Out ControlPort, SCKActive
Else
Out ControlPort, (SCKActive Xor 1)
End If
SCKDelay SCKHalf
Next i
'If SCKPHA = 0 then switch clock to inactive and delay a half of a clock cycle
If SCKPhase = SCKPhase1st Then
Out ControlPort, SCKActive
SCKDelay SCKHalf
End If
Out DataPort, SSInactive
SCKDelay SCKHalf
End Sub
Public Function RecvByte() As Byte
'set clock to inactive
Out ControlPort, SCKActive Xor 1
Out DataPort, SSActive
'If SCKPHA = 1 then delay a half of a clock cycle
If SCKPhase = SCKPhase2nd Then SCKDelay SCKHalf
ByteReceived = 0
For i = 1 To 8
'Switching clock
If SCKPhase = SCKPhase2nd Then
Out ControlPort, SCKActive
Else
Out ControlPort, (SCKActive Xor 1)
End If
'Sample triple
SCKDelay SampleFirst
Sample1 = (Inp(StatePort) And &H80) / 128
SCKDelay SampleDelta
Sample2 = (Inp(StatePort) And &H80) / 128
SCKDelay SampleDelta
Sample3 = (Inp(StatePort) And &H80) / 128
Sample1 = Sample1 + Sample2 + Sample3
'Get a bit
If BitSequence = MSBFirst Then
ByteReceived = (ByteReceived And &H7F) * 2
If Sample1 < 2 Then ByteReceived = ByteReceived Or 1
Else
ByteReceived = ByteReceived \ 2
If Sample1 < 2 Then ByteReceived = ByteReceived Or &H80
End If
'Switching clock
If SCKPhase = SCKPhase1st Then
Out ControlPort, SCKActive
Else
Out ControlPort, (SCKActive Xor 1)
End If
SCKDelay SCKHalf
Next i
'If SCKPHA = 0 then switch clock to inactive and delay a half of a clock cycle
If SCKPhase = SCKPhase1st Then
Out ControlPort, SCKActive
SCKDelay SCKHalf
End If
Out DataPort, SSInactive
SCKDelay SCKHalf
RecvByte = ByteReceived
End Function
uj5u.com熱心網友回復:
哦,還缺一個定時模塊:
Option Explicit
Public Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As LARGE_INTEGER) As Long
Public Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As LARGE_INTEGER) As Long
Public Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
Public T1 As LARGE_INTEGER, T2 As LARGE_INTEGER
Public SYSFrequency As LARGE_INTEGER
'Public tt As Single, totalTime As Single, sngTime As Single
Public TickPerCycle As Single
'Public Overhead As Single
Public Declare Function GetTickCount Lib "kernel32" () As Long
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/153378.html
標籤:控件
上一篇:軟體啟動界面檢測是否有網路連接
