Cannot send data to 16x2 LCD via PIC18F45k22 Micro Controller (display showing black boxes)

Thread Starter


Joined Aug 21, 2013

My 16x2 LCD displays black boxes when I hook it up according to the attached wiring diagram.

I am using a PIC18F45k22 development board by Mikroelectronika and using their MikroC pro for PIC software for code development

Attached is also my code.

What am I doing wrong?


Mods Note:
Please upload the image file as .jpg when the image has more color scale or gray scale, the .png file suitable for less colors and the as the vertical line and horizontal line.



Joined Jun 4, 2014
If you adjust the LCD contrast pot can you make the black boxes go away?
If so adjust it so that the boxes are just barely visible and try your code again.


Joined Apr 16, 2011
Circuit diagram shows LCD connected to PORTB, but code is for PORTC

You mention PIC18F45K22, but circuit diagram shows PIC18F2620.


Joined Mar 10, 2018
No, that MCU should be fine. What is the part number for the module ?

If you have a datasheet link post that as well.

Regards, Dana.
What happens when you only power the LCD display? So far with the displays I've worked with the first line is light squares and the second is black squares (or something to that effect depending on color, backlight, etc) until you initialize it.

The displays I've worked with like between 0 - .5 volts for contrast... outside of that range they get hard to read or the other pixels start showing. Your display may be different, but the datasheet will tell you.

Other than those things... Different LCD displays have slightly different initialization routines with different timing requirements depending on what chip is running them. Your problem may be there.


Joined Jul 1, 2009
Are you using a code-library to talk to the display or rolling your own? If you are rolling your own, you need to read the datasheet carefully, and learn how to initialize it. In particularly, you need to tell it whether you are using 4-lines or 8-lines in for communication, and you need to be cognizant of wait periods and command state (whether in command state or data state), and how long to wait after a command is issued before you can issue another.

This is a 44780- it's the most common of this type there is. I wrote a device driver for it for 8-bit MCUs, and the initialization sequence was like this:

o Tell the init routine whether I want to use 4-lines or 8. I choose 4 (fewer pins being used off the MCU, but it halves the transfer rate).
o Init routine goes into command mode
o Init routine waits 10ms, changes to 'Function Set' Mode
o Tells LCD we're just using 4-bit comms (nybbles, not bytes)
o Tells LCD it's using 2 lines; default 5x8pixel font
o Tells LCD that entrymode is to automatically move cursor right
o Enables Display
o Clears LCD
o Upload custom characters into the display (like low-bat symbols)

Read the data sheet, understand what you're doing :)
Last edited:


Joined Jun 26, 2012
Some observations:
You have the oscillator set to high speed crystal but you don’t show any crystal on the schematic. Do you have a clock source?
Your code has TRISC =0 and TRISD=0 commented out. That leaves the pins as inputs. Set the TRIS registers to 0 to make them outputs (as well as using ANSELx to make them digital.).

Thread Starter


Joined Aug 21, 2013
@BobaMosfet ,

I have read the datasheet and struggled to get out the information I need to fix this issue. I am very new to MCU programming and hands on electronics.


I am using a PIC development board so I assumed the crystal on the board is part of the MCU circuit supplying the clock speed right?

Ian Rogers

Joined Dec 12, 2012
Showing black boxes on the top line only is an Init() fault as the screen defaults to single line.
Showing black boxes on both lines is a contrast fault..

As there is nothing wrong with your code and you are using a Mikrolectronica dev board, leaves us with little to go on.

Even if the config was out ( other than the watchdog ) it would still drive the screen..

I expect an internal module is on and is a spanner in your works..

*** Added*** The pic18f45k22 dev board has no screen so you must have added one!!!!
check the connections!