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

JohnInTX

Joined Jun 26, 2012
4,787
@BobaMosfet
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?
Sorry if I missed something above and this is redundant - dismiss as necessary.

Are you using the Ready-Pic-Dip40 board? If so, yes the crystal is attached. Others such as Easy PIC need some hardware configuration.

The code you posed is incorrect:
C:
sbit LCD_RS at LATC4_bit;
sbit LCD_EN at LATC5_bit;
sbit LCD_D0 at LATD0_bit;
sbit LCD_D4 at LATC0_bit;
sbit LCD_D5 at LATC1_bit;
sbit LCD_D6 at LATC2_bit;
sbit LCD_D7 at LATC3_bit;


sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;


void main() {

     //TRISC = 0;     //CONFIGURE PORTC AS OUPUT
     //TRISD = 0;    //CONFIGURE PORTD AS OUTPUT
     ANSELC = 0; // configure PORTC pins as digital
     //ANSELD = 0;
     Lcd_Init(); // initialize LCD
  
     Lcd_Cmd(_LCD_CLEAR);
     Lcd_Cmd(_LCD_CURSOR_OFF);
     //Lcd_Cmd(_LCD_BLINK_CURSOR_ON); // blink cursor

       Lcd_Out(1, 1, "Hello World");
       Lcd_Out(2, 1, "LCD Display");
       Lcd_Chr_CP('@');
  
     while (1)
     {

     }
}
Uncomment lines 20 and 21. Your ports are currently input, not output.
Uncomment line 23 to make port D a digital port.
I know you're not using PORTD but it's a good practice not to leave uncommitted pins as analog inputs. While you're at it, be sure to initialize all the other ports for the same reason. Set unused ones to output 0.

If that's not it, post your current code and actual circuit.

Good luck!
 
Last edited:

Thread Starter

metric_electric

Joined Aug 21, 2013
33
All,

The tool set is working as I have flashed LCDs through all Ports.
I do not have an oscilloscope
I am using the Ready for PIC Dip 40 with socket PIC18F45k22 developement board.
I grounded the unused pins D0 - D3 of the LCD
To get it to finally display, I re-checked my wiring and it started working. It wasn't the LCD because I swapped it out with spares I have and still get the same results.
Right now I have gotten it to display on the LCD but:

The output is not displaying all characters. Its missing some characters (it displays "Hell wrd") instead of displaying the full "hello world". Each time I reset it using the on board reset button, it changes to another set of uncomplete characters: "Hlo ol"......"Hll rld"......"Hll ol".
 

MrChips

Joined Oct 2, 2009
34,889
You might want to look at the timing delays with respect to how the E signal is toggled.

Do you have a 0.1μF capacitor between VDD and VSS at the LCD?
 

danadak

Joined Mar 10, 2018
4,057
You can start with a PC sound card based scope for free. Will give you basically
audio range scope, spectrum analyzer, and function generator all using your
PC sound card. It may not be fast enough to handle the character LCD interface
however.


https://www.zeitnitz.eu/scope_en


http://www.zelscope.com/


http://www.ledametrix.com/oscope/


http://www.virtins.com/downloads.shtml


But first build a simple circuit to protect sound card inputs so you do not
ruin from transients, overvoltage. Google "protect sound card input".


For example http://makezine.com/projects/sound-card-oscilloscope/



A real inexpensive Logic Analyzer/pc combo can be had with this -

https://www.ebay.com/itm/USB-Logic-...h=item33f2ef28ec:g:NNoAAOSwjXVaoiyH:rk:4:pf:0

There are many vendors of this on ebay.

You download and install Saleae software to run it. https://www.saleae.com/downloads/


Regards, Dana.
 
Last edited:

Thread Starter

metric_electric

Joined Aug 21, 2013
33
@Mr Chips,
I placed a 0.1 mircoF capacitor between Vdd and Vss as you said. I still get the same error.


@dana,
Thanks for your reply. I am new to MCU programming. What should I be looking for when I pass the signals through an analyzer?
I intend to buy an oscilloscope.
 

danadak

Joined Mar 10, 2018
4,057
When using a scope you look for signal integrity, that logic levels are
met, and set/hold times are also met. Newer scopes have some logic
analyzer capabilities, like buss decode for SPI, I2C, One Wire....

A logic analyzer allows you to see sent/receive data with buss decode.
Allows for masking, to look for specific data, and or specific control/
code/data sequences. Usually have much more memory than scope
implementation. To facilitate deep record observation in long data
sequences. Some with pattern generators to provide stimulus data.

Last few years scopes and analyzers are starting to merge their capabilities
into one instrument. Still limit but happening never-the-less.

Regards, Dana.
 

BobaMosfet

Joined Jul 1, 2009
2,211
Fundamentally you're applying power to the display, but not much else. Now's the time to dig deep, or provide actual schematics and pics so we can help.
 

spinnaker

Joined Oct 29, 2009
7,830
All,

sorry for the silence. I ordered an oscilloscope and sti
ll waiting for it to be delivered
Why do you think you need a scope? A multi-meter or logic probe is going to tell you a lot. If you dona't have a logic probe, you can make one out of an let, resistor and a couple of wires. Add some alligator clips to get really fancy.
 

jayanthd

Joined Jul 4, 2015
945
Fixed code.

Code:
sbit LCD_RS at LATC4_bit;
sbit LCD_EN at LATC5_bit;
sbit LCD_D4 at LATC0_bit;
sbit LCD_D5 at LATC1_bit;
sbit LCD_D6 at LATC2_bit;
sbit LCD_D7 at LATC3_bit;

sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;


void main() {
     ANSELC = 0;
     TRISC = 0;
     PORTC  0;
     LATC = 0;
    
     Lcd_Init();
     Lcd_Cmd(_LCD_CURSOR_OFF);
     Lcd_Cmd(_LCD_CLEAR);
    
     Lcd_Out(1,1,"Hello World");
     Lcd_Out(2,1,"LCD Display");
     Lcd_Chr_CP('@');
    
     while (1)
     {

     }
}
If you are using EasyPIC v7 development board then it has an LCD connector and its default connections are

Code:
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
Also EasyPIC v7 comes with default PIC18F45K22 and 8 MHz crystal. So, you have to select HS (4-16MHz) which is right in your configuration.

If you are using default Lcd connector on EasyPIC v7 development board then change code to PORTB connections as shown above and also use these.

Code:
ANSELB = 0;
TRISB = 0;
PORTB = 0;
LATB = 0;
before

Code:
Lcd_Init();
I have EasyPIC v7 and Ready for PIC development boards and also mikroC, mikroBasic and mikroPascal PRO for PIC Compilers.

If you need more help then you can contact me here.

Check for loose connections as you are using jumper wires to connect Ready for PIC40 board to Lcd. Put a 200 ms delay before Lcd_Init().
 
Last edited:
Top