Haz una pregunta
  Foros de Electrónica » Diseño digital » Microcontroladores y sistemas embebidos
Foros Registrarse ¿Olvidaste tu contraseña?

Temas similares

09/01/2012 #1


Programa en Visual Basic 6.0 para USB
hola brothers!
Estoy aprendiendo a programar en Visual Basic 6.0 y me gustaría que me pudiesen ayudar a comprender mejor el siguiente programa.

El programa en Visual debe de generar una cadena de 10 bits y transmitirlos por la USB al puerto B del PIC, lo único que hará el PIC es captar bit por bit e inmediatamente sacar cada BIT por el puerto D. la trama de BITs debe de estar repitiéndose periódicamente a una frecuencia de 13Hz, el programa ya funciona, el problema es que no se que instrucción hace que se tenga una frecuencia de salida de 13Hz.

Yo sospechaba que era la Instrucción Timer.Interval , pero esta, esta declarada en el programa como Timer.Interval =1 y segun esto eso equivale a 1 milisegundo.

Estoy bastante confundido hacerca de esto que ya empieso e terner herrores hortograficos!!
Les doy las gracias por adelantado, un saludo grande

El código para la USB de PIC es el siguiente, esta hecho en PICBASIC PRO



Código:
DEFINE OSC 48          
DEFINE LOADER_USED 1

USBBufferSizeMax   con 8  ' maximum buffer size
USBBufferSizeTX    con 8  ' input 
USBBufferSizeRX    con 8  ' output

' the USB buffer...
USBBuffer        Var Byte[USBBufferSizeMax] 
USBBufferCount   Var Byte 
          
PORTB=0
TRISB=%11111111
PORTC=0
TRISC=%11111111
PORTD=0
TRISD=0

' ************************************************************
' * main program loop - remember, you must keep the USB      *
' * connection alive with a call to USBService every couple  *
' * of milliseconds or so...                                 *
' ************************************************************
usbinit ' initialise USB...
ProgramStart: 
    USBService
    USBBuffer[1]=PORTB
    gosub DoUSBOut    
    gosub DoUSBIn
    PORTD=USBBuffer[2]
   goto ProgramStart 

' ************************************************************
' * receive data from the USB bus                            *
' ************************************************************
DoUSBIn:
   USBBufferCount = USBBufferSizeRX              ' RX buffer size
   USBService                                    ' keep connection alive
   USBIn 1, USBBuffer, USBBufferCount, DoUSBIn   ' read data, if available
   return
    
' ************************************************************
' * wait for USB interface to attach                         *
' ************************************************************
DoUSBOut:
   USBBufferCount = USBBufferSizeTX              ' TX buffer size
   USBService                                    ' keep connection alive
   USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data
   return
El programa en Visual Basic 6.0 es el siguiente:


Código:
' 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)
   Check1(0).Value = 0
   Check1(1).Value = 0
   Check1(2).Value = 0
   Check1(3).Value = 0
   Check1(4).Value = 0
   Check1(5).Value = 0
   Timer1.Enabled = False
   Timer1.Interval = 1
   Check1(0).Caption = ""
   Check1(1).Caption = ""
   Check1(2).Caption = ""
   Check1(3).Caption = ""
   Check1(4).Caption = ""
   Check1(5).Caption = ""
   
   
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

Private Sub INICIAR_Click()
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Dim a As Long

If Check1(0).Value = 0 Then
    BufferOut(2) = 0
    hidWriteEx VendorID, ProductID, BufferOut(0)
Else
    BufferOut(2) = 1
    hidWriteEx VendorID, ProductID, BufferOut(0)
    End If
    
If Check1(1).Value = 0 Then
    BufferOut(3) = 0
    hidWriteEx VendorID, ProductID, BufferOut(0)
Else
    BufferOut(3) = 1
    hidWriteEx VendorID, ProductID, BufferOut(0)
End If

If Check1(2).Value = 0 Then
    BufferOut(4) = 0
    hidWriteEx VendorID, ProductID, BufferOut(0)
Else
    BufferOut(4) = 1
    hidWriteEx VendorID, ProductID, BufferOut(0)
End If
    
    
If Check1(3).Value = 0 Then
    BufferOut(5) = 0
    hidWriteEx VendorID, ProductID, BufferOut(0)
Else
    BufferOut(5) = 1
    hidWriteEx VendorID, ProductID, BufferOut(0)
End If

If Check1(4).Value = 0 Then
    BufferOut(6) = 0
    hidWriteEx VendorID, ProductID, BufferOut(0)
Else
    BufferOut(6) = 1
    hidWriteEx VendorID, ProductID, BufferOut(0)
End If

If Check1(5).Value = 0 Then
    BufferOut(7) = 0
    hidWriteEx VendorID, ProductID, BufferOut(0)
Else
    BufferOut(7) = 1
    hidWriteEx VendorID, ProductID, BufferOut(0)
End If
End Sub
Respuesta
¿Tienes una mejor respuesta a este tema? ¿Quieres hacerle una pregunta a nuestra comunidad y sus expertos? Registrate

Foros de Electrónica » Diseño digital » Microcontroladores y sistemas embebidos

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2011, Crawlability, Inc.