LCD displays black blocks on 1st row [solved]

edorul
2012-07-31
2013-05-30
  • edorul
    edorul
    2012-07-31

    Hello.

    At first I'd like to thanks a lot "Great Cow Basic" developpers !!! It's a very great work :-)

    Today I've tried LCD library and I get the same problem than two other people on the forum : my LCD only displays black blocks on the first raw.
    I need to precise that this issue only appears on PIC reset and never after a power-up. Logicaly hardware reset of the LCD was not done again after a PIC reset.

    I modified "InitLCD" function in "lcd.h" library to include soft reset of the LCD :

    '------ Initialize lcd with soft reset (from HD44780 datasheet) -------
    '----------- LCD_IO_2 was not modified, only 4 and 8 bits parts
    sub InitLCD
        #IFDEF LCD_IO 2
            DIR LCD_DB OUT
            DIR LCD_CB OUT
            SET LCD_DB OFF
            SET LCD_CB OFF
            Wait 35 ms
            SET LCD_RS OFF
            LCD2_NIBBLEOUT 0X03
            Wait 5 ms
            LCD2_NIBBLEOUT 0X03
            Wait 1 MS
            LCD2_NIBBLEOUT 0X03
            Wait 1 MS
            LCD2_NIBBLEOUT 0X02
            Wait 1 MS
            LCDWriteByte 0x28
            Wait 1 MS
            LCDWriteByte 0x08
            Wait 1 MS
            LCDWriteByte 0x01
            Wait 5 MS
            LCDWriteByte 0x06
            WAIT 1 MS
            LCDWriteByte 0x0C
            WAIT 1 MS
        #ENDIF
    
        #IFDEF LCD_IO 4,8
            DIR LCD_DB4 OUT
            DIR LCD_DB5 OUT
            DIR LCD_DB6 OUT
            DIR LCD_DB7 OUT
            DIR LCD_RS OUT
            #IFNDEF LCD_NO_RW
                DIR LCD_RW OUT
            #ENDIF
            DIR LCD_Enable OUT
            SET LCD_RS OFF
            SET LCD_RW OFF
            SET LCD_Enable OFF
            SET LCD_DB4 OFF
            SET LCD_DB5 OFF
            SET LCD_DB6 OFF
            SET LCD_DB7 OFF
    
            ' wait for more than 15ms after power up
            Wait 35 ms
    
            ' Function set (Interface is 8 bits long.)
            SET LCD_DB4 ON
            SET LCD_DB5 ON
    
            PulseOut LCD_Enable, LCD_Write_Delay
            Wait 6 ms
    
            ' Function set (Interface is 8 bits long.)
            SET LCD_DB4 ON
            SET LCD_DB5 ON
    
            PulseOut LCD_Enable, LCD_Write_Delay
            Wait 6 ms
    
            ' Function set (Interface is 8 bits long.)
            SET LCD_DB4 ON
            SET LCD_DB5 ON
    
            PulseOut LCD_Enable, LCD_Write_Delay
            Wait 6 ms
            #IFDEF LCD_IO 8
                LCDWriteByte(b'00111000') 
            #ENDIF
            #IFDEF LCD_IO 4
                ' set IO mode to 4bit 
                SET LCD_DB4 OFF
                SET LCD_DB5 ON
                PulseOut LCD_Enable, LCD_Write_Delay
    
                SET LCD_RS OFF
                LCDWriteByte(b'00101000') ' function set: display 2 lines 
                wait LCD_Write_Delay
            #ENDIF
            LCDWriteByte(b'00001000') ' 0x08 : display off
            wait LCD_Write_Delay
    
            LCDWriteByte(b'00000001') ' 0x01 : display clear
            wait LCD_Write_Delay
            LCDWriteByte(b'00000110') ' xx06 : set entry mode  (increment by 1, no shift)  
            wait LCD_Write_Delay
    
            LCDWriteByte(b'00001100') ' 0x0C : display on /cursor off control
            wait LCD_Write_Delay
        #endif
    end function
    

    Best regards,
    Edorul

     
  • Rikki
    Rikki
    2013-05-12

    Thankyou for writing this code.  It works well.

    There is a situation when using LCD_NO_RW that still causes the display to corrupt after a watchdog reset or brown-out

    to resolve it is simply a matter of calling your InitLCD subroutine in the code start / initialize area.

    In the contributor section I have submitted the entire lcd.h library with your code added.
    It also includes timing fixes for when using LCD_NO_RW as there seems to be a lot of confusion
    and frustration with this (seperate) issue.
    Also, code has been added to make the Arduino Mega (AVR 2560) work properly with the popular 5 button LCD shield.

     
  • Rikki
    Rikki
    2013-05-12

    Thanks for this code it is very useful.
    When using LCD_NO_RW the LCD will corrupt.
    Simply call the InitLCD subroutine in the code intializing routine to resolve this issue

    For a complete solution with your code included please see the contributors section.
    A new LCD routine with fixes for NO_LCD_RW has been included