Character LCD initialization

Discussion in 'Embedded Systems and Microcontrollers' started by Pencil, Jun 23, 2012.

  1. Pencil

    Thread Starter Active Member

    Dec 8, 2009
    271
    38
    I have been trying to implement a software initialization
    on a character LCD using a PIC 16f690.

    When I run the code as is the display will not display anything.
    If I jump over the initialization sequence I have written and go
    straight to writing instructions it seems to work fine. (automatic
    initialization works fine with the power supply/test circuit at present).

    A couple of notes about the display.
    OPTREX DMC20261NY-LY
    Hitachi 44780 chip
    Although unit is previously unused, it may be an older model.

    Any ideas? I have changed the delays longer and shorter in
    an attempt to see if it was a timing issue.

    Datasheet attached.


    Code ( (Unknown Language)):
    1.  
    2. ;Internal Oscillator 4MHz (1Mhz instruction)
    3.  
    4. ;PIN CONNECTIONS:
    5. ;______________
    6. ;PIC            LCD
    7. ;______________
    8. ;RB4            RS
    9. ;RB5            R/W
    10. ;RB6            ENABLE
    11. ;RC0-RC7     DB0-DB7
    12.  
    13. ;****BEGIN INITIALIZE LCD****
    14. ;DWELL 100ms (Wait for 15ms minimum after Vcc=4.5V)
    15.         MOVLW    0xDF  ;223
    16.         MOVWF    DWELLA
    17.         MOVLW    0x82  ;130
    18.         MOVWF    DWELLB
    19.         DECFSZ    DWELLA,F
    20.         GOTO    $-1
    21.         DECFSZ    DWELLB,F
    22.         GOTO    $-3
    23.         NOP
    24.         NOP
    25. ;FUNCTION SET COMMAND (8-BIT INTERFACE)*1*
    26.         MOVLW  0x30        ;0011 0000
    27.         MOVWF  PORTC     ;0011 0000 RC5(DB5)=1 RC4(DB4)=1
    28.         MOVLW  0x00        ;0000 0000    
    29.         MOVWF  PORTB     ;0000 0000 RB4(RS)=0 RB5(R/W)=0 RB6(E)=0
    30.         NOP                     ;WAIT MINIMUM .14uS
    31.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    32.         NOP                     ;WAIT 1us
    33.         NOP                     ;WAIT 1us
    34.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    35.         CALL   DWELL5ms
    36. ;FUNCTION SET COMMAND (8-BIT INTERFACE)*2*
    37.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    38.         NOP                     ;WAIT 1us
    39.         NOP                     ;WAIT 1us
    40.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    41.         CALL   DWELL5ms
    42.  ;FUNCTION SET COMMAND (8-BIT INTERFACE)*3*
    43.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    44.         NOP                     ;WAIT 1us
    45.         NOP                     ;WAIT 1us
    46.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    47.         CALL   DWELL5ms
    48.  ;FUNCTION SET COMMAND (8-BIT INTERFACE, LINES 2, FONT 5X7)
    49.         MOVLW  0x38        ;0011 1000
    50.         MOVWF  PORTC     ;0011 1000 RC5=1 RC4=1 RC3=1 RC2=0
    51.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    52.         NOP                     ;WAIT 1us
    53.         NOP                     ;WAIT 1us
    54.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    55.         CALL   DWELL5ms
    56.  ;DISPLAY OFF
    57.         MOVLW  0x08        ;0000 1000
    58.         MOVWF  PORTC     ;0000 1000 RC3=1 (DISPLAY OFF)
    59.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    60.         NOP                     ;WAIT 1us
    61.         NOP                     ;WAIT 1us
    62.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    63.         CALL   DWELL5ms
    64. ;****END INITIALIZE LCD****
    65. ;***************************
    66. ;NO INITIALIZATION JUMP TO HERE
    67. ;***************************
    68.  ;CLEAR DISPLAY
    69.         MOVLW  0x01        ;0000 0001
    70.         MOVWF  PORTC     ;0000 0001 RC0=1
    71.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    72.         NOP                     ;WAIT 1us
    73.         NOP                     ;WAIT 1us
    74.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    75.         CALL   DWELL5ms
    76.  ;SET ENTRY MODE (INCREMENT, NO DISPLAY SHIFT)
    77.         MOVLW  0x06        ;0000 0110
    78.         MOVWF  PORTC     ;0000 0110 RC2=1 RC1=1 RC0=0
    79.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    80.         NOP                     ;WAIT 1us
    81.         NOP                     ;WAIT 1us
    82.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    83.         CALL   DWELL5ms
    84.  ;DISPLAY ON OFF CONTROL (DISPLAY=ON, CURSOR=ON, BLINK=ON)
    85.         MOVLW  0x0E        ;0000 1110
    86.         MOVWF  PORTC     ;0000 1110 RC3=1 RC1=2 RC1=1 RC0=0
    87.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    88.         NOP                     ;WAIT 1us
    89.         NOP                     ;WAIT 1us
    90.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    91.         CALL   DWELL5ms
    92.  ;CLEAR DISPLAY AND CURSOR HOME
    93.         MOVLW  0x01        ;0000 0001
    94.         MOVWF  PORTC     ;0000 0001 RC0=1
    95.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    96.         NOP                     ;WAIT 1us
    97.         NOP                     ;WAIT 1us
    98.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    99.         CALL   DWELL5ms    
    100. ;****END INITIALIZE LCD****
    101. ;TEST WRITE CHARACTER
    102. ;CHARACTER 1
    103. ;INSTRUCTION SET DD RAM ADDRESS
    104.         MOVLW  0x8A        ;1000 1010 ADDRESS 0Ah
    105.         MOVWF  PORTC     ;1000 1010 ADDRESS 0Ah
    106.         MOVLW  0x00        ;0000 0000    
    107.         MOVWF  PORTB     ;0000 0000 RB4(RS)=0 RB5(R/W)=0 RB6(E)=0
    108.         NOP                     ;WAIT MINIMUM .14uS
    109.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)  
    110.         NOP                     ;WAIT 1us
    111.         NOP                     ;WAIT 1us
    112.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    113.         CALL   DWELL5ms
    114. ;WRITE DATA
    115.         MOVLW  0x41        ;0100 0001
    116.         MOVWF  PORTC     ;0100 0001 CHARACTER=A
    117.         MOVLW  0x10        ;0001 0000    
    118.         MOVWF  PORTB     ;0001 0000 RB4(RS)=1 RB5(R/W)=0 RB6(E)=0
    119.         NOP                     ;WAIT MINIMUM .14uS
    120.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    121.         NOP                     ;WAIT 1us
    122.         NOP                     ;WAIT 1us
    123.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    124.         CALL   DWELL5ms
    125. HERE
    126.         NOP
    127.         GOTO   HERE
    128.  
    129. DWELL5ms
    130. ;DWELL 5ms
    131.         MOVLW    0x7E  ;126
    132.         MOVWF    DWELLA
    133.         MOVLW    0x07  ;7
    134.         MOVWF    DWELLB
    135.         DECFSZ    DWELLA,F
    136.         GOTO    $-1
    137.         DECFSZ    DWELLB,F
    138.         GOTO    $-3
    139.         NOP
    140.         NOP
    141.         RETURN
    142.  
     
    Last edited: Jun 24, 2012
  2. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
  3. Pencil

    Thread Starter Active Member

    Dec 8, 2009
    271
    38
    Thanks for responding takao21203.

    I have been searching feverishly to solve this problem.
    I stumbled accross your site previously and found it to
    be quite informative.

    I am sure I must be making a basic mistake, either in the
    coding or in the interpretation of the flow chart.
     
  4. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Well I can read assembler I used it for years.

    There are some things missing in your source, such as configuration,
    and information about clock frequency.

    It is not clear what is the main code, where is the entry point etc.

    And sometimes you comment 1mS, sometimes 1uS for the NOP.

    What version of MPLAB do you use or something else? MPASM only?

    It would also be helpful if you (in commented lines) write the I/O assigment, which LCD pins are connected to which PIC I/O pins.
    It's written in line comments but I mean all together in one block at the top.

    After power up it's required to wait 40mS or something like this!
    And correct LCD reset is not guaranteed only if you power it directly via PIC I/O. If the reset was not correct, the flowchart from the website I linked must be followed.
     
  5. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Code ( (Unknown Language)):
    1.  
    2. ;DWELL 100ms (Wait for 15ms minimum after Vcc=4.5V)
    3.         MOVLW    0xDF  ;223
    4.         MOVWF    DWELLA
    5.         MOVLW    0x82  ;130
    6.         MOVWF    DWELLB
    7.         DECFSZ    DWELLA,F
    8.         GOTO    $-1
    9.         DECFSZ    DWELLB,F
    10.         GOTO    $-3
    11.         NOP
    12.         NOP
    13.  
    also is slightly incorrect, the inner loop pointer must be reloaded!

    Code ( (Unknown Language)):
    1.  
    2.  movlw c_loop_outer_count
    3.  movwf DWELLA
    4. l_loop_outer:
    5.  movlw c_loop_inner_count
    6.  movwf DWELLB
    7.  
    8. l_loop_inner:
    9.  decfsz DWELLB,f
    10.  goto l_loop_inner
    11.  decfsz DWELLA,f
    12.  goto l_loop_outer
    13.  
     
  6. Pencil

    Thread Starter Active Member

    Dec 8, 2009
    271
    38
    Added and fixed comments. See original code.

    MPLAB v8.60
    That is the 100ms delay at the beginning.

    As stated before, the automatic reset will work if I skip down to the
    comment ";NO INITIALIZATION JUMP TO HERE" after the 100ms delay.

    If I skip to comment mentioned above after the 100ms delay routine
    the LCD will display the character "A" as I have programmed for a test.

    If I run the entire program, without skipping the problematic code, LCD will display nothing.

    To skip the part of the program that is problematic I insert a "CALL"
    instruction after the 100ms delay and a label in the place of ";NO INITIALIZATION JUMP TO HERE".

    The simulation shows the delay to be 100.005ms.
     
    Last edited: Jun 24, 2012
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Yes I was thinking that you insert a goto.

    All I can say is that the Hitachi LCD controllers are not intelligent, they have exact requirement at which point of time they can accept certain commands.

    I founds these flowcharts helpful, and following them 1:1 resulted in working code.

    Assembler really has the disadvantage that you have to change many lines.

    To be 100% sure the LCD should only become powered up after values on PORTB have been established (for instance E=0). But I don't do that myself, and no problems from that.

    If I read through your code, you don't follow this sequence 100%, at first yes, but then at some point, different.
    http://elm-chan.org/docs/lcd/hd44780_e.html

    Here is some old assembler code, where I use character LCD:

    Code ( (Unknown Language)):
    1.  
    2. l_lcd_init: ; initialize LCD display
    3.  btfss v_status,c_status_lcd_cmd_st
    4.  goto l_lcd_init_next ; get next command from table
    5.  
    6.  movf v_lcd_cmd_ints,w
    7.  cpfsgt v_serial_ints ; refresh interrupts elapsed?
    8.  return
    9.  
    10.  bcf v_status,c_status_lcd_cmd_st ; yes
    11.  movlw d'4' ; next list element
    12.  addwf v_lcd_offset,f
    13.  return
    14.  
    15. l_lcd_init_next:
    16.  bsf v_status,c_status_lcd_cmd_st ; enable refresh interrupt counter
    17.  clrf v_serial_ints
    18.  movlw high(l_lcd_init_data) ; load data table address
    19.  movwf TBLPTRH,ACCESS
    20.  movlw low(l_lcd_init_data)
    21.  movwf TBLPTRL,ACCESS
    22.  movf v_lcd_offset,w ; add offset
    23.  addwf TBLPTRL,f,ACCESS
    24.  btfsc STATUS,C,ACCESS
    25.  incf TBLPTRH,f,ACCESS
    26.  
    27.  tblrd *+ ; read LCD data
    28.  movff TABLAT,v_m_ioxp0
    29.  
    30.  movlw 0xff ; end of table?
    31.  cpfseq TABLAT,ACCESS
    32.  goto l_lcd_init_skip0
    33.  bcf v_status,c_status_lcd_more ; no more list elements
    34.  return
    35.  
    36. l_lcd_init_skip0: ; get refresh interrupt counts
    37.  tblrd *+ ; how many refresh interrupts are needed for delay?
    38.  movff TABLAT,v_lcd_cmd_ints
    39.  
    40.  tblrd *+ ; command or ASCII data?
    41.  movff TABLAT,v_lcd_cmd ; this variable is used in refresh routine
    42.  bcf v_m_ioxp1,d'0' ; at first, delay is needed, no command
    43.  btfsc v_lcd_cmd,d'1' ; this is a special case which also is included
    44.  bsf v_m_ioxp1,d'0' ; normally set command/data bit here
    45.  
    46.  return
    47.  
    48. l_lcd_init_data:
    49.  dw 0x3000
    50.  dw 0x0000 ; wait for 30 milliseconds (at least)
    51.  dw 0x0138
    52.  dw 0x0001 ; 5x7 font size, 2 lines
    53.  dw 0x010f
    54.  dw 0x0001 ; display on, no cursor, no blink
    55.  dw 0x0301
    56.  dw 0x0001 ; clear the display
    57.  dw 0x0106
    58.  dw 0x0001 ; shift off, increment
    59.  
    60.  dw 0x0100+'P'
    61.  dw 0x0003 ; ASCII data (test)
    62.  dw 0x0100+'I'
    63.  dw 0x0003
    64.  dw 0x0100+'C'
    65.  dw 0x0003
    66.  dw 0x0100+' '
    67.  dw 0x0003
    68.  dw 0x0100+'1'
    69.  dw 0x0003
    70.  dw 0x0100+'3'
    71.  dw 0x0003
    72.  dw 0x0100+'k'
    73.  dw 0x0003
    74.  dw 0x0100+'5'
    75.  dw 0x0003
    76.  dw 0x0100+'0'
    77.  dw 0x0003
    78.  
    79.  dw 0xffff
    80.  dw 0x0000 ; end of lcd initialization sequence
    81.  
    it's incomplete but maybe you can follow the general idea to read the code from a table, so it's easier to change.

    Particulary in your code, you seem to switch off the display, then immediately switch on again, then you set increment, then you set blink, and then you clear the display!

    on the website:

    3x enable with 0x30
    then function set,
    then display off,
    then clear display,
    then entry mode set,
    then display on.

    http://web.alfredstate.edu/weimandn/lcd/lcd_initialization/lcd_initialization_index.html

    My suggestion is to write some assembler code to read "LCD commands" from a table, so you only have to modify this table, not the program code anymore!
     
  8. Pencil

    Thread Starter Active Member

    Dec 8, 2009
    271
    38
    The code after comment ";DISPLAY ON" is actually writing the instruction
    for "Clear Display" (0x01). I wrote the comment because on the sheet
    that I have, (the original paper that came with the display) that line
    on the flow chart had that comment. This was a source of confusion
    for me also until I figured it was a typo on the sheet. I corrected the
    comment in the original post.

    My (intended) sequence is as follows:
    Delay 100ms
    Function set (0x30)
    Delay 5ms
    Function set (0x30)
    Delay 5ms
    Function set (0x30)
    Delay 5ms
    Function set (0x38)
    Delay 5ms
    Display off (0x08)
    Delay 5ms
    Clear display (0x01)
    Delay 5ms
    Entry mode (0x06)
    Delay 5ms
    Cursor on, blink off (0x0E)
    Delay 5ms
    Clear display (0x01)
    Delay 5ms
    Start writing to display

    I am beginning to think that if the display performs
    the automatic initialization correctly it cannot be
    commanded to "re-initialize". Am I correct?
     
  9. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    This should not be the case.

    Have you tried to power the LCD via PIC I/O?

    And why you want to clear the display two times now?

    The LCD glass can be powered directly, only the chip powered by PIC I/O.
     
    Pencil likes this.
  10. Pencil

    Thread Starter Active Member

    Dec 8, 2009
    271
    38
    I finally figured it out.

    Since it is a 2-line display the three (3) function
    set commands at the beginning must be set for
    a 2 line display, in addition to the fourth (4th) function
    set command.

    The corrected sequence is as follows:
    Delay 100ms
    Function set (0x38)
    Delay 5ms
    Function set (0x38)
    Delay 5ms
    Function set (0x38)
    Delay 5ms
    Function set (0x38)
    Delay 5ms
    Display off (0x08)
    Delay 5ms
    Clear display (0x01)
    Delay 5ms
    Entry mode (0x06)
    Delay 5ms
    Cursor on, blink on(0x0F)
    Delay 5ms
    Clear display (0x01)
    Delay 5ms
    Start writing to display

    Corrected code snippet below:
    Code ( (Unknown Language)):
    1.  
    2. ;PIC 16f690
    3. ;Internal Oscillator 4MHz (1Mhz instruction)
    4. ;DMC20261NY-LY 20x2 Character display
    5.  
    6. ;PIN CONNECTIONS:
    7. ;__________________
    8. ;PIC            LCD
    9. ;__________________
    10. ;RB4            RS
    11. ;RB5            R/W
    12. ;RB6            ENABLE
    13. ;RC0-RC7       DB0-DB7
    14.  
    15. ;****BEGIN INITIALIZE LCD****
    16. ;DWELL 100ms (Wait for 15ms minimum after Vcc=4.5V)
    17.         MOVLW    0xDF  ;223
    18.         MOVWF    DWELLA
    19.         MOVLW    0x82  ;130
    20.         MOVWF    DWELLB
    21.         DECFSZ    DWELLA,F
    22.         GOTO    $-1
    23.         DECFSZ    DWELLB,F
    24.         GOTO    $-3
    25.         NOP
    26.         NOP
    27.  
    28. ;FUNCTION SET COMMAND (8-BIT INTERFACE)*1*
    29.         MOVLW  0x38        ;0011 1000 *LOOK*
    30.         MOVWF  PORTC     ;0011 1000 RC5(DB5)=1 RC4(DB4)=1 RC3(DB3)=1
    31.         MOVLW  0x00        ;0000 0000    
    32.         MOVWF  PORTB     ;0000 0000 RB4(RS)=0 RB5(R/W)=0 RB6(E)=0
    33.         NOP                    ;WAIT MINIMUM .14uS
    34.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    35.         NOP                     ;WAIT 1us
    36.         NOP                    ;WAIT 1us
    37.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    38.         CALL   DWELL5ms
    39.  
    40. ;FUNCTION SET COMMAND (8-BIT INTERFACE)*2*
    41.         BSF    PORTB,6   ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    42.         NOP                  ;WAIT 1us
    43.         NOP                  ;WAIT 1us
    44.         BCF    PORTB,6   ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    45.         CALL   DWELL5ms
    46.  
    47.  ;FUNCTION SET COMMAND (8-BIT INTERFACE)*3*
    48.         BSF    PORTB,6   ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    49.         NOP                  ;WAIT 1us
    50.         NOP                  ;WAIT 1us
    51.         BCF    PORTB,6   ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    52.         CALL   DWELL5ms
    53.  
    54.  ;FUNCTION SET COMMAND (8-BIT INTERFACE, LINES 2, FONT 5X7)
    55.         MOVLW  0x38        ;0011 1000 0x38 *LOOK*
    56.         MOVWF  PORTC     ;0011 1000 RC5=1 RC4=1 RC3=1 RC2=0
    57.         BSF    PORTB,6     ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    58.         NOP                    ;WAIT 1ms
    59.         NOP                    ;WAIT 1ms
    60.         BCF    PORTB,6     ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    61.         CALL   DWELL5ms
    62.  
    63.  ;DISPLAY OFF
    64.         MOVLW  0x08        ;0000 1000
    65.         MOVWF  PORTC     ;0000 1000 RC3=1 (DISPLAY OFF)
    66.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    67.         NOP                     ;WAIT 1us
    68.         NOP                     ;WAIT 1us
    69.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    70.         CALL   DWELL5ms
    71.  
    72.  ;CLEAR DISPLAY
    73.         MOVLW  0x01        ;0000 0001
    74.         MOVWF  PORTC     ;0000 0001 RC0=1
    75.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    76.         NOP                    ;WAIT 1us
    77.         NOP                    ;WAIT 1us
    78.         BCF    PORTB,6     ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    79.         CALL   DWELL5ms
    80.  
    81.  ;SET ENTRY MODE (INCREMENT, NO DISPLAY SHIFT)
    82.         MOVLW  0x06        ;0000 0110
    83.         MOVWF  PORTC     ;0000 0110 RC2=1 RC1=1 RC0=0
    84.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    85.         NOP                     ;WAIT 1us
    86.         NOP                     ;WAIT 1us
    87.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    88.         CALL   DWELL5ms
    89.  
    90.  ;DISPLAY ON OFF CONTROL (DISPLAY=ON, CURSOR=ON, BLINK=ON)
    91.         MOVLW  0x0F        ;0000 1111
    92.         MOVWF  PORTC     ;0000 1111 RC3=1 RC1=2 RC1=1 RC0=0
    93.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    94.         NOP                     ;WAIT 1us
    95.         NOP                     ;WAIT 1us
    96.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    97.         CALL   DWELL5ms
    98.  
    99.  ;CLEAR DISPLAY AND CURSOR HOME
    100.         MOVLW  0x01        ;0000 0001
    101.         MOVWF  PORTC     ;0000 0001 RC0=1
    102.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    103.         NOP                     ;WAIT 1us
    104.         NOP                     ;WAIT 1us
    105.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    106.         CALL   DWELL5ms    
    107. ;****END INITIALIZE LCD****
    108.  
    109. ;TEST WRITE CHARACTER
    110.  
    111. ;TEST CHARACTER R
    112.  
    113. ;INSTRUCTION SET DD RAM ADDRESS
    114.         MOVLW  0x8A      ;1000 1010 ADDRESS 0Ah
    115.         MOVWF  PORTC     ;1000 1010 ADDRESS 0Ah
    116.         MOVLW  0x00        ;0000 0000    
    117.         MOVWF  PORTB     ;0000 0000 RB4(RS)=0 RB5(R/W)=0 RB6(E)=0
    118.         NOP                    ;WAIT MINIMUM .14uS
    119.         BSF    PORTB,6     ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)  
    120.         NOP                    ;WAIT 1us
    121.         NOP                    ;WAIT 1us
    122.         BCF    PORTB,6     ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    123.         CALL   DWELL5ms
    124.  
    125. ;WRITE DATA
    126.         MOVLW  0x52        ;0101 0010
    127.         MOVWF  PORTC     ;0101 0001 CHARACTER=R
    128.         MOVLW  0x10        ;0001 0000    
    129.         MOVWF  PORTB     ;0001 0000 RB4(RS)=1 RB5(R/W)=0 RB6(E)=0
    130.         NOP                    ;WAIT MINIMUM .14uS
    131.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    132.         NOP                    ;WAIT 1us
    133.         NOP                    ;WAIT 1us
    134.         BCF    PORTB,6     ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    135.         CALL   DWELL5ms
    136.  
    137. ;TEST CHARACTER L
    138.  
    139. ;INSTRUCTION SET DD RAM ADDRESS
    140.         MOVLW  0xCA        ;1100 1010 ADDRESS 4Ah
    141.         MOVWF  PORTC     ;1100 1010 ADDRESS 4Ah
    142.         MOVLW  0x00        ;0000 0000    
    143.         MOVWF  PORTB     ;0000 0000 RB4(RS)=0 RB5(R/W)=0 RB6(E)=0
    144.         NOP                     ;WAIT MINIMUM .14uS
    145.         BSF    PORTB,6      ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)  
    146.         NOP                     ;WAIT 1us
    147.         NOP                     ;WAIT 1us
    148.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    149.         CALL   DWELL5ms
    150.  
    151. ;WRITE DATA
    152.         MOVLW  0x4C        ;0100 1100
    153.         MOVWF  PORTC     ;0100 1100 CHARACTER=L
    154.         MOVLW  0x10        ;0001 0000    
    155.         MOVWF  PORTB      ;0001 0000 RB4(RS)=1 RB5(R/W)=0 RB6(E)=0
    156.         NOP                      ;WAIT MINIMUM .14uS
    157.         BSF    PORTB,6       ;x1xx xxxx RB6(E)=1 (ENABLE HIGH)
    158.         NOP                     ;WAIT 1us
    159.         NOP                     ;WAIT 1us
    160.         BCF    PORTB,6      ;x0xx xxxx RB6(E)=0 (ENABLE LOW)
    161.         CALL   DWELL5ms
    162.  
    163. DWELL5ms
    164.        ;DWELL 5ms
    165.         MOVLW    0x7E  ;126
    166.         MOVWF    DWELLA
    167.         MOVLW    0x07  ;7
    168.         MOVWF    DWELLB
    169.         DECFSZ    DWELLA,F
    170.         GOTO    $-1
    171.         DECFSZ    DWELLB,F
    172.         GOTO    $-3
    173.         NOP
    174.         NOP
    175.         RETURN
    176.  
    #%@&*! I lined up the comments nice and neat and look how they posted.

    Thanks for all the help.:)
     
    Last edited: Jun 24, 2012
  11. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Interesting. According to the flowchart these bits are irrelevant for the reset. And that's also my experience.

    So if you keep it like it is, and only modify the first three commands to 0x30, it won't work?

    Interesting because if this is the case, indeed there might be a chip revision which always requires the correct bits for 2 lines.
     
  12. Pencil

    Thread Starter Active Member

    Dec 8, 2009
    271
    38
    I know it is confusing. I cannot find a single reference to changing
    any of the lower 4 bits, this includes the paper that was stuck in
    with the display. (this display may be 10+ years old). I read the date
    before I mounted it in my test fixture, but I cannot see it now.
    It may have been 1993? Is this possible? The number on the chip
    is HD44780A00 1B3.

    My process of elimination included initializing as a 1-line and it worked.
    Then I changed the first three commands from 0x30 to 0x38 and suddenly
    it worked. Added the second test character and there it appeared.

    As a note, if i tried to write a character to the second line when initialized
    as a 1-line display the cursor disappeared. I never tried writing any
    more instructions after the cursor disappeared so I don't know what
    would happen.

    0x30 3 times and 0x38 1 time = does not work

    0x30 4 times= works as 1-line

    0x38 4 times= works as 2-line

    Results are based on limited testing of writing a single character
    in the middle of the line on each line.
     
    Last edited: Jun 24, 2012
Loading...