![]() |
|
Tài trợ cho PIC Vietnam |
Giao tiếp USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC |
|
Ðiều Chỉnh | Xếp Bài |
![]() |
#7 |
Đệ tử 1 túi
Tham gia ngày: Jul 2006
Bài gửi: 17
: |
vb 6 chạy ngon
thử nhé: ' vendor and product IDs Private Const VendorID = 2606 Private Const ProductID = 2007 ' read and write buffers Private Const BufferInSize = 9 Private Const BufferOutSize = 9 Dim BufferIn(0 To BufferInSize) As Byte Dim BufferOut(0 To BufferOutSize) As Byte Dim byteLED As Byte Private Sub Check3_Click() End Sub ' ************************************************** ************** ' when the form loads, connect to the HID controller - pass ' the form window handle so that you can receive notification ' events... '************************************************* **************** Private Sub Form_Load() ' do not remove! ConnectToHID (Me.hwnd) End Sub '************************************************* **************** ' disconnect from the HID controller... '************************************************* **************** Private Sub Form_Unload(Cancel As Integer) DisconnectFromHID End Sub '************************************************* **************** ' a HID device has been plugged in... '************************************************* **************** Public Sub OnPlugged(ByVal pHandle As Long) If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then LbStatus.Caption = "Hardware Connected" LED.FillColor = &HFF00& Counter = 0 ' ** YOUR CODE HERE ** End If End Sub '************************************************* **************** ' a HID device has been unplugged... '************************************************* **************** Public Sub OnUnplugged(ByVal pHandle As Long) If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then LbStatus.Caption = "Hardware not Found! Please plug hardware" LED.FillColor = &HFF& ' ** YOUR CODE HERE ** End If End Sub '************************************************* **************** ' controller changed notification - called ' after ALL HID devices are plugged or unplugged '************************************************* **************** Public Sub OnChanged() Dim DeviceHandle As Long ' get the handle of the device we are interested in, then set ' its read notify flag to true - this ensures you get a read ' notification message when there is some data to read... DeviceHandle = hidGetHandle(VendorID, ProductID) hidSetReadNotify DeviceHandle, True End Sub '************************************************* **************** ' on read event... '************************************************* **************** Public Sub OnRead(ByVal pHandle As Long) ' read the data (don't forget, pass the whole array)... If hidRead(pHandle, BufferIn(0)) Then ADC0.Caption = BufferIn(1) ADC1.Caption = BufferIn(2) ADC2.Caption = BufferIn(3) ADC3.Caption = BufferIn(4) ADC4.Caption = BufferIn(5) ADC5.Caption = BufferIn(6) ADC6.Caption = BufferIn(7) ADC7.Caption = BufferIn(8) ' ** YOUR CODE HERE ** ' first byte is the report ID, e.g. BufferIn(0) ' the other bytes are the data from the microcontrolller... End If End Sub '************************************************* **************** ' this is how you write some data... '************************************************* **************** 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 Label4_Click() End Sub Private Sub Label7_Click() End Sub Private Sub Label8_Click() End Sub Private Sub Ledoff_Click() swLed1.Value = 1 swLed2.Value = 1 swLed3.Value = 1 swLed4.Value = 1 swLed5.Value = 1 swLed6.Value = 1 swLed7.Value = 1 swLed8.Value = 1 byteLED = 255 BufferOut(8) = byteLED hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub LedOn_Click() swLed1.Value = 0 swLed2.Value = 0 swLed3.Value = 0 swLed4.Value = 0 swLed5.Value = 0 swLed6.Value = 0 swLed7.Value = 0 swLed8.Value = 0 byteLED = 0 BufferOut(8) = byteLED hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub swLed1_Click() byteLED = byteLED Xor (2 ^ 0) BufferOut(8) = byteLED hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub swLed2_Click() byteLED = byteLED Xor (2 ^ 1) BufferOut(8) = byteLED hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub swLed3_Click() byteLED = byteLED Xor (2 ^ 2) BufferOut(8) = byteLED hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub swLed4_Click() byteLED = byteLED Xor (2 ^ 3) BufferOut(8) = byteLED hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub swLed5_Click() byteLED = byteLED Xor (2 ^ 4) BufferOut(8) = byteLED hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub swLed6_Click() byteLED = byteLED Xor (2 ^ 5) BufferOut(8) = byteLED hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub swLed7_Click() byteLED = byteLED Xor (2 ^ 6) BufferOut(8) = byteLED hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub swLed8_Click() byteLED = byteLED Xor (2 ^ 7) BufferOut(8) = byteLED hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub Timer1_Timer() BufferOut(0) = 0 hidWriteEx VendorID, ProductID, BufferOut(0) End Sub |
![]() |
![]() |
|
|
![]() |
||||
Ðề tài | Người gửi | Chuyên mục | Trả lời | Bài mới |
Port A làm port I/0, ai biết chỉ mình với??? | tuankobe | Cơ bản về vi điều khiển và PIC | 10 | 26-04-2011 02:09 PM |
Driver cho động cơ DC? | tinhthanthep | Cơ cấu chấp hành (Actuator) | 5 | 10-12-2007 03:56 PM |
Hỏi về Proteus, LCD, port... | Jerry | Chương trình dịch & các công cụ mô phỏng | 5 | 15-01-2007 09:43 PM |
Tim mua mach dieu khien DC/AC SERVO Driver | Vo Hoang SOn | Tìm mua sản phẩm | 0 | 13-08-2005 11:40 AM |