kardeş portb ye led bağladıktan sonra neden giriş olarak ayarlıyorsun anlayamadım doğrusu..!
arkadaşlar usb pic kontrol için visual basic ve proto n -pic basic dillerinde kaynaga ihtiyacım var . Yardımcı olabilir misiniz . internette genel de C dilinde verilmiş.
usb out usbin komutlarını detaylı biçimde ve bu komutları vb tarafında nasıl kullanabilirim ögrenmek istiyorum .sitede
easyhid maker kullanıyorum kodları nereye yazılacagını gösteriyor. elimde bi kaç örnek var daha cok örnekle karşılaştırmak istiyorum.
en kolay yoluyla usb kullanımı adı altında sitede detaylı olarak paylaşacağım
Kod:Device = 18F2550 XTAL = 48 ' descriptor file, located in \inc\usb_18 - a copy ' is located in the same folder as this file USB_DESCRIPTOR = "USBProjectDESC.inc" ' USB Buffer... ' Buffer Haritası ' Buffer[1] = PORTA , Buffer[2] = PORTB Symbol USBBufferSizeMax = 8 Symbol USBBufferSizeTX = 8 Symbol USBBufferSizeRX = 8 Dim USBBuffer[USBBufferSizeMax] As Byte ' some useful flags... 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 ' ************************************************************ ' * main program loop - remember, you must keep the USB * ' * connection alive with a call to USBPoll, USBIn or USBOut * ' * every couple of milliseconds or so * ' ************************************************************ ' ************************************************************ TRISA = %01110000 TRISB = %00000000 ' ************************************************************ GoSub AttachToUSB ProgramLoop: USBBuffer[1] = PORTA 'portA bilgilerini gönderecek USBOut 1, USBBuffer, USBBufferSizeTX USBIn 1, USBBuffer, USBBufferSizeRX, ProgramLoop PORTB = USBBuffer[2] 'buffer2 yi port b de yansıtacak 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
şöyle bir kod yazdım amacım port a daki buton girişlerini okuyup pc de görmek . pc de port b ye bilgi göndermek .
şöyle de bir devrem var
Kaynak : Picman arkadaşımızın paylaştıgı konu.
Konu raercan tarafından (26.Nisan.2010 Saat 00:21 ) değiştirilmiştir.
kardeş portb ye led bağladıktan sonra neden giriş olarak ayarlıyorsun anlayamadım doğrusu..!
Bir ulusu yok etmenin en iyi yolu o ulusun dilini yok etmektir
Özel mesaj yoluyla yardım istemek Kesinlikle yasaktır
hocam yanlışlık olmuş.arkadaşın projeden kopyala yapıştır yaptıgımdan . hoşgör...
şimdi asıl sorunum şu . visual basic te ve protonda bufferları nasıl değerlendirecegim onu anlayamadım.
vb tarafı :
Kod:Private Sub Command1_Click() BufferOut(4) = Val(Text1.Text)
atıyorum text bara girdigim bi degeri port b de nasıl görebilirim.
proton tarafı :
bunlar yeterli olur mu ?Kod:usbin: usbin 1,usbbuffer(4),USBBufferSizeRX,usbin portb=usbbuffer(4)
USB de İşler biraz Karışık. Ne Seriye nede parelele benzer.
Usb de verilenin gönderilip alınması için Pipe döşenir(bunlar yazılımsaldır). Alınan yada gönderilen bilgiler USBBuffer a koyulur.Protonda EasyHid ile bazı projeler yaptım ama hiç VB.60 kullanmadım.(vb.net kullandım) Gönderirken yada alırken sadece buffer0 ve 1 i kullandım.
pipe olayı ve diger konuları en azından yüzeysel de olsa biraz daha açık anlatabilir misiniz ?
peki bit düzeyinde nasıl gönderip alabiliriz ? b konuda yardımcı olaiblir misiniz ?
anlatayım ama çok derinine inemem
Host a(PC) bir cihaz takıldığında, baz künyelerin (description file) cihazdan host a gitmesi gerekir. bunlar cihazın hangi sınıfa ait olduğu(HID-Human Interface Device- vs) gücün usb denmi kendi kaynağındanmı alacağı vs gibi bilgilerdir.("USBProjectDESC.inc" dosyasını inceleyiniz). bunları Pipe adı verilen (sanal olan) sistem üzerinden yürütür. Bu pipe lar verinin iletişimini sağlar.
buraya kadar tamam yanlız usb cihaz ın iletşim sağlaması için bu description file in içerisinde geçen configuration,interface,EndPoint gibi kavramların neler olduğunu bilmek gerek. burada söyleyebileceğim. bu endpointlerle bilgi alınır ve verilir.
usb ile ilgili www.lvr.com epeyce bilgi mevcut. usb gerçekten karışık bir sistem.
----------
http://www.lvr.com/usbcode.htm#microchip
hocam gözümü korkuttunuz fakat yılmak yok . yapacagım işlem için sanırımo kadar detaya gerek yok. sadece 1 en fazla 2 bytelık veri göndermek. bunun o kadar detaya girmeden bir yolu yokmudur. biraz daha inceleyeyim. çözdüğümde herkes yapabilsin diye detaylı ca anlatmak istiyorum
![]()
senin işini easy hid görür
sağol hocam![]()
kodlarında şöyle olacak
Buffer a bilgi koy
Goto DoUsbOut
Goto DoUsbin
buffer dan bilgiyi al
USBBuffer[USBBufferSizeMax] daki USBBufferSizeMax descriptionfile içerinde dataleght dir ve genelde 8 dir yani 8byte ı gönderebilirsin
yanlış hatırlamıyorsam easyhid den ayarlanıyordu hocam. yarın bir kaç denemem olacak neticiesini burada paylaşacagım . teşekkürlerimi saygılarımı sunarım .
Doğrudur eh den ayarlayabiliyorsun ama senin için default(8) kalması yeter
sağolasın hocam .
buffer (1)
buffer (2)
bunlar 8 byte lık verinin 1 byte lık bölümleri mi oyluyor.
mesela aşagıdaki örnekte
Label3.Caption = BufferIn(1)
Label4.Caption = BufferIn(2)
ProgressBar1.Value = BufferIn(1) + 1
ProgressBar2.Value = BufferIn(2) + 1
Label5.Caption = BufferIn(3)
böyle bir bölüm var. burada o bufferların 1.2. byte larınıa mı hükmediyor. ?
eger öyleyse
1 byte lık bir değişken yaratıp ona yükleyecegim degerleri pic e yollayabilir veya alabilir miyim ?
Kod:' vendor and product IDs Private Const VendorID = 6020 Private Const ProductID = 2008 ' 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 ' **************************************************************** ' 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() App.Title = Me.Caption ' 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 ** Image1.Visible = True Frame1.Enabled = True Frame2.Enabled = True Frame4.Enabled = True 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 ** Image1.Visible = False Frame1.Enabled = False Frame2.Enabled = False Frame4.Enabled = False 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... Label3.Caption = BufferIn(1) Label4.Caption = BufferIn(2) ProgressBar1.Value = BufferIn(1) + 1 ProgressBar2.Value = BufferIn(2) + 1 Label5.Caption = BufferIn(3) 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 Text1_Change() If Val(Text1.Text) > 255 Then Text1.Text = "" End Sub Private Sub Text1_GotFocus() SeciliTxBox End Sub Sub SeciliTxBox() Screen.ActiveControl.SelStart = 0 Screen.ActiveControl.SelLength = Len(Screen.ActiveControl.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
Label3.Caption = BufferIn(1) 'bufferin ikinci byte ı label 3 ün içerisine yaz
Label4.Caption = BufferIn(2) ''bufferin üçüncü byte ı label 4 ün içerisine yaz
ProgressBar1.Value = BufferIn(1) + 1 ''bufferin ikinci byte ı ile 1 topla progress barın valu deg. at
ProgressBar2.Value = BufferIn(2) + 1
Label5.Caption = BufferIn(3)
evet doğrusun
----------
unutmadan Pıc e yüklediğin VID ve PID ler le buradakiler aynı olmalı
hocam şöyle bişey yaptım ama hiç bir tepki yok...
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(2) = Val(Text1.Text) hidWriteEx VendorID, ProductID, BufferOut(2) 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 ' 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 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 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
http://hotfile.com/dl/39911667/fab41...pic18.DSN.htmlKod:Device = 18F2550 XTAL = 48 ' descriptor file, located in \inc\usb_18 - a copy ' is located in the same folder as this file USB_DESCRIPTOR = "USBProjectDESC.inc" ' USB Buffer... ' Buffer Haritası ' Buffer[1] = PORTA , Buffer[2] = PORTB Symbol USBBufferSizeMax = 8 Symbol USBBufferSizeTX = 8 Symbol USBBufferSizeRX = 8 Dim USBBuffer[USBBufferSizeMax] As Byte ' some useful flags... 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 TRISA = %01110000 TRISB = %00000000 GoSub AttachToUSB ProgramLoop: USBBuffer[1] = PORTA 'portA bilgilerini gönderecek USBOut 1, USBBuffer, USBBufferSizeTX PORTB = USBBuffer[2] 'buffer2 yi port b de yansıtacak USBIn 1, USBBuffer, USBBufferSizeRX, ProgramLoop GoTo ProgramLoop DoUSBIn: USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBIn Return DoUSBOut: USBOut 1, USBBuffer, USBBufferSizeTX, DoUSBOut Return AttachToUSB: Repeat USBPoll Until PP0 = ATTACHED_STATE Return
acaba fuses ayarlarından olabilir mi? zamanınız varsa inceleyebilir misiniz ?
Konu raercan tarafından (26.Nisan.2010 Saat 22:33 ) değiştirilmiştir.
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 Returnhocam böyle yapınca oldu . neden bi önceki deneme de olmadı onu anlayamadım ?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
Private Sub Command1_Click()
BufferOut(4) = Val(Text1.Text)
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
böyle yapınca buffer ın 0 . byte ına veri yollaması gerek miyor mu ? eger öyleyse pic tarafında :
USBIn 1, USBBuffer, USBBufferSizeRX, ProgramLoop
PORTB = USBBuffer[3]
böyle yazınca neden buffer 3 olarak atanıyor port b ?
yani port b = buffer (0) olması gerekmiyor mu ? bi önceki örnekte öyle yazınca çalışmadı![]()
sanki hatırladığım kadarı ile pc tarafı 1-2-3-4-5....,Pic tarafı 0-1-2-3.... diye gidiyordu (yada tersi) yani bufferlar tam karşılamıyordu. (ama dediğim gibi vb.60 la hiç çalışmadım)
anladım hocam birde öyle deneyip sonucları yazayım . pekişsin.![]()



