/*
#define F_CPU 12000000UL
#include <avr/io.h>
#include<util/delay.h>
#define LCDPORT PORTC // Renaming the PORTD to LCDPORT
#define RS PC2 // Renaming the RS pin to 2
#define E PC3 // Renaming the E to number 3
#define LINE2 lcd_cmd(0xc0);
void latch(void) // used to a high to low pulse the pin E
{
PORTC |= ~(1<<E); // here we give a high to PORTD.3
_delay_ms(1);
PORTC |= (1<<E); // Here we give a LOW to PORTD.#
}
void lcd_cmd(unsigned char c) // used to send the command / Instruction to the lcd port
{
PORTC |= ~(1<<RS); // send a '0' value to select to send command
_delay_ms(1);
LCDPORT = c & 0xf0; // send the command c only 4 bit by masking the lower bit
latch();
_delay_ms(1);
LCDPORT = (c << 4); // giving the lowerbit by shifting the 4 bit to left
latch();
}
void lcd_data(unsigned char c)
{
PORTC |= (1<<RS); // send 1 to send data
_delay_ms(1);
LCDPORT = c & 0xf0| 0x4; //send the data only 4 bit by masking the lower bit and also making the RS pin high by giving 0x04 .
_delay_ms(1);
latch();
LCDPORT = (c << 4)| 0x4; ; // giving the lower bit by shifting the 4 bit to left
latch();
}
void lcd_init()
{
_delay_ms(20);
lcd_cmd(0x30); //as per data sheet
_delay_ms(1);
lcd_cmd(0x30); //as per data sheet
_delay_us(100);
lcd_cmd(0x32); //as per data sheet
_delay_ms(4);
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x0c); // Make cursorinvisible
lcd_cmd(0x6); // Set entry Mode(auto increment of cursor)
}
void string(const char *q) // used to send single charcter to display the lcd
{
while (*q) {
lcd_data(*q++);
}
}
void main(){
_delay_ms(50);
DDRC = 0xff;
lcd_init();
string("hello ");
LINE2
string("good displaying ");
while(1);
}