Sign In

Trouble Printing Strings In Lcd

MERIN ALEXANDER merinalexander4@gmail.com India

Hardware: Pic16f877a With 20mhz Frequency Software: MPLAB IDE V8.92

my program is not printing string if i use the below string function. but if single charcter is displayed it works fine. please help me.

Images

Program

#include<pic.h>

char str[20];

#define lcd_port PORTD
#define lcd_rs RB0
#define lcd_rw RB1
#define lcd_en RB2

void lcd_init();
void lcd_command(char);
void lcd_data(char);
void delay(int);
void lcd_string(char *);


void main()
{
 TRISD=0x00;
 TRISB=0x00;
 lcd_init();
 //lcd_command(0x80);
 lcd_string("Merin Alexander");
// lcd_command(0xc0);
// delay(2);	
// lcd_string("Technologics");	
 while(1);
}

void lcd_init()
{
 lcd_command(0x01);
 lcd_command(0x80);
 lcd_command(0x0c);
 lcd_command(0x06);
 lcd_command(0x38);
}

void lcd_command(char x)
 {
   lcd_rs=0;
   lcd_port=x;
   lcd_rw=0;
   lcd_en=1;
   delay(2);
   lcd_en=0;
 }
 
void lcd_data(char x)
 {
   lcd_rs=1;
   lcd_port=x;
   lcd_rw=0;
   lcd_en=1;
   delay(2);
   lcd_en=0;
 }

void delay(int d)
{
  int i,j;
  for(i=0;i<d;i++)
  {
   for(j=0;j<256;j++);
   for(j=0;j<256;j++);
  }
}

//void lcd_string(char x[])
//{
//  int i; 
//  for(i=0;x[i];i++)
//   {
//     lcd_data(x[i]);
//     delay(2);
//   }
//}
  
void lcd_string(char *s)
 {
  while(*s)
   {
     lcd_data(*s++);
   }
 }

Replies

R Avinash Gupta
2017-05-16 05:25:46
The code is written in extremely poor way. You can correct it by putting a delay between sending characters. it will start working but even then it is a poor piece of code.
R MERIN ALEXANDER
2017-05-16 05:44:58
even with a delay it will not work. i am a beginner in programming so suggest me ways to improve my coding too.
R Avinash Gupta
2017-05-16 13:12:57
How much delay did you put? How did you put the delay?

Post a reply to MERIN ALEXANDER

Think you can help MERIN ALEXANDER ? Then post your thoughts that might help MERIN ALEXANDER. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.