I am trying to write message on specific line of LCD. I wrote following program but LCD doesn't show the message on screen
8051 and keil
Program output
compiling lcd.c...
lcd.c - 0 Error(s), 0 Warning(s).
8051 and keil
C:
#include<reg51.h>
#define port P1 /* Data pins connected to port P1 */
sbit RS = P2^0; /* RS pin connected to pin 0 of port P2 */
sbit RW = P2^1; /* RW pin connected to pin 1 of port P2 */
sbit EN = P2^2; /* EN pin connected to pin 2 of port P2 */
void DelayUs(unsigned int wait);
void DelayMs(unsigned int wait);
void LCD_Command(unsigned char cmd);
void LCD_Data(unsigned char Data);
void LCD_init();
void LCD_goto( int x, int y);
void LCD_print(char* str);
/* functions for delay */
void DelayUs(unsigned int wait)
{
wait >>= 3;
while(wait--);
}
void DelayMs(unsigned int wait)
{
while(wait--)
DelayUs(1000);
}
/* Function to send command instruction to LCD */
void LCD_Command(unsigned char cmd)
{
port = cmd;
RS=0;
RW=0;
EN=1;
DelayMs(5);
EN=0;
}
/*Function to send display dato LCD */
void LCD_Data(unsigned char Data)
{
port = Data;
RS=1;
RW=0;
EN=1;
DelayMs(5);
EN=0;
}
/* Function to prepare the LCD */
void LCD_init()
{
LCD_Command(0x38);
DelayMs(15);
LCD_Command(0x0f);
DelayMs(15);
LCD_Command(0x01);
DelayMs(15);
LCD_Command(0x81);
DelayMs(15);
}
/*Function to position cursor on the LCD */
void LCD_goto( int x, int y)
{
int addr = 0x80;
if(y==2) addr+=0x40;
addr += x;
LCD_Command(addr);
}
/* Function to print on the LCD */
void LCD_print(char* str)
{
while(*str!=0)
LCD_Data(*str++);
}
void main(void)
{
void LCD_init();
while(1)
{
LCD_goto(1,1);
LCD_print("Hello");
LCD_goto(2,1);
LCD_print("Forum");
}
}
compiling lcd.c...
lcd.c - 0 Error(s), 0 Warning(s).