New Haven LCD display no cursor

Discussion in 'The Projects Forum' started by parttimegeek, Apr 27, 2013.

  1. parttimegeek

    Thread Starter New Member

    Apr 27, 2013
    4
    1
    Hello all! I seem to be missing something probably incredibly simple, but can't seem to put my finger on it... Here's what is going on.

    I have a pic 18f4525 running off a 40 mhz oscillator connected to a New Haven NHD-0440WH-ATMI-JT lcd display. It is a 40x4 character display. At the moment when I power it all up the first and third line show solid blocks then they go away during the initialization. By turning the contrast down all four rows appear as darker blocks which from what I gather from other posts and information I've found so far lead me to believe it's being initialized properly and working, I just seem to lose it somewhere along the line.

    Here's the code so far for the lcd:
    Code ( (Unknown Language)):
    1. include "main.inc"
    2.  
    3.     global __lcd_init
    4.  
    5. #define ENABLE1_TRIS TRISA, 0
    6. #define ENABLE1_BIT LATA, 0
    7. #define ENABLE2_TRIS TRISA, 1
    8. #define ENABLE2_BIT LATA, 1
    9. #define RS_TRIS TRISA, 2
    10. #define RS_BIT LATA, 2
    11. #define WR_TRIS TRISA, 3
    12. #define WR_BIT LATA, 3
    13.     code
    14.  
    15. __lcd_init
    16.     movlw 0x07
    17.     movwf ADCON1
    18.     movwf CMCON
    19.     bcf ENABLE1_TRIS
    20.     bcf ENABLE2_TRIS
    21.     bcf RS_TRIS
    22.     bcf WR_TRIS
    23.  
    24.     bcf ENABLE1_BIT
    25.     bcf ENABLE2_BIT
    26.     bcf RS_BIT
    27.     bcf WR_BIT
    28.  
    29. ;initialize LCD
    30.     ;wait 15 msec
    31.     movlw 3
    32.     movwf temp_count+2
    33.     setf temp_count+1
    34.     setf temp_count
    35. .li_wait1
    36.     decfsz temp_count, F
    37.     bra $-1
    38.     setf temp_count
    39.     decfsz temp_count+1, F
    40.     bra .li_wait1
    41.     setf temp_count+1
    42.     decfsz temp_count+2, F
    43.     bra .li_wait1
    44.  
    45.     movlw 0x30
    46.     movwf lcd_byte
    47.     call __lcd_write_command1_no_check
    48.     call __lcd_write_command2_no_check
    49.     ; wait 5 msec
    50.     setf temp_count+1
    51.     setf temp_count
    52. .li_wait2
    53.     decfsz temp_count, F
    54.     bra $-1
    55.     setf temp_count
    56.     decfsz temp_count+1, F
    57.     bra .li_wait2
    58.  
    59.     movlw 0x30
    60.     movwf lcd_byte
    61.     call __lcd_write_command1_no_check
    62.     call __lcd_write_command2_no_check
    63.     ; wait 5 msec
    64.     setf temp_count+1
    65.     setf temp_count
    66. .li_wait3
    67.     decfsz temp_count, F
    68.     bra $-1
    69.     setf temp_count
    70.     decfsz temp_count+1, F
    71.     bra .li_wait3
    72.  
    73.     movlw 0x30
    74.     movwf lcd_byte
    75.     call __lcd_write_command1
    76.     call __lcd_write_command2
    77.     ; wait 5 msec
    78.     setf temp_count+1
    79.     setf temp_count
    80. .li_wait4
    81.     decfsz temp_count, F
    82.     bra $-1
    83.     setf temp_count
    84.     decfsz temp_count+1, F
    85.     bra .li_wait4
    86.  
    87.     movlw 0x38
    88.     movwf lcd_byte
    89.     call __lcd_write_command1
    90.     call __lcd_write_command2
    91.  
    92.     movlw 0x08
    93.     movwf lcd_byte
    94.     call __lcd_write_command1
    95.     call __lcd_write_command2
    96.  
    97.  
    98.     movlw 0x01
    99.     movwf lcd_byte
    100.     call __lcd_write_command1
    101.     call __lcd_write_command2
    102.  
    103.     setf temp_count
    104.     decfsz temp_count, F
    105.     bra $-1
    106.  
    107.  
    108.     movlw 0x06
    109.     movwf lcd_byte
    110.     call __lcd_write_command1
    111.     call __lcd_write_command2
    112.  
    113.  
    114.     movlw 0x0f
    115.     movwf lcd_byte
    116.     call __lcd_write_command1
    117.     call __lcd_write_command2
    118.  
    119.     movlw 'H'
    120.     movwf lcd_byte
    121.     call __lcd_write_data1
    122.  
    123. ;set up PWM for backlight
    124.     bcf LATC, 2
    125.     bcf TRISC, 2
    126.     movlw b'11111111'
    127.     movwf PR2
    128.     movlw b'00000111'
    129.     movwf T2CON
    130.     ;movlw b'00011110'
    131.     movlw b'00111111'
    132.     movwf CCPR1L
    133.     ;movlw b'00101100'
    134.     movlw b'00111100'
    135.     movwf CCP1CON
    136.     return
    137.  
    138. __lcd_write_command1
    139.     call __lcd_check_busy1
    140.  
    141. __lcd_write_command1_no_check
    142.     bsf ENABLE1_BIT
    143.     nop
    144.     nop
    145.     movff lcd_byte, LATD
    146.     nop
    147.     nop
    148.     bcf ENABLE1_BIT
    149.     nop
    150.     nop
    151.     return
    152.    
    153. __lcd_check_busy1
    154.     setf TRISD
    155.     bsf WR_BIT
    156.     bsf ENABLE1_BIT
    157.     nop
    158.     nop
    159.     nop
    160.     nop
    161.     movff PORTD, WREG
    162.     bcf ENABLE1_BIT
    163.     nop
    164.     nop
    165.     bcf WR_BIT
    166.     clrf TRISD
    167.     btfsc WREG, 7
    168.     bra __lcd_check_busy1
    169.     return
    170.  
    171. __lcd_write_command2
    172.     call __lcd_check_busy2
    173.  
    174. __lcd_write_command2_no_check
    175.     bsf ENABLE2_BIT
    176.     nop
    177.     nop
    178.     movff lcd_byte, LATD
    179.     nop
    180.     nop
    181.     bcf ENABLE2_BIT
    182.     nop
    183.     nop
    184.     return
    185.    
    186. __lcd_check_busy2
    187.     setf TRISD
    188.     bsf WR_BIT
    189.     bsf ENABLE2_BIT
    190.     nop
    191.     nop
    192.     nop
    193.     nop
    194.     movff PORTD, WREG
    195.     bcf ENABLE2_BIT
    196.     nop
    197.     nop
    198.     bcf WR_BIT
    199.     clrf TRISD
    200.     btfsc WREG, 7
    201.     bra __lcd_check_busy2
    202.     return
    203.  
    204. __lcd_write_data1
    205.     call __lcd_check_busy1
    206.  
    207.     bsf RS_BIT
    208.     bsf ENABLE1_BIT
    209.     nop
    210.     nop
    211.     movff lcd_byte, LATD
    212.     nop
    213.     nop
    214.     bcf ENABLE1_BIT
    215.     bcf RS_BIT
    216.     return
    217.  
    218. __lcd_write_data2
    219.     call __lcd_check_busy2
    220.  
    221.     bsf RS_BIT
    222.     bsf ENABLE2_BIT
    223.     nop
    224.     nop
    225.     movff lcd_byte, LATD
    226.     nop
    227.     nop
    228.     bcf ENABLE2_BIT
    229.     bcf RS_BIT
    230.     return
    231.     end
    232.  
    I am using 8 bits at the moment and from what I gather when all is well I should have two cursors: one at row 1 and one at row 3. I'm also attempting to put an 'H' at the top left corner. I haven't really figured out the delay times other than they're more than enough during the initialization (didn't account for the extra cycles used to jump around and decrement). All the other problems I could find online seem to be related to the contrast setting which I have tried to adjust to no avail. I have seen where many people set the data lines before setting the enable pins and wonder if it's possible that maybe I just need to do that instead even though everything seems to be working up to a point. According to the timing characteristics in the datasheet my programming should be acceptable so I haven't tried any other approach so far. I've had the same code working with an optrex display before, but couldn't find it on digikey when I ordered this one... apparently they are part of kyocera now which I just noticed earlier so I ordered this one instead.

    Another question I have is if I hook Vo (contrast) directly to 0v will it work like the optrex one I had did where I could adjust the backlight to make things brighter or darker, or do I need the roughly .5v to Vo to make characters appear?

    The datasheet for the display is here http://www.newhavendisplay.com/specs/NHD-0440WH-ATMI-JT.pdf

    I know lcd programming is covered all over the internet and apologize for any redundancy, but I could not find much specific to the New Haven displays and was just wondering if there's a little secret to them. Thanks in advance!!

    I'm fairly new to electronics, but have been tinkering for a few years now and have had some pretty good luck with other projects... just not this one at the moment.
     
    Last edited: Apr 27, 2013
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,346
    1,028
    One thing that jumps out is $-1 should be $-2 on an 18F. The P C counts by 2 on these part s.
     
  3. parttimegeek

    Thread Starter New Member

    Apr 27, 2013
    4
    1
    Thanks JonhnInTX... I have always wondered about that, but everything I've ever done with $-1 has worked so far. I just thought maybe the compiler was either making up for my mistake or I was reading things wrong and not quite understanding. Will give it a try.
     
Loading...