18f2550 ile usb kontrol

Başlatan mesut25, 22 Kasım 2013, 14:07:47

mesut25

uzun zaman önce yapmış oldugum projeyi yenıden paylaşmak istedim   18f2550 üzerin de çalışmıştım usb üzerinden motor hız kontrolü yapmıştım o kodları  projemi paylaşmak istedim inşallah yararlı olur

vb06 kodlarını paylaşıyorum
önce vısual basıc 06 kodlarını paylaşıyorumm.' vendor and product IDsPrivate Const VendorID = 6017Private Const ProductID = 2000' read and write buffersPrivate Const BufferInSize = 8Private Const BufferOutSize = 8Dim BufferIn(0 To BufferInSize) As ByteDim BufferOut(0 To BufferOutSize) As Byte' ****************************************************************' 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)DisconnectFromHIDEnd Sub'*****************************************************************' a HID device has been plugged in...'*****************************************************************Public Sub OnPlugged(ByVal pHandle As Long)If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID ThenLabel1 = "baglandıııı"End IfEnd Sub'*****************************************************************' a HID device has been unplugged...'*****************************************************************Public Sub OnUnplugged(ByVal pHandle As Long)If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID ThenLabel1 = "koptu"End IfEnd 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, TrueEnd 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' ** YOUR CODE HERE **' first byte is the report ID, e.g. BufferIn(0)' the other bytes are the data from the microcontrolller...End IfEnd Sub'*****************************************************************' this is how you write some data...'*****************************************************************Public Sub WriteSomeData()BufferOut(0) = 0 ' first by is always the report IDBufferOut(1) = 10 ' first data item, etc etc' write the data (don't forget, pass the whole array)...hidWriteEx VendorID, ProductID, BufferOut(0)End SubPrivate Sub HScroll1_Change()Text1.Text = HScroll1.ValueEnd SubPrivate Sub Text1_Change()BufferOut(1) = Val(Text1.Text)hidWriteEx VendorID, ProductID, BufferOut(0)End Sub


pıcbaısc kodları
'****************************************************************'* Name : HIZ2.BAS *'* Author : [select VIEW...EDITOR OPTIONS] *'* Notice : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] *'* : All Rights Reserved *'* Date : 22.11.2012 *'* Version : 1.0 *'* Notes : *'* : *'****************************************************************' select MCU and clock speedDevice = 18F2550XTAL = 48DEFINE CCP1_REG PORTCDEFINE CCP1_BIT 2DEFINE CCP2_REG PORTCDEFINE CCP2_BIT 1USB_DESCRIPTOR = "HIZ2DESC.inc"' USB Buffer...Symbol USBBufferSizeMax = 8Symbol USBBufferSizeTX = 8Symbol USBBufferSizeRX = 8Dim USBBuffer[USBBufferSizeMax] As Bytea var WordDim PP0 As Byte SYSTEM ' USBPOLL status returnSymbol CARRY_FLAG = STATUS.0 ' high if microcontroller does not have control over the bufferSymbol ATTACHED_STATE = 6 ' is USB attachedTRISC = 0GoSub AttachToUSBProgramLoop:USBOut 1, USBBuffer, USBBufferSizeTXUSBIn 1, USBBuffer, USBBufferSizeRX, ProgramLoopa = USBBuffer[0]' BİLGİSAYARDAN PIC VERİ ATMAK İÇİNHPWM 1, a, 1000GoTo ProgramLoop' ************************************************************' * receive data from the USB bus *' ************************************************************DoUSBIn:USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBInReturn' ************************************************************' * transmit data *' ************************************************************DoUSBOut:USBOut 1, USBBuffer, USBBufferSizeTX, DoUSBOutReturn' ************************************************************' * wait for USB interface to attach *' ************************************************************AttachToUSB:RepeatUSBPollUntil PP0 = ATTACHED_STATEReturn


gelişmeye hazır

est32

Eline sağlık hocam kaydettim ileride lazım olabilir

Powered by EzPortal