Send data to PC USB


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    5

    Default Send data to PC USB

    Hi,
    I'm doing a program for viewing data from PC to PIC and vice versa.
    When filling the fields of TextBox in VB6 application and press the "Send" button I see on the display the data correctly.
    But when it comes to receiving the data to be invented in the Subroutine "EnviarDatos" the Pic not visualize anything in the TextBox.
    Here I leave the program for the PIC and the subroutine VB6 "OnRead" for you dig where you're going to have a look at the ruling.

    in this line means: USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBIn
    The USB 1 it means?

    Thanks again ....


    ______PIC_________________________________________ _________________________

    Device = 18F4550
    Xtal = 48

    USB_Descriptor = "Pruebas.inc"
    Declare LCD_Type Samsung
    Declare LCD_Interface 8
    Declare LCD_DTPort = PORTB
    Declare LCD_CS1Pin = PORTD.5
    Declare LCD_CS2Pin = PORTD.4
    Declare LCD_RWPin = PORTD.6
    Declare LCD_RSPin = PORTD.7
    Declare LCD_ENPin = PORTC.7
    Declare GLCD_CS_Invert On
    All_Digital = TRUE

    'SIZES OF USB BUFFER
    Symbol USBBufferSizeMax = 10
    Symbol USBBufferSizeTX = 10
    Symbol USBBufferSizeRX = 10
    Dim USBBuffer[USBBufferSizeMax] As Byte
    Dim USBBufferCount As Byte



    Symbol LED = PORTC.1 'LED will PORTC.1 CALL OUT
    Dim LEDUSB As Bit 'STATUS LED (OFF or ON) 1
    Dim A As Word 'MULTI-VARIABLE
    Dim B As Bit 'Biester VARIABLE IN WHICH RECEIVE THE BUTTON

    'REGISTROS Y BANDERAS
    Dim PP0 As Byte System ' EGISTRATION STATUS WITHIN THE PIC USBPOLL
    Symbol CARRY_FLAG = STATUS.0 ' IF HIGH IN STATE HAS NO PIC
    'CONTROL ON THE BUFFER
    Symbol ATTACHED_STATE = 6 'IF USB IS CONNECTED

    Cls 'CLEAN START TO DISPLAY
    Clear 'CLEAN THE RAM TO START

    Internal_Font = On
    Font_Addr = 1

    Print Cls,"Connecting ..."
    GoSub AttachToUSB
    High LED
    Print Cls,"OK"
    USBBuffer[0]= 0 'Flag data 0=Receive (PC>PIC)
    ' 1=Send (PIC>PC)
    ProgramLoop:
    GoSub DoUSBIn 'I will read the input buffer
    If USBBuffer[0]= 1 Then
    Print At 0,9, "Sending ..."
    GoSub EnviarDatos
    Else
    Print At 0,9, "Reading ..."
    Print At 0,8,Dec USBBuffer[0] 'I read the data from the PC and displayed on the GLCD
    Print At 2,1, Dec USBBuffer[2]
    Print At 3,1, Dec USBBuffer[3]
    Print At 4,1, Dec USBBuffer[4]
    Print At 5,1, Dec USBBuffer[5]
    Print At 2,8, Dec USBBuffer[6]
    Print At 3,8, Dec USBBuffer[7]
    Print At 4,8, Dec USBBuffer[8]
    Print At 5,8, Dec USBBuffer[9]
    DelayMS 1
    GoSub DoUSBIn
    End If
    Toggle LED
    GoTo ProgramLoop 'Closes the loop AFTER ALL THE WORK



    ' ************************************************** **********
    ' * RECEIPT OF DATA ROUTINE *
    ' ************************************************** **********
    DoUSBIn:
    USBBufferCount = USBBufferSizeTX
    USBSERVICE
    USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBIn
    Return

    ' ************************************************** **********
    ' * DATA TRANSFER ROUTINE *
    ' ************************************************** **********
    DoUSBOut:
    USBBufferCount = USBBufferSizeTX
    USBSERVICE
    USBOut 1, USBBuffer, USBBufferSizeTX, DoUSBOut
    Return

    ' ************************************************** **********
    ' * Wait until the USB connects*
    ' ************************************************** **********
    AttachToUSB:
    Repeat
    USBPoll
    Until PP0 = ATTACHED_STATE
    Return

    EnviarDatos:
    USBBuffer[2] = 1
    USBBuffer[3] = 2
    USBBuffer[4] = 3
    USBBuffer[5] = 4
    USBBuffer[6] = 5
    USBBuffer[7] = 6
    USBBuffer[8] = 7
    USBBuffer[9] = 8
    DelayMS 1 'GIVE A TIME OF DELAY
    GoSub DoUSBOut 'Sending data in the buffer for the PC
    Return

    End
    Include "FONT.INC"

    _______ VB6 __________________________________________________

    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...
    Text1(1).Text = BufferIn(2)
    Text1(2).Text = BufferIn(3)
    Text1(3).Text = BufferIn(4)
    Text1(4).Text = BufferIn(5)
    Text1(5).Text = BufferIn(6)
    Text1(6).Text = BufferIn(7)
    Text1(7).Text = BufferIn(8)
    Text1(8).Text = BufferIn(9)
    End If
    End Sub

  2. #2
    Join Date
    Dec 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Right so...What I am doing in my project is as follows:
    1. I am using the LM35 temperature sensor and converting the analog output into digital using PIC's A/D
    2. Then I want to send this output to the PC

    Now here are my series of doubts after making lots of efforts on the internet and google.
    1. How do I transfer the bits of the digital output which is produced by the A/D and stored in the ADRESH and ADDRESL registers?
    2. Will it come out of a port serially?(Do I have to code it that way?)
    3.How do I get the readings on the PC side in Hyper Terminal?

    Thanks in advance,

  3. #3
    Join Date
    Dec 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Send data to PC USB

    Sorry, But I´m working with USB not Hyper Terminal (Serial).
    THX.

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 05:47
  2. Send data PIC to PC
    By konter in forum Off Topic
    Replies: 6
    Last Post: - 25th December 2009, 23:04
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 03:21
  4. LCD + bar graph
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th October 2005, 15:50
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 29th November 2004, 00:56

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts