Thread: LCD 16x2 Display only shows black boxes?

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    1

    LCD 16x2 Display only shows black boxes?

    Hi, I am unable to initialise this 16x2 LCD Display, could any one here help please? Went through past threads and still unable to solve
    Using a PIC18F4520 with 4Mhz crystal

    First line is filled with black boxes, second line is clear

    Code:
    #include <p18f4520.h>
    #include <delays.h>
    #include <timers.h>
    #include <stdio.h>
    
    
    #pragma config WDT = OFF   	 //	Disable Watchdog timer
    #pragma config BOREN = OFF   // Disable Brown-out reset
    #pragma config LVP = OFF   	 // Disable low voltage ICSP
    
    
    #define LCD_DATA	PORTD				// LCD Data
    #define LCD_RS   	PORTBbits.RB4   	// RS signal for LCD
    #define LCD_E    	PORTBbits.RB3   	// E signal for LCD
    
    
    void Init_LCD(void);			// Initialize the LCD
    void W_ctr_8bit(char);			// 8-bit Control word for LCD
    void W_data_8bit(char);			// 8-bit Text Data for LCD
    void Delay_1kcyc(void);			// 1000 cycles delay, 1ms
    
    
    void main()
    {
    unsigned char i=0; //loop variable
    char MESS[12] ="WELCOME!!!";
    
    
    ADCON1=0x0F;					// Ports A,B & E as digital I/O
    TRISA=0x00;
    TRISB=0;				// RB3,RB4 for LCD interface RS&E	
    TRISD=0;				// Port D as LCD Data Output
    TRISE=0x00;
    
    
    Delay10KTCYx(1);
    Init_LCD();				// Init LCD 8-bit interface,multiple line
    
    
    W_ctr_8bit(0b11000000); 
    
    
    for(i=0;i<10;i++)
    {
    Delay1KTCYx(1);	//small delay
    W_data_8bit(MESS[i]); 	// Write individual character to LCD
    }
    }
    
    
    /* LCD display initialization */
    void Init_LCD(){								
    	W_ctr_8bit(0b00111000);		// Function Set - 8-bit, 2 lines, 5X7
     	W_ctr_8bit(0b00001100);		// Display on, cursor on
    	W_ctr_8bit(0b00000110);		// Entry mode - inc addr, no shift
    	W_ctr_8bit(0b00000001);		// Clear display  
    	W_ctr_8bit(0b00000110);		// Return cursor to home position
    }
    
    
    /* Write control word to LCD */
    void W_ctr_8bit(char x){ 						
       LCD_RS	= 0;				// Logic ‘0’
       Delay1KTCYx(1);	//small delay
       LCD_E	= 1;				// Logic ‘1’
       Delay1KTCYx(1);	//small delay
       LCD_DATA = x;
       Delay1KTCYx(1);	//small delay
       LCD_E	= 0;				// Logic 0’
       Delay1KTCYx(1);			// delay
    }
    
    
    /* Write text data to LCD */
    void W_data_8bit(char x){ 
       LCD_RS	 = 1;				// Logic ‘1’
       Delay1KTCYx(1);	//small delay
       LCD_E	 = 1;				// Logic ‘1’
       Delay10KTCYx(1);	//small delay
       LCD_DATA  = x;
       Delay1KTCYx(1);	//small delay
       LCD_E	 = 0;				// Logic ‘0’
       Delay10KTCYx(25);			// delay
    }

    Help please, I tried for really long already.
    Last edited by ElectronicX; 06-12-2012 at 07:28 AM. Reason: format error

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You have checked that the contrast isnt too high?

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    This probably isn't the best forum for this question (for example, I might have considered the tech forum).

    You don't provide a link to the LCD you are using, so there is little we can do to help. I do notice that you have the "E" and "RS" signals in your code; does your LCD use "R/W~" also? I have a little bit of experience with the Noritake displays, and I remember crawling through the data sheet for hours before I finally got it to work.

    Also check the timing diagrams carefully, this might highlight a problem. For instance, maybe a 1ms pause between the "send" command (setting "E", pausing 1ms, then clearing "E") might be too long. Again, difficult to say without knowing which LCD you're using.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Wait a least 1 sec after power on before sending any initialization commands to the LCD.

    Normally requires 100ms to 500ms before LCD is ready for commands after it is turned on.

    NOTE: The initialization commands often require several ms for them to work (this delay is needed between each command).

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Definitely check your timing, normally you must wait several ms (usually about 40 ms) before writing to the LCD. Also after writing the first byte (0x38) you need to wait about 5 ms, you need to repeat this command three times waiting 5 ms, 100us, 100us. Then you can set your modes, checking the busy flag or waiting at least 37 us for everything except the cursor home which takes about 1.6 ms.

    The above is based on using a LCD which has a HD44780 based controller.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Edit boxes, and list boxes
    By osal in forum Windows Programming
    Replies: 2
    Last Post: 07-07-2004, 12:34 PM
  2. What shows do you watch?
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 40
    Last Post: 04-29-2004, 02:55 PM
  3. no window shows up
    By hanhao in forum Windows Programming
    Replies: 5
    Last Post: 04-15-2004, 10:23 AM
  4. I declared it as int but it shows up as an char...
    By XR3D403 in forum C Programming
    Replies: 5
    Last Post: 02-10-2003, 09:12 AM
  5. TV shows
    By Yoshi in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-13-2001, 11:37 PM

Tags for this Thread