The LCD powers on and displays one solid lines (black boxes), but no characters are shown. Even after sending correct initialization commands (e.g., 0x28
, 0x0C
, 0x01
), the display remains unchanged. The Display OFF
command (0x08
) has no effect either.
Observed Symptoms:
- Backlight and contrast are OK.
- LCD shows 1 solid lines (default uninitialized state).
- No change after command execution.
- Verified working pin connections and logic levels.
Steps Taken:
- Verified correct wiring for 4-bit mode:
- RS → P5.1, EN → P5.0, D4-D7 → P1.4–P1.7
- R/W pin tied to GND
- Used HD44780-compatible 4-bit init sequence:
LCD_Nibble(0x03); // x3
LCD_Nibble(0x02); // switch to 4-bit
LCD_Command(0x28); // Function set
LCD_Command(0x0C); // Display ON
LCD_Command(0x06); // Entry mode
LCD_Command(0x01); // Clear
- Proper delays added between steps (as per datasheet).
// lcd.c - Corrected Version with Proper EN Pulse and Initialization Sequence
**file lcd.c**
#include "lcd.h"
static const unsigned char LINE[2] = {0x80, 0xC0};
volatile unsigned long delay_count = 0;
void delayMs(unsigned long delay)
{
delay_count = 0;
R_TAU0_Channel0_Start();
while (delay_count < delay);
R_TAU0_Channel0_Stop();
}
void delayUs(unsigned int us)
{
volatile unsigned int i;
for (i = 0; i < (us * 5); i++)
{
NOP();
}
}
void LCD_Enable(void)
{
LCD_EN = 1;
delayUs(1); // Short enable pulse
LCD_EN = 0;
delayMs(2); // Let command settle
}
void LCD_Nibble(unsigned char nibble)
{
LCD_D4 = (nibble >> 0) & 0x01;
LCD_D5 = (nibble >> 1) & 0x01;
LCD_D6 = (nibble >> 2) & 0x01;
LCD_D7 = (nibble >> 3) & 0x01;
LCD_Enable();
}
void LCD_Command(unsigned char cmd)
{
LCD_RS = 0;
LCD_Nibble(cmd >> 4);
LCD_Nibble(cmd & 0x0F);
delayMs(2);
}
void LCD_Data(unsigned char data)
{
LCD_RS = 1;
LCD_Nibble(data >> 4);
LCD_Nibble(data & 0x0F);
delayMs(2);
}
void LcdInit(void)
{
LCD_RS = 0;
LCD_EN = 0;
delayMs(40); // Wait for LCD power-up
// Initialization sequence for 4-bit interface
LCD_Nibble(0x03); delayMs(5);
LCD_Nibble(0x03); delayMs(1);
LCD_Nibble(0x03); delayMs(1);
LCD_Nibble(0x02); delayMs(1); // Switch to 4-bit
LCD_Command(0x28); // 4-bit, 2-line, 5x8 font
LCD_Command(0x08); // Display OFF
LCD_Command(0x01); // Clear Display
delayMs(2);
LCD_Command(0x06); // Entry mode set
LCD_Command(0x0C); // Display ON, Cursor OFF
}
void LcdPrint(char row, char col, char* str)
{
LCD_Command(LINE[row - 1] + (col - 1));
while (*str)
{
LCD_Data(*str++);
}
}
**file lcd.h**
// lcd.h
#ifndef LCD_H
#define LCD_H
#include "r_cg_macrodriver.h"
#include "r_cg_port.h"
#include "r_cg_timer.h"
#define LCD_EN P5.0
#define LCD_RS P5.1
#define LCD_D4 P1.4
#define LCD_D5 P1.5
#define LCD_D6 P1.6
#define LCD_D7 P1.7
void LCD_Enable(void);
void LCD_Nibble(unsigned char nibble);
void LCD_Command(unsigned char cmd);
void LCD_Data(unsigned char data);
void LcdInit(void);
void LcdPrint(char row, char col, char* str);
void delayMs(unsigned long delay);
#endif
please suggest some solutions
