#include <htc.h>
#include<delays.h>
#include <pic18F4550.h>
#define E_PIN PORTDbits.RD6 /* PORT for E */
#define RW_PIN PORTDbits.RD5 /* PORT for RW */
#define RS_PIN PORTDbits.RD4 /* PORT for RS */
#define _XTAL_FREQ 20000000
__CONFIG (1, FOSC_HS);
__CONFIG (2, WDTDIS & PWRTEN & BOREN & LVPEN);
void prnt(unsigned int);
void commd(unsigned int);
void lcd_init(void);
void Delay10KTCYx(unsigned char unit);
void Delay1KTCYx(unsigned char unit);
void main(void)
{
int count=0;
int marquee_1 = 0;
int dir_1 = 0;
char output[] = " Hello ";
char output2[] = " World !! ";
TRISD=0x00;
PORTD=0x00;
Delay10KTCYx(200); // After Power On, this instruction will give 16ms delay
lcd_init();
while(output[count] != '\0')
{
prnt(output[count]);
count++;
}
commd(0b11000000); //Move 2nd Next Line
count = 0;
while(output2[count] != '\0')
{
prnt(output2[count]);
count++;
}
commd(0b10000000);
while(1)
{
if(marquee_1 == 0)
dir_1 = 1;
if(marquee_1 == 9)
dir_1 = 0;
if(dir_1)
{
commd(0b00011100);
marquee_1++;
}
else
{
commd(0b00011000);
marquee_1--;
}
Delay10KTCYx(200);
}
}
void lcd_init(void)
{
E_PIN = 0;
RS_PIN = 0;
RW_PIN = 0;
commd(0b00100000); //
commd(0b00101100); // Function Set
commd(0b00001000); // Display OFF
commd(0b00000001); // Display Clear
commd(0b00000110); // Entry Mode Set
}
//4-bit print interface
void prnt(unsigned int character)
{
PORTD=character >> 4;
RS_PIN = 1;
RW_PIN = 0;
E_PIN = 1;
E_PIN = 0;
PORTD=character & 0x0f;
RS_PIN = 1;
RW_PIN = 0;
E_PIN = 1;
E_PIN = 0;
Delay1KTCYx(200);
//Delay1KTCYx(1); //The Delay Above Is Only To
//Create The Type-Writer Effect
}
//4-bit instruction interface
void commd(unsigned int commd)
{
PORTD=commd >> 4;
RS_PIN = 0;
RW_PIN = 0;
E_PIN = 1;
E_PIN = 0;
PORTD=commd &0x0f;
RS_PIN = 0;
RW_PIN = 0;
E_PIN = 1;
E_PIN = 0;
Delay1KTCYx(10);
}