Problem with PIC18F458 ADC code


Closed Thread
Results 1 to 7 of 7
  1. #1
    minmin's Avatar
    minmin Guest

    Question Problem with PIC18F458 ADC code

    HI, I am new to PicBasic.

    I am trying to use PIC18F458 convert 0-5 v analog input, and show the result to LCD. I post my code below. The LCD part works fine, but it always show number "255" on the LCD, even I did not give any voltage input to PORTA.3

    So anyone can help me look at my code, and see what is the problem?

    Many thanks!!

    Min

    My code is:
    -------------------------------------
    DEFINE OSC 4

    W1 VAR WORD

    include "modedefs.bas"

    PAUSE 1000 'LCD takes a second to start

    TRISA = 255 'PORTA all inputs
    ADCON1 = 0 'PORTA Analog I/O
    ADCON0.7 = 1 'Right justified.


    ' Initialize USART
    TRISC = %10111111 'Set TX (PortC.6) to out, rest in
    TXSTA = %00100000 'Enable transmit and asynchronous mode

    SEROUT PORTC.6,N9600,["Citrus Counter ",254,2]
    PAUSE 1000

    SEROUT PORTC.6,N9600,[254,1] ' Clear screen

    LOOP1:
    ADCIN PORTA.3, W1
    SEROUT PORTC.6,N9600,[#W1,13]
    GOTO LOOP1
    END
    --------------------------------------------------

  2. #2
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by minmin
    ADCIN PORTA.3, W1
    Just use the right syntax !

    ADCIN 3,W1 (use the channelnumber, not the Portpin!)
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  3. #3
    minmin's Avatar
    minmin Guest


    Did you find this post helpful? Yes | No

    Default thanks, it works just fine!!!

    it works!!!
    Thanks
    Min

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Also, how do you send a word size variable via serial comm?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    francisco767's Avatar
    francisco767 Guest


    Did you find this post helpful? Yes | No

    Post Re: Problem with PIC18F458 ADC code

    Hi, wich simulator you used?

    Quote Originally Posted by minmin View Post
    HI, I am new to PicBasic.

    I am trying to use PIC18F458 convert 0-5 v analog input, and show the result to LCD. I post my code below. The LCD part works fine, but it always show number "255" on the LCD, even I did not give any voltage input to PORTA.3

    So anyone can help me look at my code, and see what is the problem?

    Many thanks!!

    Min
    __________-




    My code is:
    -------------------------------------
    DEFINE OSC 4

    W1 VAR WORD

    include "modedefs.bas"

    PAUSE 1000 'LCD takes a second to start

    TRISA = 255 'PORTA all inputs
    ADCON1 = 0 'PORTA Analog I/O
    ADCON0.7 = 1 'Right justified.


    ' Initialize USART
    TRISC = %10111111 'Set TX (PortC.6) to out, rest in
    TXSTA = %00100000 'Enable transmit and asynchronous mode

    SEROUT PORTC.6,N9600,["Citrus Counter ",254,2]
    PAUSE 1000

    SEROUT PORTC.6,N9600,[254,1] ' Clear screen

    LOOP1:
    ADCIN PORTA.3, W1
    SEROUT PORTC.6,N9600,[#W1,13]
    GOTO LOOP1
    END
    --------------------------------------------------

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Problem with PIC18F458 ADC code

    There's no mention he used a simulator but a standard LCD.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Problem with PIC18F458 ADC code

    I meant standard serial LCD. sorry (Yeah I know... think more post less... plah plah plah)
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Problem compiling EasyHID code
    By mindthomas in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th August 2010, 20:46
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. MN1307 sample code problem
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th November 2008, 20:41
  4. 16F88 ADC problem
    By greensasquatch in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 7th September 2008, 16:16
  5. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26

Members who have read this thread : 0

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