i got a program for 8 bit lcd and its working
but i'd like to know , how its working
so anybody could explain the program
#include<htc.h>
#define RS RB2
#define RW RB3
#define EN RB4
void LCD_delay(void)
{
int t;
for(t=0;t<250;t++);
}
void delay_ms(unsigned char delay)
{
unsigned int i,j;
for(i=0;i<=delay;i++)
{
for(j=0;j<=1000;j++);
}
}
void LCD_command(unsigned char command)
{
unsigned char temp;
RS = 0;
temp =command & 0xff;
PORTD &= 0x00;
PORTD |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();
}
void LCD_data(unsigned char data)
{
unsigned char temp;
RS=1;
temp = data & 0xff;
PORTD &= 0x00;
PORTD |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();
}
void initialise_LCD(void)
{
ADCON0 = 0x00;//Disable ADC ports
ADCON1 = 0x06;//Disable ADC ports
TRISD = 0x00;
PORTD = 0x00; //DATA or COMMAND i/p to LCD
TRISE = 0x00;
PORTE = 0x00; //CONTROL i/p to LCD
EN=0;
RW=0;
delay_ms(40);
LCD_command(0x38);
delay_ms(20);
LCD_command(0x38);
delay_ms(2);
LCD_command(0x38);
delay_ms(1);
LCD_command(0x07);//increment, disp shift
LCD_command(0x0c);//off cursor, display on
LCD_command(0x14);//Display shift,shift to left i.e. scroll
LCD_command(0x02);//Command return the cursor to home
LCD_command(0x01);//clear LCD
delay_ms(1);
}
void clear_LCD()
{
LCD_command(0x01);
delay_ms(1);
}
void display_LCD(char line_number,char position, const char *message)
{
int a;
if(line_number==1)
{
a=0x80+position;
LCD_command(a);
}
else if(line_number==2)
{
a=0xC0+position;
LCD_command(a);
}
while(*message!=0)
{
LCD_data(*message);
delay_ms(15);
message++;
}
}
void main(void)
{
__CONFIG(0x193A);
initialise_LCD();
while(1)
{
display_LCD(1,8,"WELCOME TO ALL OF YOU PEOPLE...");
display_LCD(2,4,"welcome");
delay_ms(1);
}
}
but i'd like to know , how its working
so anybody could explain the program
#include<htc.h>
#define RS RB2
#define RW RB3
#define EN RB4
void LCD_delay(void)
{
int t;
for(t=0;t<250;t++);
}
void delay_ms(unsigned char delay)
{
unsigned int i,j;
for(i=0;i<=delay;i++)
{
for(j=0;j<=1000;j++);
}
}
void LCD_command(unsigned char command)
{
unsigned char temp;
RS = 0;
temp =command & 0xff;
PORTD &= 0x00;
PORTD |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();
}
void LCD_data(unsigned char data)
{
unsigned char temp;
RS=1;
temp = data & 0xff;
PORTD &= 0x00;
PORTD |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();
}
void initialise_LCD(void)
{
ADCON0 = 0x00;//Disable ADC ports
ADCON1 = 0x06;//Disable ADC ports
TRISD = 0x00;
PORTD = 0x00; //DATA or COMMAND i/p to LCD
TRISE = 0x00;
PORTE = 0x00; //CONTROL i/p to LCD
EN=0;
RW=0;
delay_ms(40);
LCD_command(0x38);
delay_ms(20);
LCD_command(0x38);
delay_ms(2);
LCD_command(0x38);
delay_ms(1);
LCD_command(0x07);//increment, disp shift
LCD_command(0x0c);//off cursor, display on
LCD_command(0x14);//Display shift,shift to left i.e. scroll
LCD_command(0x02);//Command return the cursor to home
LCD_command(0x01);//clear LCD
delay_ms(1);
}
void clear_LCD()
{
LCD_command(0x01);
delay_ms(1);
}
void display_LCD(char line_number,char position, const char *message)
{
int a;
if(line_number==1)
{
a=0x80+position;
LCD_command(a);
}
else if(line_number==2)
{
a=0xC0+position;
LCD_command(a);
}
while(*message!=0)
{
LCD_data(*message);
delay_ms(15);
message++;
}
}
void main(void)
{
__CONFIG(0x193A);
initialise_LCD();
while(1)
{
display_LCD(1,8,"WELCOME TO ALL OF YOU PEOPLE...");
display_LCD(2,4,"welcome");
delay_ms(1);
}
}