yviswanathbe
Full Member level 4
Hi Friends,
I am facing problem with interfacing lcd in 4 bit mode with atmega32 micro controller.
I have done in 8 bit mode.
for initial testing i am just sending a string to LCD, but nothing is visible in the LCD. LCD is blank.
and the same lcd is working fine in 8 bit mode.
I am not able to trace the problem.
i have attached my source code. Some body please help me in solving the issue.
Thanks and Regards,
Viswanath.
I am facing problem with interfacing lcd in 4 bit mode with atmega32 micro controller.
I have done in 8 bit mode.
for initial testing i am just sending a string to LCD, but nothing is visible in the LCD. LCD is blank.
and the same lcd is working fine in 8 bit mode.
I am not able to trace the problem.
i have attached my source code. Some body please help me in solving the issue.
Code:
#include <mega32.h>
#include <stdio.h>
#include <delay.h>
#define LCDPORT PORTD
#define RS PORTB.0
#define RW PORTB.1
#define E PORTB.2
#define led PORTB.3
#define flag PIND.7
void lcd_init_write(unsigned char);
void lcd_com(unsigned char);
void lcd_data(unsigned char);
void lcd_init(void);
void lcd_puts(char *);
void busy();
void lcd_init_write(unsigned char a)
{
//busy();
RS=0;
RW=0;
LCDPORT=a;
E=1;
delay_ms(2);
E=0;
}
void busy()
{
PORTD=0x00;
DDRD=0x00;
RS=0;
RW=1;
while(flag!=0)
{
E=0;
delay_ms(2);
E=1;
}
PORTD=0xFF;
DDRD=0xFF;
}
void lcd_com(unsigned char a)
{
unsigned char temp;
busy();
RS=0;
RW=0;
temp=a;
temp=temp & 0xF0;
//LCDPORT=LCDPORT & 0xF0;
LCDPORT=LCDPORT & temp;
E=1;
delay_ms(2);
E=0;
temp=a;
temp=temp<<4;
temp=temp & 0xF0;
temp=temp>>4;
//LCDPORT=LCDPORT | 0xF0;
LCDPORT=LCDPORT & temp;
LCDPORT=LCDPORT & 0x0F;
E=1;
delay_ms(2);
E=0;
}
void lcd_data(unsigned char a)
{
unsigned char temp;
busy();
RS=1;
RW=0;
temp=a;
temp=temp & 0xF0;
//LCDPORT=LCDPORT & 0xF0;
LCDPORT=LCDPORT & temp;
E=1;
delay_ms(2);
E=0;
temp=a;
temp=temp<<4;
temp=temp & 0xF0;
temp=temp>>4;
//LCDPORT=LCDPORT | 0xF0;
LCDPORT=LCDPORT & temp;
LCDPORT=LCDPORT & 0x0F;
E=1;
delay_ms(2);
E=0;
}
void lcd_init(void)
{
lcd_init_write(0x30);
delay_ms(5);
lcd_init_write(0x30);
delay_ms(1);
lcd_init_write(0x30);
lcd_init_write(0x20);
lcd_com(0x28);
lcd_com(0x06);
lcd_com(0x08);
lcd_com(0x01);
lcd_com(0x0F);
lcd_com(0x02);
}
void lcd_puts(char *str)
{
while(*str)
lcd_data(*str++);
}
void main()
{
DDRB=0x0F;
PORTB=0x00;
DDRD=0xFF;
PORTD=0xFF;
delay_ms(20);
lcd_init(); //Intilize LCD in 4-Bit Mode
lcd_com(0x80); // Start Cursor From First Line
lcd_puts("Hello"); //Print HELLO on LCD
//lcd_com(0x01);
//lcd_com(0xC0); // Start Cursor From Second Line
//lcd_puts("World"); //Print HELLO on LCD
while(1); //Stay Forever Here
}
Thanks and Regards,
Viswanath.