Sunday, June 12, 2016

LCD INTERFACING 8 BIT MODE

Circuit connection is 
RS => PB0
RW => PB1
EN => PB2
D0-D3 =>PORTD 0 TO 3
D4-D7 => PORTC 0 TO 3



#define  F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>

#define LCD_RS_SET PORTB |= (1<<PORTB0)
#define LCD_RS_RESET PORTB &= ~(1<<PORTB0)
#define LCD_RW_RESET PORTB &= ~(1<<PORTB1)
#define LCD_EN_SET PORTB |= (1 <<PORTB2)
#define LCD_EN_RESET PORTB &= ~(1<<PORTB2)
#define LCD_DATAL PORTD
#define LCD_DATAH PORTC
#define LCD_ISDATA 1
#define LCD_ISCMD 0

void write_port(unsigned char d){
LCD_DATAH = d;
LCD_DATAH >>= 4;
LCD_DATAL = d;

}

void send_data(unsigned char d, int isData){
LCD_EN_SET;
if(isData)
LCD_RS_SET;
else
LCD_RS_RESET;
write_port(d);
_delay_ms(1);
LCD_EN_RESET;
LCD_RW_RESET;

}


void lcd_init(){
DDRB = 0xff;
DDRC = 0xff;
DDRD = 0xff;
send_data(0x38,LCD_ISCMD); //8 bit 2 line mode
send_data(0x0e,LCD_ISCMD); //display on and cursor on

send_data(0x01,LCD_ISCMD); //clears the screen
send_data(0xc0,LCD_ISCMD); //MOVES TO SENCOND LINE
}


int main(void)
{ unsigned char name[]="MICROCONTROLLER";
int i;
lcd_init();
for(i = 0;i<sizeof(name)-1;i++){
send_data(name[i],LCD_ISDATA);
}

 
    while (1)
    {

    }
}

No comments:

Post a Comment