Toll-Free Customer Support 24/7

PIC Development Board

/*
* Project name:
PIC Development Board
* Copyright
(c) Researchdesignlab.com
* Test configuration:
MCU: PIC16F877A
Dev.Board: PIC
Oscillator: 20.0 MHz
Software: MPLAB IDE v8.92(HI-TECH_C)
*/

/*LCD Display*/

#include <htc.h>
#include<string.h>
#define _XTAL_FREQ 20000000 //crystal frequency of 20MHZ
#define EN RD7 //connect enable pin of LCD to port D7
#define RS RD6 //connect Register select pin of LCD to port D6

void LCD_Delay() //Delay
{
__delay_ms(1);
}

 

void LCD_Cmd(unsigned char cmd) //send a command
{


PORTB=cmd;
RS=0; //for command
EN=1;
LCD_Delay();
EN=0;
LCD_Delay();
}

void LCD_Init() //Initialising LCD
{
unsigned char cmd[5]={0X38,0X06,0X0F,0X01,0X80},Count;
for(Count=0;Count<5;Count++)
LCD_Cmd(cmd[Count]);
}

void LCD_SendDataByte(unsigned char data) //to display a character
{
PORTB=data;
RS=1; //for data
EN=1;
LCD_Delay();
EN=0;
LCD_Delay();
}
void LCD_Display( char *addr) //for strings
{
while(*addr)
{
LCD_SendDataByte(*addr);
addr++;
}
}


void main()
{
TRISB=0x00; //make the register as ouput
TRISD=0x00;
LCD_Init();
__delay_ms(1000);
while(1)

{

LCD_Cmd(0X01); //clearing the LCD
LCD_Cmd(0X84); //1st row 4th position
LCD_Display("123"); //display

LCD_Cmd(0xc0); //2nd row
LCD_Display(" RDL"); //display
__delay_ms(1000); //delay

LCD_Cmd(0x01); //clear the LCD
LCD_Cmd(0x80); //1st row
LCD_Display(" LCD");

LCD_Cmd(0xc0); //2nd row
LCD_Display(" Display"); //display on LCD
__delay_ms(1000); //delay
}
}

Back to top