whyliving
Üye
- Katılım
- 31 Ocak 2008
- Mesajlar
- 30
- Puanları
- 1
- Yaş
- 40
Kod:
Device = 18F2550
XTAL = 48
USB_DESCRIPTOR = "USBProjectDESC.inc"
Symbol USBBufferSizeMax = 8
Symbol USBBufferSizeTX = 8
Symbol USBBufferSizeRX = 8
Dim USBBuffer[USBBufferSizeMax] As Byte
Dim PP0 As Byte SYSTEM ' USBPOLL status return
Symbol CARRY_FLAG = STATUS.0 ' high if microcontroller does not have control over the buffer
Symbol ATTACHED_STATE = 6 ' is USB attached
TRISB = %00000000
GoSub AttachToUSB
ProgramLoop:
USBBuffer[2] = PORTA
USBOut 1, USBBuffer, USBBufferSizeTX
USBIn 1, USBBuffer, USBBufferSizeRX, ProgramLoop
PORTB = USBBuffer[3]
GoTo ProgramLoop
DoUSBIn:
USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBIn
Return
DoUSBOut:
USBOut 1, USBBuffer, USBBufferSizeTX, DoUSBOut
Return
AttachToUSB:
Repeat
USBPoll
Until PP0 = ATTACHED_STATE
Return
Kod:
' vendor and product IDs
Private Const VendorID = 6114
Private Const ProductID = 2010
' read and write buffers
Private Const BufferInSize = 8
Private Const BufferOutSize = 8
Dim BufferIn(0 To BufferInSize) As Byte
Dim BufferOut(0 To BufferOutSize) As Byte
Private Sub Command1_Click()
BufferOut(4) = Val(Text1.Text)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Form_Load()
' do not remove!
ConnectToHID (Me.hwnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
DisconnectFromHID
End Sub
Public Sub OnPlugged(ByVal pHandle As Long)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
' ** YOUR CODE HERE **
End If
End Sub
Public Sub OnUnplugged(ByVal pHandle As Long)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
' ** YOUR CODE HERE **
End If
End Sub
Public Sub OnChanged()
Dim DeviceHandle As Long
DeviceHandle = hidGetHandle(VendorID, ProductID)
hidSetReadNotify DeviceHandle, True
End Sub
Public Sub OnRead(ByVal pHandle As Long)
' read the data (don't forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then
End If
End Sub
Public Sub WriteSomeData()
BufferOut(0) = 0 ' first by is always the report ID
BufferOut(1) = 10 ' first data item, etc etc
' write the data (don't forget, pass the whole array)...
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Text1_Change()
If Val(Text1.Text) > 255 Then Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub
If IsNumeric(Chr(KeyAscii)) = False Then KeyAscii = 0
End Sub