Adcin, can't get it right


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2007
    Location
    Denmark
    Posts
    28

    Default Adcin, can't get it right

    What is wrong with my code below? I'm using a pic16f88, I want to output the value of the voltage divisor in my lcd, I have my lcd connected likes this:
    data bits: rb0-rb3
    enable bit: rb7
    r/s: ra4 (with pull up)

    I have a pot wired like this:
    pin1 to VDD
    pin2 to Ra0 (an0)
    pin3 to ground

    I'm using the internal oscillator at 4mhz

    First, with my old code, I was trying to read the analog input in rb7 but since I saw most examples with ra0 I changed my lcd configuration in order to be able to use ra0. Before I did the change, the lcd worked perfectly but the adcin value displayed was 75, then 181, and it alternated between those 2.
    Now with the new code (below), my lcd stopped working.

    here is my code:



    @ __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _PWRTE_ON & _WDT_ON & _INTRC_IO


    @ __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF

    ANSEL = %00011 '
    ADCON1 = %10000000
    cmcon = 7
    OSCCON=%1100000 '
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    define lcd_dreg portb
    define lcd_dbit 4
    define lcd_ereg portb
    define lcd_ebit 7

    define osc 4
    trisa= %111
    advar var word

    pause 1000

    inicio:
    lcdout 254, 1, "iniciando"
    lcdout 254, 192, "espera..."
    pause 2000

    checa:
    adcin portb.7, advar
    pause 50
    lcdout 254, 1, #advar
    pause 200
    goto checa

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Double check your ANSEL value...
    And your default LCD DEFINE's...
    You've got multiple conflicts...

  3. #3
    Join Date
    Dec 2007
    Location
    Denmark
    Posts
    28


    Did you find this post helpful? Yes | No

    Default

    ok, got it working, thanks Ace

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


    Did you find this post helpful? Yes | No

    Default

    also, always use the channel number instead or the PORT name in your adcin.. but as you got it working... you should already know that
    Steve

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

  5. #5
    Join Date
    Dec 2007
    Location
    Denmark
    Posts
    28


    Did you find this post helpful? Yes | No

    Default

    Yeah haha, found it the hard way . Thanks anyway Steve!

Similar Threads

  1. ADCIN and PIC18F4331 Arghhhhh !
    By GrandPa in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th December 2010, 20:27
  2. How to make adcin stable?
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 20th January 2009, 07:41
  3. ADCIN problems with PIC16F73
    By passion1 in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 26th July 2007, 11:38
  4. ADCIN - AD settings are wrong
    By teverett in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th December 2006, 16:32
  5. help using adcin
    By harryweb in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2006, 07:46

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