PIC18F25K22 & 2 x 20 LCD

Discussion in 'Embedded Systems and Microcontrollers' started by nerdegutta, Apr 1, 2012.

  1. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,513
    784
    Hi.

    Has anybody seen this on their LCD display?
    [​IMG]

    I'm working through the Hi Tech C PIC18 sample files, and trying to display some text. But all I get is this. :(

    lcd.txt = lcd.c
    lcd-h.txt = lcd.h

    MPLAB 8.63
    Hi tech C PIC18 (lite mode) V9.80
    PIC 18F25K22
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    Usually means not initialized correctly.

    Have you confirmed all of your connections by stepping through the code and confirming the correct data is arriving at the LCD?

    Also could be your timing delays are not correct.
     
  3. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    How did you set up the oscillator
    you have a #define _XTAL_FREQ 4000000

    If your using PLL it's not set up in code
     
  4. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,513
    784
    As far as I can see, all the EN, RS and R/W's are connected correct, same goes for datalines. But I can always check again. :)

    I know the best practice is to have the Configuration Bits set in code, but here they are in MPLAB. I've used internal oscillator.

    On a later stage, they will end up in the code.
     
  5. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    Like I said you defined 40mhz
    That's not happening with that chip Pll is times 4

    So you set the osccon to one of these
    16 x4 = 64mhz
    8 x 4 = 32mhz
    4 x 4 = 16 mhz
    You get the idea it goes lower

    There is no 40 mhz and the OSC will not run with out you setting the OSCCON in code
    now if you where to use a 10mhz crystal you can get 40mhz

    Put this in your code
    Code ( (Unknown Language)):
    1.  
    2. #define _XTAL_FREQ 6400000
    3. OSCCON = 0x73  'for 16mhz intosc
    4.  
     
    Last edited: Apr 2, 2012
  6. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,513
    784
    40MHz?

    Isn't 4000000 = 4MHz?
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    How do you connect the LCD to PIC. Do you use 8 or 4 bit mode
     
  8. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,513
    784
    Four bit mode. To RC4-RC7. Control pins are connected to RA1-RA3.
     
  9. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Jens From your code it looks like you are writing the nibbles in wrong order. As the example is made for using the 4 lower bits of the port. try this instead
    Code ( (Unknown Language)):
    1. /* send data to the LCD */
    2. void
    3. lcd_data(unsigned char c) {
    4.  LCD_WAIT; // may check LCD busy flag, or just delay a little, depending on lcd.h
    5.  LCD_DATA = 0;
    6.  LCD_RS = 1;
    7.  if (fourbit) {
    8.    LCD_DATA = c &0xF0;
    9.    LCD_STROBE();
    10.    LCD_DATA = ( ( c << 4 ) & 0xF0 );      
    11.    LCD_STROBE();
    12.  } else {
    13.   LCD_DATA = c;
    14.   LCD_STROBE();
    15.  }
    16.  LCD_RS = 0;
     
  10. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    Did I miss a 0 sorry but it's still the same if you don't set the OSCCON the chips oscillator will not run

    Been there and done that. There is no default setting like some chips have

    And I ask if you where using PLL
     
  11. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,513
    784
    Now it looks like this:
    [​IMG]

    I've added the 64000000 and the OSCON. It looks like in the picture...
    PLL? No, I don't think so...
     
  12. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    I'll test your code on hardware when I get home and see whats going on here

    You have to turn pll on in the configure word PLLCFG: 4 x PLL Enable bit
    and the osccon setting I posted should work at 64 mhz with pll and you Lcd should work
    You used the standard LCD library that came with Hi-Tech
     
  13. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,513
    784
    I found the setting you were talking about just now. It was on "Oscillator used directly".

    I'll change it and try again.

    Yes, it is a pretty std LCD, and the LCD code found in the Hi Tech sample folder under PIC18.

    Thanks.
     
  14. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,513
    784
    With this:

    Code ( (Unknown Language)):
    1. OSCCON = 0x73
    I cannot compile the program. I get an error message referring to the file PIC18F25K22.h, line 5894.

    file pic18f25k22 line 5894. (Extern volatile is line 5894)
    Further more I get an error on lcd.c line 122, the lcd_puts function..

    I've checked the box in the Configuration Bits window that says: "Configuration Bits set in code."
    And I've added this line:

    Code ( (Unknown Language)):
    1. #pragma config IESO = OFF, FOSC = INTIO67, PRICLKEN = OFF, PLLCFG = ON
    But still nothing.
     
  15. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    Are you using a boot loader? for get this part

    And start here
    Here the whole thing it should work out of the box unzip it and open with MPLAB
    if you put it on C/ that's where I built it

    I set the configure in MPLAB to use 4mhz OSC no pll
     
    Last edited: Apr 2, 2012
  16. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    My advice is first make sure you are getting what you are getting with your OSC settings.

    You can do this pretty easily with the simulation mode and the stop watch utility and a test program using your delay functions.

    Once you have that nailed down, create a small test program that toggles each bit one at a time (RS, E, D4-D7 etc). Use a scope, logic analyzer, logic probe whatever to verify each bit.
     
  17. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    What line is 5894? Which is 122? And you have a lot more errors that that, it looks like.
     
  18. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    He left the LCD.C file out is why he got the errors
     
  19. nerdegutta

    Thread Starter Moderator

    Dec 15, 2009
    2,513
    784
    Thanks. I do not use a boot loader. Is that the problem?
    I'll try the code when I get home from work.

    This is line 5894:

    Code ( (Unknown Language)):
    1. extern volatile unsigned char OSCCON @ 0xFD3;
    The rest of the errors are coming from the OSCCON error initially.
    Line 122 in LCD.C is the start on the lcd_puts function.

    I tried with and without
    Code ( (Unknown Language)):
    1. #include "lcd.c"
    Thanks guys, I'll try the code, setup later today, and I'll go over the wiring for the n'th time. :)
     
  20. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    Well your not alone I tried it on hardware I'm getting the samething I've used Hi-Tech for the 10-12-16F chips and the LCD Library worked fine.

    And I no what it takes to use the 18f25k22 I use Swordfish for the 18f chips and have set the OSC up to run at any speed.

    It's not using the delay code
     
Loading...