LCD Display - Can't show characters

Discussion in 'Embedded Systems and Microcontrollers' started by BillGeek, Oct 20, 2009.

  1. BillGeek

    Thread Starter New Member

    Oct 14, 2009
    Hi All

    I'm busy following a PDF "tutorial" on LCD displays, but am at a point where I can't seem to get the thing working. The PDF file is called lcd1.pdf and is found at

    Basically, I can clear the display and show a blinking cursor, but that's where it stops. Sending data through to the D0 to D7 pins to show a character "A" doesn't do a thing, even with the 'RS' pin set to high and after setting 'E' to 1 and back to 0.

    I'm using a PIC16F627 with a display labelled "MC1602C-SYR". I have read on the forum that the recommended / suggested LCD display is a Hitachi HD44780A00, however the local supplier does not stock this, so I was forced to "improvise". :) In addition, I'm using GCBasic to compile the HEX for the PIC.

    Another side note: The datasheet for this LCD shows pinouts that match exactly to the ones in the PDF document referred to above.

    I have a couple of my own suspicions as to why I can't get this to work:
    1. In the PDF a reference is made to the pixel size of the display per character. While it only refers to 7 x 5 and 10 x 5, the LCD I have has 8 x 5 pixels. If I set the D2 bit of Function Set to 0, will it automatically use the 8 x 5 pixels? (Default)

    2. When using GCBasic, if I set a pin to 1 and back to 0, is this like pressing a momentary switch? I believe that this is indeed the case, as the display passes through each "stage" successfully. IE: In my code, I wait 1000 ms before clearing the display, 1000 ms before showing the cursor, and then 1000 ms before enabling the second line of the LCD display. In each stage, you are required to "push" a switch connected to "E", and this seems to be happening successfully.

    Just for some additional information, the pinouts of the components on the breadboard is below.

    Pin 4: 4.7k Resistor to Pin 14 (no reset switch)
    Pin 5: Ground
    Pin 6 - 13: D0 to D7 on the display (in numeric order so RB0 = D0, RB1 = D1, etc...)
    Pin 14: +5V Supply
    Pin 17: E pin on LCD display (Pin 6)
    Pin 18: RS pin on LCD Display (Pin 4)

    LCD: (Pins not specified above)
    Pin 1: Ground
    Pin 2: +5V Supply
    Pin 3: (Vee / Contrast) 47K Resistor to Ground
    Pin 5: (RW) Ground

    Is there any apparent reason I can't seem to send data to the LCD in character mode? If neccessary, I can upload the BAS file for GCBasic as well as the ASM file generated when compiling...


    EDIT: Additional Note: I'm using the internal 4MHz oscillator of the 627.
  2. SgtWookie


    Jul 17, 2007
    I can't seem to get the datasheet for your LCD to display.

    Here's a link to it on Farnell:
    I think it's supposed to have a HD44780-compatible controller on it. The datasheet would say what it is.

    Look at the part numbers on the IC's closely with a magnifying glass.

    Meanwhile, it would be helpful if you posted a schematic of how you had things wired up, and also your Basic source code.
  3. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    Are you able to move the flashing cursor? Making a flashing cursor seems to show that you can send commands ok to initialise it and set a flashing cursor.

    Moving the cursor will show it has not hanged and you can still send more bytes to it.

    And to send characters to display you need to set the RS pin HI, so maybe you have a problem with the RS pin connection or the code that drives the RS pin. If that's the case you can send commands (RS = LOW) but you won't be able to send chars.
  4. AlexR

    Well-Known Member

    Jan 16, 2008
    From your pin-out info I assume you are operating the LCD display in 8 bit mode. Is you LCD initialisation also for 8 bit mode or have you used 4 bit mode initialisation by mistake?

    A software listing and copy of your circuit would help, Without those all we can do is make random guesses as to what is wrong.
  5. mik3

    Senior Member

    Feb 4, 2008
    Find the datasheet of the driver IC of the LCD (built in it). Many LCDs have different driver ICs.
  6. BillGeek

    Thread Starter New Member

    Oct 14, 2009
    I did find the following "image", which shows the pinouts and physical dimensions for the display: While it doesn't help for the technical stuff, it at least shows that the pinouts match. (This is the "datasheet" I was referring to in the first post - I know... it's not a datasheet)

    @SgtWookie: I had the same problem with that document and was able to open it with a program called "Cool PDF Reader". Still, in the document there is no mention of the driver IC. I had a look at the IC, but can't see anything printed on it either. It's just a big black blob. Nevertheless, I will check again tonight. There might be something that I missed somewhere else on the PCB of the LCD module.

    I have attached the schematic of the project. I apologize for the crude drawing. As I'm at the office right now, drawing with MS Paint is a bit of a headache...

    I will attach a proper schematic when I get home as well as the source-code.

    @THE_RB: I have not tried moving the cursor. I will give this a shot tonight, as well as check the RS pinout. From what I can understand, it should be just a simple on / off "switch", implying 0 and 1 through the pin on the PIC.

    @AlexR: Yes, I'm running the display in 8-bit. I believe I initialized it properly, as according to the PDF document, the Function Set code D4 should be 1 for 8 bit... (Hope this is right?)

    @mik3: I did get the datasheet, (the one SgtWookie pointed out) but as mentioned, it does not say which driver IC is used. I emailed Everbouquet to find out what driver is used, so I'm waiting for a response from them now. Will post here when I get anything back.
  7. BillGeek

    Thread Starter New Member

    Oct 14, 2009
    I got the code emailed to me. See below. :)

    Will attach the generated assembler as well if required?
    Code ( (Unknown Language)):
    1.     'Select proper device
    2.     #chip PIC16F627, 20
    4.     'Configuration bit for internal oscillator
    5.     #config INTRC_OSC_NOCLKOUT
    7.     'Define pinouts
    8.     #define LCDPins PORTB
    9.     #define RS      PORTA.1
    10.     #define E       PORTA.0
    12.     'Set port directions
    13.     DIR LCDPins OUT
    14.     DIR RS      OUT
    15.     DIR E       OUT
    17.     'Main application loop
    18.     do
    19.         SetupLCD
    20.         SendAChar
    22.         wait 10 ms
    23.     loop
    25.     Sub SetupLCD #NR
    26.         'Display On and Show cursor
    27.         RS = 0
    28.         LCDPins = 0b00001111
    29.         E = 1
    30.         wait 10 ms
    31.         E = 0
    33.         wait 1000 ms
    35.         'Pixel format and two lines
    36.         LCDPins = 0b00111000
    37.         E = 1
    38.         wait 10 ms
    39.         E = 0
    41.         wait 1000 ms
    42.     End Sub
    44.     Sub SendAChar #NR
    45.         RS = 1
    46.         LCDPins = 0b01000001
    47.         E = 1
    48.         wait 10 ms
    49.         E = 0
    51.         wait 1000 ms
    52.     End Sub
    Last edited: Oct 21, 2009
  8. AlexR

    Well-Known Member

    Jan 16, 2008
    Your LCD initialisation procedure could be a fault. Take a look at the HD44780 data sheet at and follow the initialisation as outlined on page 45. Take special note of the time delays and don't try to skip any steps. Also your E pulse is waaaay too long, a 1usec delay or a single nop instruction between raising and lowering the E line is plenty, (in fact all your delays are too long, not that it's the cause of your problem but it will make the LCD very sluggish).
  9. BillGeek

    Thread Starter New Member

    Oct 14, 2009
    Ah, well spotted. :) I didn't notice the missing resistor and will add it to the board.
    I'm using a DC PSU which is grounded, yes. (Though to be honest, I'm not quite sure what you are referring to as pin 1, 5 and the VR from the LCD goes to negative of the supply. I'm sure this is what you mean?) Also, I'm using the standard GCBASIC compile.bat script that compiles the BAS into HEX.

    AlexR, I'm reading through the document you posted right now and will change the delays.
  10. BillGeek

    Thread Starter New Member

    Oct 14, 2009
    Meh, got the thing working somehow. I rebuilt the breadboard and went looking through my code at the same time, so I can't pinpoint exactly what the problem was / is. One thing to note is that I changed "LCDPins" in code to the individual pins. While this might take up more space on the PIC, it makes it a little more clear which bit I'm setting to what value. In addition, I have changed the delays in the code as AlexR suggested. I don't know if this might have been the cause of the problem, but you never know. If I run the circuit now, the character "A" is repeatedly printed on the screen. :)

    So attached is the "new" circuit diagram (drawn with CircuitMaker Student 6) and below is the "new" code if anyone is interested.

    Thanks to everyone for all the help.

    Code ( (Unknown Language)):
    2.     #chip 16F627, 20
    3.     #config INTRC_OSC_NOCLKOUT
    5.     #define E PORTA.0
    6.     #define RS PORTA.1
    8.     #define D0 PORTB.0
    9.     #define D1 PORTB.1
    10.     #define D2 PORTB.2
    11.     #define D3 PORTB.3
    12.     #define D4 PORTB.4
    13.     #define D5 PORTB.5
    14.     #define D6 PORTB.6
    15.     #define D7 PORTB.7
    17.     DIR RS OUT
    18.     DIR E  OUT
    19.     DIR D0 OUT
    20.     DIR D1 OUT
    21.     DIR D2 OUT
    22.     DIR D3 OUT
    23.     DIR D4 OUT
    24.     DIR D5 OUT
    25.     DIR D6 OUT
    26.     DIR D7 OUT
    28.     Dim iAltChar
    30.     'Initial "boot" time - rather safe than sorry...
    31.     wait 1 s
    33.     do
    34.         wait 1 us
    35.         RunLCD
    36.     loop
    38. Sub RunLCD #NR
    39.     'Set to Program mode
    40.     RS = 0
    41.     wait 1 us
    42.     D0 = 1
    43.     D1 = 1
    44.     D2 = 1
    45.     D3 = 1
    46.     D4 = 0
    47.     D5 = 0
    48.     D6 = 0
    49.     D7 = 0
    50.     wait 1 us
    51.     SendRW
    52.     wait 2 ms
    54.     'Enable second line
    55.     D0 = 0
    56.     D1 = 0
    57.     D2 = 0
    58.     D3 = 1
    59.     D4 = 1
    60.     D5 = 1
    61.     D6 = 0
    62.     D7 = 0
    63.     wait 1 us
    64.     SendRW
    65.     wait 2 ms
    67.     'Clear existing text
    68.     D0 = 1
    69.     D1 = 0
    70.     D2 = 0
    71.     D3 = 0
    72.     D4 = 0
    73.     D5 = 0
    74.     D6 = 0
    75.     D7 = 0
    76.     wait 1 us
    77.     SendRW
    78.     wait 2 ms
    80.     'Enter a character
    81.     RS = 1
    82.     wait 1 us
    84.     D0 = 1
    85.     D1 = 0
    86.     D2 = 0
    87.     D3 = 0
    88.     D4 = 0
    89.     D5 = 0
    90.     D6 = 1
    91.     D7 = 0
    92.     wait 1 us
    93.     SendRW
    94.     wait 2 ms
    95. End Sub
    97. Sub SendRW #NR
    98.     E = 1
    99.     wait 1 us
    100.     E = 0
    101. End Sub
  11. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    Why does it need a pullup resistor? I've used LCD for years and never needed a pullup resistor on RS.
  12. BillGeek

    Thread Starter New Member

    Oct 14, 2009
    Just to follow up here: I found an even easier way to do all of this in GCBasic. (Reading the manual really does help... :) )

    Code ( (Unknown Language)):
    2. #chip P16F628A, 20
    3. #config INTRC_OSC_NOCLKOUT
    5. #define LCD_IO 8
    6. #define LCD_RS PORTA.0
    7. #define LCD_RW PORTA.1
    8. #define LCD_Enable PORTA.2
    10. PRINT "What you want"
    As easy as that. Also, I had no problems rebuilding the circuit on the breadboard from memory. I once again omitted the pullup resistor on RS and the contrast on the pot but it still worked first time. Worth noting that it appeared as though I had much "finer" control over the contrast with the vdd on the contrast of the pot, though I couldn't notice any difference with or without the pullup resistor on RS. I suspect that this will have an effect when doing multiple quick extensive changes to the LCD?
  13. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    You don't need the pullup on RS. I checked the Hitachi 44780 LCD driver datasheet, the RS E and R/W pins are input only, they can be driven direct from your PIC digital outputs.

    If you used PORTA.4 that PIC output pin is "open drain" only and needs a pullup resistor, but that is property of that special PIC pin, nothing to do with the LCD or RS.

    I'm sure your original fault was that RS wasn't connected right (as I said before) it matched your symptoms perfectly.

    Some LCDs don't need the contrast pot, but many do. I always include it.