C program to print text on 2x16 LCD display using PIC 16f877a micro-controller

C program to print text on 2x16 LCD display using PIC 16f877a micro-controller



#include <htc.h>
__CONFIG(0x3F3A);
#define rs RC0
#define rw RC1
#define en RC2
#define lcd PORTD

void lcd_ini();
void lcd_cmd(unsigned char cmd);
void lcd_data(unsigned char data);
void lcd_str(unsigned char *str);
void delay();

void main()
{
          TRISC=0;
          TRISD=0;
          lcd_ini();
    lcd_cmd(0x82);
    lcd_str("I AM CAPTAIN");
    lcd_cmd(0XC0);
          lcd_str("NEEL JACKSPARROW");
    while(1);
}

void lcd_ini()
{
          lcd_cmd(0x38);
    delay();
          lcd_cmd(0x0E);
    delay();   
    lcd_cmd(0x01);
    delay();
    lcd_cmd(0x06);
    delay();
}

void lcd_cmd(unsigned char cmd)
{
          lcd=cmd;
          rs=0;
          rw=0;
          en=1;
          delay();
          en=0;
}

void lcd_data(unsigned char data)
{
          lcd=data;
          rs=1;
          rw=0;
          en=1;
          delay();
          en=0;
}

void delay()
{
unsigned int i=5000;
while(i--);
}

void lcd_str(unsigned char *str)
{
unsigned char i=0;
while(str[i]!=0)
lcd_data(str[i++]);
}


Proteus Simulated design: 

< click on the image for enlarged view >

 

 

Video Screen Capture