ibrahim626
Üye
- Katılım
- 3 Ağu 2008
- Mesajlar
- 12
- Puanları
- 1
- Yaş
- 40
Öncelikle Herkese merhaba benim bir sorum olacak , ben suan PIC 18F4550 ile usbden led yakmaya çalışıyorum bağlantıyı sorunsuz kurdum işlemci ile haberleşebiliyorum fakat ledleri istediğim gibi yakamıyorum. programda toplamda 16 adet buton var bunlar 8 ledi yakıp söndürmek içindir, benim istediğim çalışma kosulu :
butonlardan basılı olana karsılık o ledi yakmak yani hangi buton yada butonlar basılı ise karsılık gelen ledlerı yakmak
benim programımın çalışması iste şöyle :
1. butona basıyorum portb'nin 0.ledi yanıyor
2. butona bastığımda ise port.0'daki lled sönüyor 1.led yanıyor ben bunları birbirinden nasıl kontrol edebilirim ? nasıl bi program yazmalıyım vb'de henuz biraz acemiyim.
butonlardan basılı olana karsılık o ledi yakmak yani hangi buton yada butonlar basılı ise karsılık gelen ledlerı yakmak
benim programımın çalışması iste şöyle :
1. butona basıyorum portb'nin 0.ledi yanıyor
2. butona bastığımda ise port.0'daki lled sönüyor 1.led yanıyor ben bunları birbirinden nasıl kontrol edebilirim ? nasıl bi program yazmalıyım vb'de henuz biraz acemiyim.
Kod:
' 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
Dim sayi As Byte
Private Sub Command1_Click()
BufferOut(4) = Val(sayi + 1)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Command2_Click()
BufferOut(4) = Val(sayi + 2)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Command3_Click()
BufferOut(4) = Val(sayi + 4)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Command4_Click()
BufferOut(4) = Val(sayi + 8)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Command5_Click()
BufferOut(4) = Val(sayi + 16)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Command6_Click()
BufferOut(4) = Val(sayi + 32)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Command7_Click()
BufferOut(4) = Val(sayi + 64)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Command8_Click()
BufferOut(4) = Val(sayi + 128)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Command9_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
' ** 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
' ** 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
' ** 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
/CODE]