想做一蓝牙地址自加的界面后写入蓝牙芯片中,写入成功后界面中的地址自动加一,继续下一个IC的地址输入.打算用VB做界面,将起始地址输入到界面内,单击"输入"按键,则蓝牙地址通过计算机主机的并口输出,输出到并口转换板(型号为IDS-1309C,淘宝上买的 http://item.taobao.com/item.htm?id=4456008392)上在通过SPI写入蓝牙IC中.问题1:如何将界面中的数据(既蓝牙地址)输出到并口(即VB如何进行并口通信)?问题2:估计是要通过计算机并口模拟SPI通信,25PIN并口如何模拟SPI通信?大致思路是怎样?
解决方案 »
- Acess数据库,ORDER BY 子句语法错误,奇怪了!
- 求各位帮忙:listview的listitem对象定义问题,急急,在线等!!
- 如何得到当前文件的路径?
- 为什么我的帖子找不到了?
- 高手请进!!!!(送分)
- 如何得到计算机名?
- 如何才能让表中的数据保留两位小数?
- vb和用ado编程实现与sql server 2000数据库的连接的疑难问题(救急)
- 修改表结构,MyTXT = txtFields(0),cn.Execute "Alter Table PersonResult Add '" & MyTXT & "' numeric(18,0) null",这样为何不行?
- 请问如何将数据库(Access)里的图片吊入VB的Image控件里显示出来?是不是要设置ODBC数据源,该如何设置?
- 我自己做了一个OCX控件想在ASP中用,怎么才能让这个控件是一个安全的控件(IE不提示)
- VB到底可不可以调matlab生成的com组件?
http://download.csdn.net/source/2321502
这个事情我干过。1 到网上下载一个 Dllport.dll 之类的库。里面有两个函数Public Declare Function Inp Lib "DLLPORT.dll" Alias "Inp32" (ByVal PortAddress As Integer) As BytePublic 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 --GND3 用 VB 控制 /SS 和时钟线的同时,读写数据线。
下面是两个主要的模块代码:'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 ExplicitPublic SCKActive As Long
'As Clock, the /Strobe is hardware inverted
Public Const SCKHighActive As Long = 0
Public Const SCKLowActive As Long = 1Public SCKPhase As Long
Public Const SCKPhase1st As Long = 0
Public Const SCKPhase2nd As Long = 1Public SCKFrequency As LongPublic BitSequence As Long
Public Const MSBFirst As Long = 0
Public Const LSBFirst As Long = 1Public SCKHalf As Long
Public SampleFirst As Long
Public SampleDelta As LongConst SSInactive As Byte = &H80
Const SSActive As Byte = &H0Const DataPort As Integer = &H378
Const StatePort As Integer = &H379
Const ControlPort As Integer = &H37ADim ByteToSend As Byte
Dim Sample1 As Byte
Dim Sample2 As Byte
Dim Sample3 As Byte
Dim ByteReceived As Byte
Dim i As IntegerPublic Sub SCKDelay(ByVal X As Long)
QueryPerformanceCounter T1
Do
QueryPerformanceCounter T2
Loop Until (T2.lowpart - T1.lowpart) >= X
End SubPublic 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 SubPublic 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
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 SinglePublic TickPerCycle As Single
'Public Overhead As SinglePublic Declare Function GetTickCount Lib "kernel32" () As Long