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 IDs
Private Const VendorID = 6017
Private Const ProductID = 2000

' 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



' ****************************************************************
' 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
Label1 = "baglandıııı"
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
Label1 = "koptu"
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
' ** 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 HScroll1_Change()
Text1.Text = HScroll1.Value
End Sub

Private 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 speed
Device = 18F2550
XTAL = 48


DEFINE CCP1_REG PORTC
DEFINE CCP1_BIT 2
DEFINE CCP2_REG PORTC
DEFINE CCP2_BIT 1
USB_DESCRIPTOR = "HIZ2DESC.inc"

' USB Buffer...
Symbol USBBufferSizeMax = 8
Symbol USBBufferSizeTX = 8
Symbol USBBufferSizeRX = 8
Dim USBBuffer[USBBufferSizeMax] As Byte
a var Word
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

TRISC = 0
GoSub AttachToUSB
ProgramLoop:
USBOut 1, USBBuffer, USBBufferSizeTX

USBIn 1, USBBuffer, USBBufferSizeRX, ProgramLoop
a = USBBuffer[0]' BİLGİSAYARDAN PIC VERİ ATMAK İÇİN
HPWM 1, a, 1000
GoTo ProgramLoop

' ************************************************************
' * receive data from the USB bus *
' ************************************************************
DoUSBIn:
USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBIn
Return

' ************************************************************
' * transmit data *
' ************************************************************
DoUSBOut:
USBOut 1, USBBuffer, USBBufferSizeTX, DoUSBOut
Return

' ************************************************************
' * wait for USB interface to attach *
' ************************************************************
AttachToUSB:
Repeat
USBPoll
Until PP0 = ATTACHED_STATE
Return


gelişmeye hazır

est32

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

Powered by EzPortal