ra ercan arkadaşım bende çok ugraştım usb ögrendiyim kadarıyla veri akışı insan arayüzü denilen bir anladıgım kadarıyla dll gibi bir dosya kullanman yada onu aktif durumuna getirmen gerekiyo aslında usb paralıdır yaptıgın cıhazın sistemin tanıması için bir miktar para ödüyor bazı kodları alıyorsun bu kodlar üzerine programını yazıp çalıştırıyorsun gerçegi bu benim ulaştıgım sonuç bende vb06 ugraşıyorum elimde bazı kodlar var biraz geç olmuş ama sana gönderiyorum sonuç ne oldu yapabildin mi
----------
Option Compare Text
Dim obj As New StdPicture
Private Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
Dim fox(13)
Dim usb_drv As String
Private Sub Form_Load()
Dim c, i As Byte
For i = 68 To 80
c = c + 1
fox(c) = Chr(i) & ":"
Next
Set obj = pic
End Sub
Private Sub Timer1_Timer()
For i = 1 To 13
If GetDriveType(fox(i)) = 2 Then
pic.Picture = plugin.Picture
usb_drv = fox(i)
Exit Sub
Else
Set pic.Picture = obj
usb_drv = ""
End If
Next
End Sub
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
bu kodla flaş belligi takınca resimdeki acık flaş bellek kapagı takılıyoo
----------
sende ekrandaki resim flaş bellek resim olmayınca hata veriri mantık vb06 biliyorsan flaş bellek takılınca iki resmi yer degiştiriyo herkez yararlansın diye bu şekil attım proje dosyasını da isterden atarım bu şekilde mantık yürütebilirsin diye atıyorum
----------
bir kaç dosya daha vardı onlarıda atarım arkadaşım şu anda bulamadımm
dostum sağolasın. easyhid yardımı ile 18f2550 nin b portuna 8 bit veri gönderebiliyorum.bunu halletmem yetti. daha fazla ugraşamadım.
zaman bulabilsem 18f2550 ve usb yi daha derin olarak çözecegim![]()



yaptıgın devrenin kodları paylaşmasanda çalışırr haldeki videosunu çekip yapılabilirligini göstesen çok faydalı olcagını düşünüyorum sevindim başarmısın
paylaşmaz olur muyum dostum .zaten bu yola paylşım için cıktım. sitede mevcut ve daha birçok türkçe sitedede mevcut.![]()
http://www.google.com.tr/#hl=tr&q=en...26da8da74c2cde
![]()
Şu anda 1 kullanıcı bu konuyu görüntülüyor. (0 kayıtlı ve 1 misafir)