LCD and PIC18F2685 - Weird LCD behavior


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2008
    Location
    Berlin, Germany
    Posts
    14

    Default LCD and PIC18F2685 - Weird LCD behavior

    I'm using the 28 pin demo board from Microchip (see schematic below) with a 18F2685pic, MPLAB IDE and Picbasic pro v2.47, and ICD2 for programming. The LCD pins are connected in the default manner. I'm using the internal oscilator @8 MHZ and the config file in my pbp directory is modified accordingly, that is:
    Code:
    __CONFIG    _CONFIG1H, _OSC_IRCIO67_1H
    The behavior the LCD is experiencing is bizzare: First, it shows black boxes on the first line (so everything fine until now). When releasing from reset, still black boxes on the first line. If I take LCD's Vdd out for a second I start seeing weird characters. Plug it back in, weird characters again. When I try to output "123456789" I get "1230123"(that is, with the vdd plugged in). If I try to output "hello", werid characters again.

    Some of the pins on the demo board are occupied with the default components(leds, pot) but I tried to stay away these pins. Just RB3 (LCD E(nable) is on the same pin as one of the board's LED)

    and the code:
    Code:
    ' display a message on the lcd
    DEFINE OSC 8
    DEFINE LCD_DREG PORTB ' portb is the port used for data lines
    DEFINE LCD_DBIT 4		'the pin on port connected to LCD pin DB4
    DEFINE LCD_RSREG PORTA	'pic port used for the RS line
    DEFINE LCD_RSBIT 4		' port pin where RS pin is connected
    DEFINE LCD_EREG PORTB	' PIC port where E pin is connected
    DEFINE LCD_EBIT 3		' port pin where E pin is connected
    DEFINE LCD_BITS 4		' 4 bit mode
    DEFINE LCD_LINES 2		' 2 LCD lines
    DEFINE LCD_COMMANDUS 2000	'delay between LCD commands
    DEFINE LCD_DATAUS 50		'delay between data sent
    adcon1=7
    trisb=0 				' port b all outputs
    trisa=0					' port a all outputs
    intcon2.7=0			'enable pull ups
    OSCCON = %01110000
    '---main program
    
    repeta:
    high portb.0   ' light led to see when main loop is running
    LCDOUT $fe,1           ' Clears LCD
    LCDOUT $fe,2, "hello"  ' Returns to beginning of line 1 and writes "string"
    pause 1000
    goto repeta
    The lcd is a optorex dmc16207 which is Hitachi HD44780 compatible
    Attached Images Attached Images  
    Last edited by Castor; - 28th April 2008 at 15:42.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Try this:
    Code:
    DEFINE OSC 8
    DEFINE LCD_DREG PORTB ' portb is the port used for data lines
    DEFINE LCD_DBIT 4		'the pin on port connected to LCD pin DB4
    DEFINE LCD_RSREG PORTA	'pic port used for the RS line
    DEFINE LCD_RSBIT 4		' port pin where RS pin is connected
    DEFINE LCD_EREG PORTB	' PIC port where E pin is connected
    DEFINE LCD_EBIT 3		' port pin where E pin is connected
    DEFINE LCD_BITS 4		' 4 bit mode
    DEFINE LCD_LINES 2		' 2 LCD lines
    DEFINE LCD_COMMANDUS 2000	'delay between LCD commands
    DEFINE LCD_DATAUS 50		'delay between data sent
    adcon1=7:trisb=0:trisa=0:intcon2.7=0:osccon=$70
    PAUSE 1000
    repeta:
    high portb.0:LCDOUT $fe,1,$fe,2, "hello":pause 1000:goto repeta

  3. #3
    Join Date
    Apr 2008
    Location
    Berlin, Germany
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Thanks skimask for the suggestion but unfortunately the output is still the same. Initially black boxes. On "release from reset", still black boxes. If I pull out the LCD Vdd - strange characters, plug it back in, I get character boxes filled with strange characters corresponding to the number of characters I output with LCDOUT and a blinking cursor at the end.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    ADCON1 must be = $0F. If =7 AN9 is still analog.

    If you still have problem copy ALL your CONFIG fuse settings here.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    ADCON1 must be = $0F. If =7 AN9 is still analog.
    Which would likely account for the "0123456789" vs. "012301230" error noted in the 1st post.
    Good call...

  6. #6
    Join Date
    Apr 2008
    Location
    Berlin, Germany
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Eventually I moved the data lines on PORTC and voila, the LCD is displaying characters as it should. Thank you guys for the help.

    Here is the working code:

    Code:
    ' display a message on the lcd
    
    '--- defines
    DEFINE OSC 8
    DEFINE LCD_DREG PORTC ' portb is the port used for data lines
    DEFINE LCD_DBIT 4		'the pin on port connected to LCD pin DB4
    DEFINE LCD_RSREG PORTA	'pic port used for the RS line
    DEFINE LCD_RSBIT 4		' port pin where RS pin is connected
    DEFINE LCD_EREG PORTB	' PIC port where E pin is connected
    DEFINE LCD_EBIT 3		' port pin where E pin is connected
    DEFINE LCD_BITS 4		' 4 bit mode
    DEFINE LCD_LINES 2		' 2 LCD lines
    DEFINE LCD_COMMANDUS 2000	'delay between LCD commands
    DEFINE LCD_DATAUS 50		'delay between data sent
    
    '--- register configs
    adcon1=$0F ' all digital i/o
    trisb=0		' portb all outputs
    trisa=0		'porta all outputs
    trisc=0
    intcon2.7=0	' enable pullups
    osccon=$70	' oscilator configure
    
    '--- main program
    PAUSE 1000				' pause to let the LCD initialise
    repeta:
    high portb.0			' light led to see when main loop is running
    LCDOUT $fe,1			' Clears LCD
    LCDOUT $fe,2, "hello"	' Returns to beginning of line 1 and writes "string"
    LCDOUT $fe, $C0, "world"    ' line 2
    pause 1000				' pause to see it
    goto repeta				' do this forever

Members who have read this thread : 1

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