Display the value of a resistance to LCD


Closed Thread
Results 1 to 5 of 5
  1. #1

    Default Display the value of a resistance to LCD

    Hi everyone,
    I'm new PBP, have a 5k ohm potentiometer, and I'm trying to dispaly it to the lcd. But I wa hoping I can display it in terms in 0% - 100%. Please help me with my codes below.

    ' Define ADCIN parameters
    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    PortB = $00 ' all outputs off to start
    TrisB = %00000000 ' All of Port B is outputs
    TRISA = %11111111 ' Set PORTA to all input
    adval var byte ' ADC result variable
    ADCON1 = %00000001 ' Set PORTA analog

    loop:
    ADCIN 0, adval ' Store ADC value to adval

    Serout 4, 6, [254, 1]
    pause 2
    serout 4, 6, [#adval] 'display to the LCD
    pause 250
    Goto loop ' Do it forever
    End



    Thanks in advance,
    joe

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,523


    Did you find this post helpful? Yes | No

    Default

    Hi,
    A quick'n'easy way could be if you changed your ADC resolution from 8 to 10 bits and then:
    Code:
    DEFINE ADC_BITS 10
    ADVAL VAR WORD             '<----Don't forget to change this to a WORD
    
    loop: 
      ADCIN 0, adval                              'Store ADC value to adval
      ADVAL = ADVAL * 10 / 102                    'ADVAL is now between 0-100
      Serout 4, 6, [254, 1]
      pause 2
      serout 4, 6, [#adval]                       'display to the LCD
      pause 250
      Goto loop                                   'Do it forever
    End
    /Henrik Olsson.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hello Henrik,
    Thanks for the reply, I tried you code, but if I turn the pot just a little to the right it gives me 663. Please see my modified code below...

    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
    '
    '
    adval var word 'Create adval to store result
    '
    '
    Init:
    PortB = $00 ' all outputs off to start
    TrisB = %00000000 ' All of Port B is outputs
    '

    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00000001 ' Set PORTA analog
    loop:
    ADCIN 0, adval ' Read channel 0 to adval
    Pause 500
    Serout 4, 6, [$1b, $2a,$80] 'Turn backlight half broghtness
    Serout 4, 6, [254, 1]
    pause 2
    adval = adval*10/102
    serout 4, 6, [#adval]
    '********** Drive LEDs *************************
    LEDtst1:
    if adval > 25 then tst2 'If A/D value is less than 10
    portb = %00000001 ' then light LED0 only

    tst2:
    if adval > 75 then tst3 'If A/D value is between 25 and 75
    portb = %00000011
    goto cont 'continue with the program
    tst3:
    if adval > 99 then
    portb = %00000111
    goto cont 'continue with the program

    ENdif
    cont:
    Pause 100 'wait 1 second
    goto loop
    end


    Thanks in advance,
    joe

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,523


    Did you find this post helpful? Yes | No

    Default

    Hi Joe,
    I'm not sure but try changing the left/right justified setting on the ADC. Your not saying which PIC you're using but on the 16F688 for example, you set that with bit0 of ADCON0 though it may be different on other PIC's - see the datasheet for your PIC.

    Let me know how it goes.

    /Henrik.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik,
    I'm using 16F876A, I did some trial and error and finally got it. But I use this formula..
    Adval=Adval*100/255 'gives the range 0-100
    But I used Define ADC_BITS 8.

    Thanks for your guidance.
    joe

Similar Threads

  1. LCD Display
    By lambert in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th January 2010, 22:18
  2. LCD display not working properly
    By dilpkan in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 2nd February 2008, 07:43
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. LCD Display not working - PIC heating...
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 24th September 2006, 07:35
  5. A/D display result on LCD
    By winsthon in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 10th January 2004, 10:09

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