Interesting result on a 16F688 with ADC and LCD


Closed Thread
Results 1 to 19 of 19
  1. #1
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default Interesting result on a 16F688 with ADC and LCD

    Ive got some code I converted from a 18F4550 thermostat, want to use it on a 16F688, on running the RA4 port never goes high, and the LCD displays a block on row1 about location 14 on a 4x20 LCD. adjusting the pot on RA0 does nothing, ive tried messing with ADCON0 & 1, and ANSEL, but im doing something wrong.
    MCP9700A on RA1
    POT on RA0
    RA4 has LED

    Code:
    include "ADC_Default.bas"
    DEFINE LCD_DREG PORTC   ' LCD Data bits on PORTC
    DEFINE LCD_DBIT 2       ' PORTC starting address
    DEFINE LCD_RSREG PORTC  ' LCD RS bit on PORTC
    DEFINE LCD_RSBIT 0      ' LCD RS bit address
    DEFINE LCD_EREG PORTC   ' LCD E bit on PORTC
    DEFINE LCD_EBIT 1       ' LCD E bit address
    DEFINE LCD_BITS 4       ' LCD in 4-bit mode
    DEFINE LCD_LINES 4      ' LCD has 4 rows
    ANSEL = %00000011
    TRISA = %00000011
    TRISC = 0 ' PORTC is output
     
    LCDOUT $FE, 1 ' Clear LCD
    PAUSE 500 ' Wait 0.5sec for LCD to initialize
    SETT Var Word ' A/D converter result in 10bit
    READT var word
    AGAIN:
    ADCIN 0, READT ' Read Channel 0 data
    ADCIN 1, SETT ' Read Channel 0 data
    ReadT = ReadT - 6500
    SETT = SETT / 1024 'Output = 0 - 63
    readT = ((((readT / 10) * 9) / 5) / 13) + 32 'Convert ANA0 to Farent.
    setT = sett + 40 ' Temp Range will be 40 - 103
    LCDOUT $FE, 2
    LCDOUT $FE, $80
    LCDOUT "Set Temp = ", DEC setT , $DF , "F    "
    LCDOUT $FE, $C0
    LCDOUT "Temp = ", DEC READT , $DF , "F    "
    if SETT < (readt - 1) then PORTA.4 = 0
    if sett > (readt + 1) then PORTA.4 = 1 
    pause 100
    GOTO AGAIN ' Repeat
    END
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  2. #2
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Add 1K pull up resistor.

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Hey Chris, Read the data sheet.... RA4 is open collector only when used as output..... Read the data sheet... It's your friend....
    Dave Purola,
    N8NTA
    EN82fn

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


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Hi Dave,
    That was actually my initial thought as well but what I did was what you suggest (but perhaps didn't do ?) and read the datasheet before posting - which resulted in me not posting that response ;-)
    There's no mentioning of RA4 being open drain on the 16F688 as is the case on some other devices - at least not what I could find.

    /Henrik.

  5. #5
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Yep I looked at it last night. I might need to add a resistor. On page 33 though it says it has weak internal pullups unless its an output pin. However that doesnt solve the LCD issue?
    I tried removeing all the ADC and output pin code, and just leave it barebones with the LCD code and LCD still doesnt work, weird.

    I am not sure what it is as the code is pretty simple.

    Code:
    DEFINE LCD_DREG PORTC   ' LCD Data bits on PORTD
    DEFINE LCD_DBIT 2       ' PORTD starting address
    DEFINE LCD_RSREG PORTC  ' LCD RS bit on PORTD
    DEFINE LCD_RSBIT 0      ' LCD RS bit address
    DEFINE LCD_EREG PORTC   ' LCD E bit on PORTD
    DEFINE LCD_EBIT 1       ' LCD E bit address
    DEFINE LCD_BITS 4       ' LCD in 4-bit mode
    DEFINE LCD_LINES 4      ' LCD has 4 rows
    
    'TRISA = %00000011
    TRISC = 0 ' PORTC is output
     
    LCDOUT $FE, 1 ' Clear LCD
    PAUSE 500 ' Wait 0.5sec for LCD to initialize
    
    AGAIN:
    LCDOUT $FE, 2
    LCDOUT $FE, $80
    LCDOUT "Set Temp = "
    LCDOUT $FE, $C0
    LCDOUT "Temp = "
    pause 100
    GOTO AGAIN ' Repeat
    
    END
    Problem is its a removable PIC, LCD is tied to board with a premade cable so I cant change pins from LCD to PORTC

    Henrik, I saw the chart on page
    Last edited by wdmagic; - 24th April 2013 at 19:29.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    You removed ADC code, , but is ADC enabled on PortC for this PIC?

    Robert

  7. #7
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    dang, I forgot C is adc ports too. Ive got an appointment I cant miss. Ill be back in a few hours. what command is it to turn adc off on portc. oh and since these are 6 bit registers do I use %000000 or %00000000 ? when doing settings?
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  8. #8
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    PIC - LCD Pins
    C0 - 4
    C1 - 6
    C3-6 - 11-14
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  9. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Datasheet tells you what register to set.

    I'd use 8 bits, no surprises.

    Robert
    Last edited by Demon; - 24th April 2013 at 19:40. Reason: typo

  10. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Quote Originally Posted by wdmagic View Post
    PIC - LCD Pins
    C0 - 4
    C1 - 6
    C3-6 - 11-14
    Start pin is 2 or 3?

  11. #11
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Code:
    DEFINE LCD_DREG PORTC   ' LCD Data bits on PORTC
    DEFINE LCD_DBIT 2       ' PORTC starting address
    DEFINE LCD_RSREG PORTC  ' LCD RS bit on PORTC
    DEFINE LCD_RSBIT 0      ' LCD RS bit address
    DEFINE LCD_EREG PORTC   ' LCD E bit on PORTC
    DEFINE LCD_EBIT 1       ' LCD E bit address
    Sorry I was in a hurry to leave, starting bit is 2.

    (C2-5 - 11-14) corrected
    Last edited by wdmagic; - 24th April 2013 at 22:53.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  12. #12
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Quote Originally Posted by wdmagic View Post
    Code:
    i
    DEFINE LCD_DREG PORTC   ' LCD Data bits on PORTC
    DEFINE LCD_DBIT 2       ' PORTC starting address
    The DBIT might be your problem - It has to be either 0 or 4 - you have to have your data lines as pins 0-3 or 4-7.

    From the manual:

    "If an 8-bit bus is used, all 8 bits must be on one port. If a 4-bit bus is used,
    the top 4 LCD data bits must be connected to either the bottom 4 or top 4 bits of
    one port. Enable and Register Select may be connected to any port pin. R/W may
    be tied to ground if the LCDIN command is not used."
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  13. #13
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Ahhhh. ok, well dang, these are hardwired, I will have to move pins in the plug...
    I figured thats why we could define a starting address was it started out on the one stated and counted up from there.

    thanks andywpg
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  14. #14
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    OK I now have something on LCD but its jibberish. I moved chip and lcd to breadboard for time being, PORTC 0-3 is now starting bits, RS is C.4 and E is C.5, nothing else is hooked up except LCD. I will need to turn on ADC for PORTA 0 & 1 after LCD starts working.

    heres the code, notes are beside respective lines

    Code:
    DEFINE LCD_DREG PORTC   ' LCD Data bits on PORTD
    DEFINE LCD_DBIT 0       ' PORTD starting address
    DEFINE LCD_RSREG PORTC  ' LCD RS bit on PORTD
    DEFINE LCD_RSBIT 4      ' LCD RS bit address
    DEFINE LCD_EREG PORTC   ' LCD E bit on PORTD
    DEFINE LCD_EBIT 5       ' LCD E bit address
    DEFINE LCD_BITS 4       ' LCD in 4-bit mode
    DEFINE LCD_LINES 4      ' LCD has 4 rows
    ADCON0 = 0 ' Tried it with and without this line
    ANSEL = 0 ' Tried it with and without this line
    TRISA = %00000011 ' Left this cause it shouldnt hurt LCD
    TRISC = %00000000 
     
    LCDOUT $FE, 1 ' Clear LCD
    PAUSE 500 ' Wait 0.5sec for LCD to initialize
    
    AGAIN:
    LCDOUT $FE, 2
    LCDOUT $FE, $80
    LCDOUT "This is a Test"
    pause 1000
    GOTO AGAIN ' Repeat
    Theres not much here to go wrong, anyone see anything?
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  15. #15
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Pause 1000 before 1st LCDOUT to start.

  16. #16
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Quote Originally Posted by wdmagic View Post
    OK I now have something on LCD but its jibberish. I moved chip and lcd to breadboard for time being, PORTC 0-3 is now starting bits, RS is C.4 and E is C.5, nothing else is hooked up except LCD. I will need to turn on ADC for PORTA 0 & 1 after LCD starts working.
    I had trouble without the following two defines (after the ones you already have):

    Code:
    ' Set command delay time in us
    DEFINE LCD_COMMANDUS 1500
    ' Set data delay time in us
    DEFINE LCD_DATAUS 44
    Then try this:

    Code:
    PAUSE 500 ' Wait 0.5sec for LCD to initialize (May need to be one second, depends on your LCD)
    DO
        LCDOUT $FE, 1, "This is a Test"
        Pause 1000
        LCDOUT $FE, 1 'clear the screen
        Pause 250 'wait 1/4 second
    Loop
    No reason the above shouldn't work. Good luck
    Last edited by andywpg; - 25th April 2013 at 02:08.
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  17. #17
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Quote Originally Posted by wdmagic View Post
    OK I now have something on LCD but its jibberish. I moved chip and lcd to breadboard for time being, PORTC 0-3 is now starting bits, RS is C.4 and E is C.5, nothing else is hooked up except LCD. I will need to turn on ADC for PORTA 0 & 1 after LCD starts working.
    This may sound like a dumb question, but it IS a Hitachi 44780-comapatable display, right?

    Just a thought......
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  18. #18
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    Agg i posted a reply but it didnt take.

    Yes Demon, that was the problem, I copied and pasted backwards, I changed the pins in the plug so it does work now on the premade board. a second problem I found was the premade board had a 7805 on it and I had tied the input of that to 5volts, it barely lit the screen and did not turn on the PIC, been stressing alot here lately, lots going on. but I have learned a ton this week. so the thermostat works, thanks everyone
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  19. #19
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Interesting result on a 16F688 with ADC and LCD

    yes andywpg, it is, I posted earlier but aprently the page didnt save it. its working now.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

Similar Threads

  1. Converting 10bit ADC result to 8 bit
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 5th March 2012, 20:38
  2. Timer0 Reload based on ADC result
    By Cyborg in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 22nd February 2011, 07:11
  3. Replies: 2
    Last Post: - 22nd January 2011, 01:58
  4. 16f688 Adc
    By PICante in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd August 2008, 10:34
  5. PBP 16-bit ADC result math
    By sonic in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2005, 14:21

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