PIC18F4525 & LCD problem - external resonator ?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2007
    Posts
    13

    Default PIC18F4525 & LCD problem - external resonator ?

    I am hooking up PIC 18F4525 to a parallel LCD screen which has HD44780 controller (16X2). I am just trying to test the connection and the working of the LCD by writing a code which displays a one line test statement. I am using Micro Code Studio.

    The LCD screen shows black boxes. I also hooked up a 20K pot to adjust the contrast. The LCD lights up...but doesn't display anything. The PIC is working fine by itself, I tested it. But its not communicating with the LCD.

    I think the problem has something to do with the clock/oscillator. I just have a DEFINE OSC statement specifying the speed of the internal oscillator.

    Do I need to connect an external resonator (20MHz) to the two OSC pins of the PIC ? If so, how do I do it ? Do I need to add something to my code ? How ?

    I dont have any knowledge of how external resonators work......Please help.



    Here is the code -


    DEFINE OSC 20

    '******Setting up the LCD display******

    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    'DEFINE LCD_COMMANDUS 2000
    'DEFINE LCD_DATAUS 50

    TRISB=0

    LCDOUT $FE, 1
    LCDOUT "PIC - LCD Test "
    LCDOUT $FE, $C0

    STOP

    END

  2. #2
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    Hello.

    You need to use external oscillator on OSC1 and 2, or add this line to your code:

    @ __CONFIG _CONFIG1H, _OSC_INTIO67_1H

    This instruction configure your pic with the internal oscillator.

    Change DEFINE OSC 20 to DEFINE OSC 8.

    If you want to use internal osc to 20Mhz you need to use the PLL.
    Last edited by Raflex; - 4th November 2007 at 06:37.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Can you post a schematic of you hook up or give a pin to pin description?

    In you other thread you mentioned using four wires, well it does take four wires for the data but two more for "control".

    You do not need an external OSC to use a LCD, but the configuration will need to be correct.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Nov 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Can you post a schematic of you hook up or give a pin to pin description?

    In you other thread you mentioned using four wires, well it does take four wires for the data but two more for "control".

    You do not need an external OSC to use a LCD, but the configuration will need to be correct.

    Hi Mackrackit,

    Here is the pin to pin description of my schematic:

    PIC 18F4525 ------ LCD HD44780 (16X2)
    B0-------- Pin4 -RS
    B1-------- Pin6- Enable
    B4-------- Pin11- D4
    B5-------- Pin12- D5
    B6-------- Pin13- D6
    B7-------- Pin14- D7

    LCD Pin3- connected to a 20K pot for contrast. The screen still shows black boxes !!!
    LCD Pin5- R/W is connected to ground.

    PIC Pin1- MCLR is not connected to anything. Is this a problem ?


    Here is the code I am using:

    DEFINE OSC 8

    '******Setting up the LCD display******

    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50


    @_CONFIG_CONFIG1H_OSC_INTIO67_1H

    TRISB=0 'Set Port B as output



    PAUSE 1000

    LCDOUT $FE, 1
    LCDOUT "PIC - LCD Test "
    LCDOUT $FE, $C0
    STOP



    Please Help !!!

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Check the data sheet for this PIC. Several PORTB pins are analog intputs at power-up, and
    you'll need to write to OSCCON to configure it for 8MHz internal.

    The default value in OSCCON at reset is for 1MHz.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Nov 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Check the data sheet for this PIC. Several PORTB pins are analog intputs at power-up, and
    you'll need to write to OSCCON to configure it for 8MHz internal.

    The default value in OSCCON at reset is for 1MHz.
    I have defined Port B as output port in my code by using TRISB=0.

    And by using the command:
    @_CONFIG_CONFIG1H_OSC_INTIO67_1H

    the internal oscillator is working fine at 8 MHz.

    The LCD is now displaying text messages, but when I try to display a numerical value of a variable or a constant, it doesnt show anythin as the screen remains blank.

    Please Help !!







    DEFINE OSC 8

    '******Setting up the LCD display******

    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50


    @_CONFIG_CONFIG1H_OSC_INTIO67_1H

    TRISB=0 'Set Port B as output



    PAUSE 1000

    LCDOUT $FE, 1
    LCDOUT "PIC - LCD Test "
    LCDOUT $FE, $C0
    STOP

  7. #7
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    Hello, you need to use DEC command, for example:

    b0 var byte

    b0=100

    loop:
    LCDOut $fe, 1
    LCDOut "LCD TEST" 'Display line1
    LCDOut $fe, $c0 'Move to line 2
    LCDOut Dec b0 'Display b0 on LCD
    Pause 500 'Wait .5 second
    goto loop

    end

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    OK. Sorry. You're probably right, but give this a shot just for the heck of it.;o}

    1. Edit your 18F4525.INC file in your PBP directory. Change this line;
    __CONFIG _CONFIG1H, _OSC_XT_1H

    to this; __CONFIG _CONFIG1H, _OSC_INTIO67_1H

    Save the file.

    Note this line: __CONFIG _CONFIG3H, _PBADEN_OFF_3H saves you from having to
    manually disable A/D for several PORTB pins. Just FYI.

    2. Change your code to something like this;

    Code:
    DEFINE OSC 8
    
    '******Setting up the LCD display******
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    
    '@_CONFIG_CONFIG1H_OSC_INTIO67_1H ; this does nothing & it is not a command
    
    TRISB=0 'Set Port B as output
    OSCCON = %01110010
    
    a VAR BYTE
    
    Loop:
      LCDOUT $FE,1,"PIC - LCD Test "
      PAUSE 1000  
      FOR a = 0 TO 255
       LCDOUT $FE, $C0," A = ", #a
       PAUSE 1000
      NEXT a
      GOTO Loop
      
      END
    Does it work now?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. LCD problem with 16F628
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 19th September 2016, 08:28
  2. Newbie? Problem with LCD
    By lew247 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th December 2009, 19:48
  3. LCD Problem
    By karenhornby in forum General
    Replies: 3
    Last Post: - 19th June 2008, 11:43
  4. Migrating from PIC16F690 to PIC18F4525 and having LCD issues
    By jblackann in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th June 2008, 20:05
  5. PIC18F4525 & LCD simple code problem
    By aggie007 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd November 2007, 16:29

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