const int rs = 3;
const int rw = 4;
const int en = 5;
const int d0 = 6;
const int d1 = 7;
const int d2 = 8 ;
const int d3 = 9;
const int d4 = 10 ;
const int d5 = 11;
const int d6 = 12;
const int d7 = 13;
void printdata(unsigned char data) {
digitalWrite(d0, (data & 0x01) ? HIGH : LOW);
digitalWrite(d1, (data & 0x02) ? HIGH : LOW);
digitalWrite(d2, (data & 0x04) ? HIGH : LOW);
digitalWrite(d3, (data & 0x08) ? HIGH : LOW);
digitalWrite(d4, (data & 0x10) ? HIGH : LOW);
digitalWrite(d5, (data & 0x20) ? HIGH : LOW);
digitalWrite(d6, (data & 0x40) ? HIGH : LOW);
digitalWrite(d7, (data & 0x80) ? HIGH : LOW);
}
void lcd_data(unsigned char data){
// this function is used to tell the lcd to place the data in the data register or in the instruction register when we are passing the character
// Thats need to be printed on the led
// so passing the data to data register of the lcd
printdata(data);
digitalWrite(rs,HIGH);// we just want to store the data received in the data register of the lcd
digitalWrite(rw, LOW); // for writing of the lcd
digitalWrite(en, HIGH); // clock signal for the lcd
delay(2);
digitalWrite(en, LOW);
}
void lcd_cmd(unsigned char cmd){ // function is used to print the data in a deisred place like where the cursor has to be placed and move the data to the next row like that..
printdata(cmd);
digitalWrite(rs, LOW);// if u make the rs as high the data passed to the lcd will be stored DATA REGISTER of the lcd and if u make RS AS LOW the data will be stored in INSTRUCTION REGISTER OF THE LCD
digitalWrite(rw, LOW);
digitalWrite(en, HIGH);
delay(2);
digitalWrite(en, LOW);
}
void lcd_string(unsigned char str[],unsigned char num){
// num=length of the string
unsigned char i;
for(i=0; i<num; i++){
lcd_data(str[i]);
}
}
void lcd_initialise(){
// initialising the state of the lcd
// this is a must function
lcd_cmd(0x38); //This wil configure the lcd in 16 column and 2 rows format
lcd_cmd(0x0c); //This will turns of the display and turn off the cursor
lcd_cmd(0x06); // Incrementing the cursor to the next position when the current element is printed
lcd_cmd(0x01); // clear screen
}
void setup() {
pinMode( rs, OUTPUT);
pinMode( rw, OUTPUT);
pinMode( en, OUTPUT);
pinMode( d0, OUTPUT);
pinMode( d1, OUTPUT);
pinMode( d2, OUTPUT);
pinMode( d3, OUTPUT);
pinMode( d4, OUTPUT);
pinMode( d5, OUTPUT);
pinMode( d6, OUTPUT);
pinMode( d7, OUTPUT);
lcd_initialise();
}
void loop() {
lcd_cmd(0x80);
lcd_string("Mathesh",7);
lcd_cmd(0xc0);
lcd_string("Varma ",5);
}