Toll-Free Customer Support 24/7

LCD interfacing with ATMEGA Code

# define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>

//#define LCD_PORT PORTB
#define RS PC0 //initialize register select as PC0 pin
#define EN PC1 //initialize enable pin as PC1

 

 


void CMD_WRT(unsigned char val)
{

PORTB=val;
PORTC = PORTC & (~(1<<RS));
_delay_ms(1); // here we provide a delay of 1 sec
ORTC = PORTC | ((1<<EN)); //make enable pin high
_delay_ms(1);
PORTC = PORTC & (~(1<<EN)); //make enable pin low

}


void DATA_WRT(unsigned char ch)
{

PORTB = ch;
PORTC = PORTC | ((1<<RS));//make register select pin high
_delay_ms(1);
PORTC = PORTC | ((1<<EN)); //make enable pin high
_delay_ms(1);
PORTC = PORTC & (~(1<<EN)); //make enable pin low
}
void LCD_WRT( char *string)
{
while(*string)
DATA_WRT(*string++);//will write the strings

}

 

 

int main(void)
{
//setting the display of the lcd
unsigned char CMD[]={0x38,0x01,0x0f,0x06,0x80},TEMP1,i;
DDRB=0XFF; //make PORTB as output
DDRC = 0xFF;//(1<<RS)|(1<<EN); //make PORTC as output
_delay_ms(10); //provide the delay of 10ms

for(i=0;i<5;i++)
{
TEMP1=CMD[i]; //it will place the command in cmd array
CMD_WRT(TEMP1); //it will write all the cmd that is in the cmd array
}

while(1)
{

CMD_WRT(0X01); //clear display
CMD_WRT(0X80); // blink the cursor in 1st row
LCD_WRT(" --RDL--");//display RDL in lcd
CMD_WRT(0XC0); //to use 2nd row of lcd
LCD_WRT(" LCD_DISPLAY"); //display LCD_DISPLAY in lcd

_delay_ms(1000); //delay of 1sec


}
return 0;
}

Back to top