Microcontroller › AVR › problem regarding interfacing LCD using ATMEGA16 code by CHINMAY CHINARA › m having same problem with
m having same problem with JHD162A ATmega16
heres the code…
//#define F_CPU 16000000
#include <avr/io.h>
//#include <util/delay.h>
#define lcd_data PORTB
/*
PD.0=rs
PD.1=rw
PD.2=en
*/
void lcdbusy() //function to monitor d7th bit (busy flag)
{
DDRB=0x7f;// this will make msb of portb to input
PORTD=0xfe;// rs=0 rw=1 en=1, rw=1->read from lcd
while(PINB>>7) //move the msb to lsb
{
PORTD |=0x04; //en-> from low to high
PORTD &=0xfb; //en-> from high to low
}
DDRB=0xff;//make PORTB for output
}
void initlcd()
{
DDRD=0xff; //PORTD as output
DDRB=0xff; //portb as output
lcd_data=0x38; //8 bit,5×7 dots
PORTD=0xfc; //rs=0 rw=0 en=1, 0xfc where c=1100
PORTD=0xf8; //rs=0 rw=0 en=0, 0xf8 where 8=1000, frm en->high to low
lcdbusy(); // w8 b4 executing next command
lcd_data=0x0f; //cursor blinking display on
PORTD=0xfc;
PORTD=0xf8;
lcd_data=0x01; // clear lcd
PORTD=0xfc;
PORTD=0xf8;
lcdbusy();
lcd_data=0x06; //entry mode
PORTD=0xfc;
PORTD=0xf8;
lcdbusy();
}
void lcdcmd(unsigned char ch)
{
lcd_data=ch;
PORTD=0xfc;
PORTD=0xf8;
lcdbusy();
}
void lcdchar(unsigned char ch)
{
lcd_data=ch;
PORTD=0xfd; // 0xfd where d=1101 rs=w rw=0 en=1
PORTD=0xf9; //9=1001 rs=1 rw=0 en=0, en-> from high to low
lcdbusy();
}
void lcdstring(char *str)
{
while(*str)
{
lcdchar(*str);
str++;
}
}
int main()
{
initlcd();
lcdcmd(0x80);// move cursor to 1st line 1st column
lcdstring(“Welcome ATmega16 !”);
while(1);
return 0;
}
m i missing something ?