Pic 18f Usb


Closed Thread
Results 1 to 40 of 135

Thread: Pic 18f Usb

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    Hello Rytech, your code is ok, i tried to compile it and it works. Probably you need a newer version of pbp or microcode studio.
    Last edited by Raflex; - 10th June 2007 at 01:03.

  2. #2
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default Version info

    I have PBP Compiler 2.46, Microcode studio 2.2.1.1 and version 4.21 beta of MeLabs Programmer software

  3. #3
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Hopefully someone can comment on why my compiler doesnt know what ADCON1 & ADCON2 is for the 18F series chip.

    If i take out ADCON2 and the usb stuff and compile for 16F877A it has no problems with ADCON1 - which to me suggest my support for a 18F4550 is buggered.

    this compiles fine for the 16F877A:


    DEFINE OSC 20
    DEFINE LOADER_USED 1
    'ADC defines
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source /32
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    Quanta con 1251
    Adval VAR WORD

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

    ' the USB buffer...
    USBBuffer Var Byte[USBBufferSizeMax]
    USBBufferCount Var Byte
    x VAR BYTE


    TRISA.0 = 1 ' RA0 input

    ADCON1 = %00001110 ' A/D channel 0
    'ADCON2 = %10000011 ' Left justify for 10-bit

    'usbinit ' initialise USB...
    x = 0
    LOW PORTB
    BlinkLED:
    if x = 7 then ProgramStart
    x = x + 1
    HIGH PORTB.7
    PAUSE 1000
    LOW PORTB.7
    PAUSE 500
    goto blinkLED
    ProgramStart:
    x = 0
    gosub DoUSBIn
    gosub DoUSBOut
    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
    if usbbuffer[2] = 1 then
    high portb.7
    ENDIF
    IF USBbuffer[2] = 0 THEN
    LOW portb.7
    ENDIF
    goto DoAD
    return
    DoAD:
    ADCIN 0,adval ' Read A/D channel 0 into ADval variable
    ADval = ADval */ Quanta ' Quanta result

    ' Load data buffer
    USBBuffer[0] = Adval dig 3 'Y.LowByte
    USBBuffer[1] = "."
    USBBuffer[2] = Adval DIG 2
    USBBuffer[3] = Adval DIG 1
    USBBuffer[4] = aDVAL DIG 0
    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

  4. #4
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    I just applied the update for version 2.46 - no effect.

  5. #5
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Updated MPLAB & MPASM to latest version - no effect.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Try this:

    'ADCON2 = %10000011 ' Left justify for 10-bit
    Poke $fc0, $83 'which is the same thing as the line above.

  7. #7
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Ok that compiled... with warnings...

    Warning c:\progra~1\picbas~1\18F4550.inc 20: _CONFIG has been depreciated for PIC18 devices. Use CONFIG (repeated about 8 ti

    does the fact that the "POKE" command compiled tell us why ADCON1 & ADCON2 would not?

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RYTECH View Post
    does the fact that the "POKE" command compiled tell us why ADCON1 & ADCON2 would not?
    PBP 2.47 shows fixes for miscellaneous items and a few other things.
    Maybe that's one of the fixes...who knows. And, heck, if Poke works, who cares

  9. #9
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Ok, so poke just manually writes values to the given registers?

    I'd still like to figure out why ADCON1 & ADCON2 is not working.



    ADCON1 = %00001110 ' A/D channel 0

    'ADCON2 = %10000011 ' Left justify for 10-bit
    Poke $fc0, $83 'which is the same thing as the line above.
    Last edited by RYTECH; - 11th June 2007 at 00:19. Reason: I asked for the answer to a simple problem

  10. #10
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    PBP 2.47 shows fixes for miscellaneous items and a few other things.
    Maybe that's one of the fixes...who knows. And, heck, if Poke works, who cares
    Yeah if the peek and poke work thats fine for me, I had used ADCON commands before and am a little stumped about why it would work in once case for a certain PIC and not for another (the 18F4550). I knew it might be a matter of having support for the specific chip. i'm hoping other commands don't have syntax errors as i go...

    I wonder if 2.47 resolves the Syntax error as I intend to start using the USB type 18Fxxxx type PICs

    How do i find the microcontroller register address for ADCON0 - ADCON1 - ADCON2, is it in the datasheet? ( the sections describing A/D operation dont seem to list the address locations)
    Last edited by RYTECH; - 11th June 2007 at 03:23.

Similar Threads

  1. USB CDC Communications for Dummies!
    By Squibcakes in forum USB
    Replies: 104
    Last Post: - 15th January 2014, 13:43
  2. Reading a slave USB with a pic
    By pcaccia in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th October 2008, 12:00
  3. Replies: 15
    Last Post: - 30th October 2007, 19:25
  4. USB communication with pic
    By Shamir in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th August 2006, 23:43
  5. USB PIC without USB Connection
    By Tissy in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th December 2005, 17:39

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