#include<pic.h>
#define RS RB2
#define EN RB1
#define databits PORTD
void Delay(unsigned int );
/*----------------PIC INITIALIZATION------------*/
void pic_init()
{
TRISB2 = 0;
TRISB1 = 0;
TRISD = 0;
}
/*-------------LCD FUNCTIONS BEGIN--------------*/
void LCD_STROBE(void)
{
EN = 1;
Delay(20);
EN = 0;
}
void Lcd4_Write(unsigned char c)
{
RS = 1;
Delay(20);
databits = (c >> 4);
LCD_STROBE();
databits = (c);
LCD_STROBE();
}
void Lcd4_Command(unsigned char c)
{
RS = 0;
Delay(20);
databits = (c >> 4);
LCD_STROBE();
databits = (c);
LCD_STROBE();
}
void clear(void)
{
Lcd4_Command(0x01);
Delay(10);
}
void Lcd4_Init()
{
Delay(10);
Lcd4_Command(0x38);
Delay(10);
Lcd4_Command(0x38);
Delay(10);
Lcd4_Command(0x38);
Lcd4_Command(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
Lcd4_Command(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
Lcd4_Command(0x0c); // Make cursorinvisible
clear(); // Clear screen
Lcd4_Command(0x6); // Set entry Mode(auto increment of cursor)
}
void Lcd4_Display(const char *q)
{
while (*q) {
Lcd4_Write(*q++);
}
}
/*-------------LCD END--------------------*/
main()
{
Delay(10);
//pic_init();
TRISD=0x00;
TRISB=0x00;
Lcd4_Init();Delay(10);
TRISC = 0;
while (1) {
Lcd4_Command(0x80);
Lcd4_Write('B');
Lcd4_Command(0xc0);
Lcd4_Display("IT IS WORKING:-)");
}
}
void Delay(unsigned int del)
{
while(del--);
}