Hi all,
I’ve connected a LCD display 16x2 with PIC16F877A . I 've written code for 8 bit mode When i run the code, the LCD powers up, I see the top row of the LCD with all black square. I did continuity test with multimeter all connection looks okay. It proves there is problem with LCD initialization
Display datasheet attached. Please help
I’ve connected a LCD display 16x2 with PIC16F877A . I 've written code for 8 bit mode When i run the code, the LCD powers up, I see the top row of the LCD with all black square. I did continuity test with multimeter all connection looks okay. It proves there is problem with LCD initialization
C:
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ
#include <xc.h>
//LCD GND - to PIC GND
//LCD VCC - to PIC 5V
//LCD CONT - to POT
#define RS RB1
#define RW RB2
#define EN RB3
#define LCD_Port PORTD
/* Make all PORTD pins low and Configured PORT pins as Output*/
void Port_Initialize (void)
{
PORTA = 0;
PORTB = 0;
PORTC = 0;
PORTD = 0;
PORTE = 0;
TRISA = 0b00000000;
TRISB = 0b00000000;
TRISC = 0b00000000;
TRISD = 0b00000000;
TRISE = 0b00000000;
}
/* Function to send command instruction to LCD */
void LCD_Command(unsigned char Command)
{
LCD_Port = Command;
RS=0;
RW=0;
EN=1;
__delay_ms(2);
EN=0;
}
/*LCD Initialize*/
void LCD_Initialize (void)
{
__delay_ms(40); // wait 40 milliseconds
LCD_Command(0x30); // 8-bit interface data, 1-line display, 5 × 8 dot character font
__delay_ms(5);
LCD_Command(0x30);
__delay_us(100);
LCD_Command(0x30);
__delay_us(40);
LCD_Command(0x01); //Clears display
__delay_us(40);
LCD_Command(0x0F); //display on, cursor on, cursor blink on
__delay_us(40);
}
/*Function to send message to LCD */
void LCD_Data(unsigned char Message)
{
LCD_Port = Message;
RS=1;
RW=0;
EN=1;
__delay_ms(2);
EN=0;
}
void Messagebuffer( unsigned char *pointer)
{
while (*pointer != '\0')
{
LCD_Data(*pointer);
pointer++;
}
}
void main(void)
{
unsigned char string []= {"Project"};
Port_Initialize ();
LCD_Initialize ();
Messagebuffer(string);
while(1);
}
Display datasheet attached. Please help