Problems with LCD in pic 18f8520


+ Reply to Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Jan 2012
    Posts
    5

    Default Problems with LCD in pic 18f8520

    Hello! I have been trying to run the LCD example that comes with de Microcode studio, but is not working!
    I'm use the BIGPIC5 that uses pic 18f8520 and i use basic lenguaje.
    This is the code that i try to run:

    DEFINE OSC 4
    DEFINE LCD_DREG PORTB
    DEFINE LCD_RSREG PORTA
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTA
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 8
    DEFINE LCD_LINES 2




    Pause 500 ' Wait for LCD to startup


    mainloop: Lcdout $fe, 1 ' Clear LCD screen
    Lcdout "Hello" ' Display Hello
    Pause 5000 ' Wait .5 second


    Lcdout $fe, 1 ' Clear LCD screen
    Lcdout "World"
    Pause 500 ' Wait .5 second


    Goto mainloop ' Do it forever


    The only thing that i get is some leds blinking, but in the lcd not appear anything.
    Please could you help me?

  2. #2
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    141

    Default Re: Problems with LCD in pic 18f8520

    Quote Originally Posted by JAVEHE View Post
    Hello! I have been trying to run the LCD example that comes with de Microcode studio, but is not working!
    I'm use the BIGPIC5 that uses pic 18f8520 and i use basic lenguaje.
    This is the code that i try to run:

    DEFINE OSC 4
    DEFINE LCD_DREG PORTB
    DEFINE LCD_RSREG PORTA
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTA
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 8
    DEFINE LCD_LINES 2




    Pause 500 ' Wait for LCD to startup


    mainloop: Lcdout $fe, 1 ' Clear LCD screen
    Lcdout $fe, "Hello" ' Display Hello
    Pause 5000 ' Wait .5 second this is actually 5 seconds


    Lcdout $fe, 1 ' Clear LCD screen
    Lcdout $fe, "World"
    Pause 500 ' Wait .5 second


    Goto mainloop ' Do it forever


    The only thing that i get is some leds blinking, but in the lcd not appear anything.
    Please could you help me?
    Make sure you have a 10K potentiometer set up so you can change the voltage on the VL pin to adjust the contrast. Not the change above in your code, whenever you use the lcdout command you need the $fe as shown in red above.
    Shawn

  3. #3
    Join Date
    Jan 2012
    Posts
    5

    Default Re: Problems with LCD in pic 18f8520

    Thanks 4 your answer. I did that but still not working, my lcd doesnt show anything...I see the lcd turn on and i can change the contrast but doesnt appear anything Also I see some leds blinking.

    I've been thinking if the problems is something with the lcd connector, because i've been trying everything but nothing.....How can i check that?

  4. #4
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    141

    Default Re: Problems with LCD in pic 18f8520

    You have it configured for 8bit, do you have all 8 data lines connected to the pic? LVP disabled? Extended instructions disabled? I/O's set to digital?

    Try adding to your code
    Code:
    adcon1=15
    cmcon=7
    Shawn

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,253

    Default Re: Problems with LCD in pic 18f8520

    Moved from Code Examples.

    Robert

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,283

    Default Re: Problems with LCD in pic 18f8520

    Hi,
    Shawn said what I was going to regarding setting the pins to digital, however....

    I took a quick look in the BIGPIC5 manual and in the 2*16LCD section it says[quote]
    The character LCD communicates with the microcontroller via 4-bit data bus[quote]
    What's also noticable when you look in the manual is that the LCD is connected to PortD while you have your code setup as if the LCD was connected to PortA and PortB. So, I'm not surprised it doesn't work.... And, since it's on PortD you don't need to worry about the analog stuff.

    Also, make sure that MCU-card with the 18F8720 on it have a 4Mhz x-tal. If it have something else that needs to be reflected in the code or the timing will wrong.

    So, read the manual for the development board and set the code up accordingly.


    Finally, it's been a while since I used LCDOUT but I don't think the part about the $fe that Shawn wrote is 100% correct. You need $fe if the next byte you send is to be interpreted as a command by the LCD, for example LCDOUT $fe,1 to clear the screen. But when writing actual data to it you should not have the $fe in there as it will then try to interpret the first character after $fe as a command and strange things will occur. LCDOUT $fe,"Hello" will interpret the H as a command (whatever that might be) and then try to print ello.

    /Henrik.

  7. #7
    Join Date
    Jan 2012
    Posts
    5

    Default Re: Problems with LCD in pic 18f8520

    Yes, I said that or i try to said that. This is the example that comes with Micro Code Examples as I said in my first post. Sorry for my english

  8. #8
    Join Date
    Jan 2012
    Posts
    5

    Default Re: Problems with LCD in pic 18f8520

    Ok thank for you time!!
    I change the connection of the LCD, and i put PortD, also i change the $fe thing, but nothing happend. The only change that i see is that now the portD leds are blinking.

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,283

    Default Re: Problems with LCD in pic 18f8520

    Hi,
    Did you change the individual bit assignement to match the actual hardware and changed from 8bit to 4bit?

    I'd try something like this:
    Code:
    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTD DEFINE LCD_RSBIT 2
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 4000
    DEFINE LCD_DATAUS 100
    
    TRISD = %000000011
    
    PAUSE 1000
    
    LCDOUT $FE,1,"Hello World"  'Clear screen then print.
    
    WHILE 1 : WEND
    /Henrik.

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,551

    Default Re: Problems with LCD in pic 18f8520

    Hi,

    the question that comes to me is ...

    Which socket of the BP5 do you use for the 8 bits mode LCD ???

    interesting answer ... for sure.

    you should use Port J and D ... ( yess , both ! )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,551

    Default Re: Problems with LCD in pic 18f8520

    That's really incredible what you can find with dedicated examples from the hardware brand ...

    Code:
    /*
     * Project name:
         Lcd8_Test (Demonstration of the Lcd8 Library routines)
     * Copyright:
         (c) Mikroelektronika, 2008.
     * Revision History:
         20081218:
           - initial release;
     * Description:
         This code demonstrates how to use Lcd 8-bit library. Lcd is first
         initialized, then some text is written, then the text is moved.
     * Test configuration:
         MCU:             P18F8520
         Dev.Board:       BIGPIC5
         Oscillator:      HS, 10.0 MHz
         Ext. Modules:    Lcd 2x16 module
         SW:              mikroC PRO for PIC
     * NOTES:
         - None.
    */
    // Lcd8 module connections
    sbit LCD8_RS at RJ2_bit;
    sbit LCD8_RW at RJ3_bit;
    sbit LCD8_EN at RJ4_bit;
    sbit LCD8_D7 at RD7_bit;
    sbit LCD8_D6 at RD6_bit;
    sbit LCD8_D5 at RD5_bit;
    sbit LCD8_D4 at RD4_bit;
    sbit LCD8_D3 at RD3_bit;
    sbit LCD8_D2 at RD2_bit;
    sbit LCD8_D1 at RD1_bit;
    sbit LCD8_D0 at RD0_bit;
    sbit LCD8_RS_Direction at TRISJ2_bit;
    sbit LCD8_RW_Direction at TRISJ3_bit;
    sbit LCD8_EN_Direction at TRISJ4_bit;
    sbit LCD8_D7_Direction at TRISD7_bit;
    sbit LCD8_D6_Direction at TRISD6_bit;
    sbit LCD8_D5_Direction at TRISD5_bit;
    sbit LCD8_D4_Direction at TRISD4_bit;
    sbit LCD8_D3_Direction at TRISD3_bit;
    sbit LCD8_D2_Direction at TRISD2_bit;
    sbit LCD8_D1_Direction at TRISD1_bit;
    sbit LCD8_D0_Direction at TRISD0_bit;
    // End Lcd8 module connections
    Don't you think ???

    Alain

    No miracle, eh, my friend JAVEHE ...
    Last edited by Acetronics2; - 16th January 2012 at 20:00.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  12. #12
    Join Date
    Jan 2012
    Posts
    5

    Default Re: Problems with LCD in pic 18f8520

    Thanks! Now is working I had problems with "LCD connections" but now i change and is fine

    another question... can i show in my lcd a "variable"? I mean a character that changes?

  13. #13
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,283

    Default Re: Problems with LCD in pic 18f8520

    Code:
    myVar VAR BYTE
    
    For myVar = 0 to 255
      LCDOUT $FE, 1, #myVAR
      PAUSE 1000
    NEXT

  14. #14
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    141

    Default Re: Problems with LCD in pic 18f8520

    Quote Originally Posted by HenrikOlsson View Post
    Finally, it's been a while since I used LCDOUT but I don't think the part about the $fe that Shawn wrote is 100% correct. You need $fe if the next byte you send is to be interpreted as a command by the LCD, for example LCDOUT $fe,1 to clear the screen. But when writing actual data to it you should not have the $fe in there as it will then try to interpret the first character after $fe as a command and strange things will occur. LCDOUT $fe,"Hello" will interpret the H as a command (whatever that might be) and then try to print ello.
    You are correct, I never use LCDOUT this way. I always have a command in there so I have never come across this problem. Thanks for correcting this
    Shawn

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts