lcd interfacing with atmega16
Discussion in "AVR Discussion Forum" started by Nikhil K'wal Aug 14, 2008.
Thu Aug 14 2008, 02:53 am
Hello every1 !!!!!!
m facing some problem in interfacing 2line 16 bit lcd sreen JHD162 with atmega16........
after setting all the circuit when i start the power button,getting nothing on the lcd screen except some black squares in the first line of screen..........
i m giving the code which i have tried for this.............plz help me
#include<avr/io.h>
#include<util/delay.h>
#include<compat/deprecated.h>
#define lcd_en PD0
#define lcd_rs PD1
#define lcd_rw PD2
void lcd_busy();
void lcd_command(unsigned char a);
void lcd_senddata(unsigned char a);
void main()
{
DDRB=0xFF;
DDRD=0xFF;
void init()
{
PORTB = 0x38;
cbi(PORTD,lcd_rs);
cbi(PORTD,lcd_rw);
sbi(PORTD,lcd_en);
cbi(PORTD,lcd_en);
lcd_busy();
PORTB=0x0F;
cbi(PORTD,lcd_rs);
cbi(PORTD,lcd_rw);
sbi(PORTD,lcd_en);
cbi(PORTD,lcd_en);
lcd_busy();
PORTB=0x01;
cbi(PORTD,lcd_rs);
cbi(PORTD,lcd_rw);
sbi(PORTD,lcd_en);
cbi(PORTD,lcd_en);
lcd_busy();
PORTB=0x06;
cbi(PORTD,lcd_rs);
cbi(PORTD,lcd_rw);
sbi(PORTD,lcd_en);
cbi(PORTD,lcd_en);
lcd_busy();
}
lcd_command(0x01);
lcd_senddata('A');
}
}
void lcd_busy()
{
unsigned char i,j;
for(i=0;i<50;i++) //A simple for loop for delay
for(j=0;j<255;j++);
}
void lcd_command(unsigned char a)
{
PORTB=a;
cbi(PORTD,PD1);
cbi(PORTD,PD2);
sbi(PORTD,PD0);
cbi(PORTD,PD0);
lcd_busy();
}
void lcd_senddata(unsigned char a)
{
PORTB=a;
sbi(PORTD,PD1);
cbi(PORTD,PD2);
sbi(PORTD,PD0);
cbi(PORTD,PD0);
lcd_busy();
}
thank you for your help in advance...................
m facing some problem in interfacing 2line 16 bit lcd sreen JHD162 with atmega16........
after setting all the circuit when i start the power button,getting nothing on the lcd screen except some black squares in the first line of screen..........
i m giving the code which i have tried for this.............plz help me
#include<avr/io.h>
#include<util/delay.h>
#include<compat/deprecated.h>
#define lcd_en PD0
#define lcd_rs PD1
#define lcd_rw PD2
void lcd_busy();
void lcd_command(unsigned char a);
void lcd_senddata(unsigned char a);
void main()
{
DDRB=0xFF;
DDRD=0xFF;
void init()
{
PORTB = 0x38;
cbi(PORTD,lcd_rs);
cbi(PORTD,lcd_rw);
sbi(PORTD,lcd_en);
cbi(PORTD,lcd_en);
lcd_busy();
PORTB=0x0F;
cbi(PORTD,lcd_rs);
cbi(PORTD,lcd_rw);
sbi(PORTD,lcd_en);
cbi(PORTD,lcd_en);
lcd_busy();
PORTB=0x01;
cbi(PORTD,lcd_rs);
cbi(PORTD,lcd_rw);
sbi(PORTD,lcd_en);
cbi(PORTD,lcd_en);
lcd_busy();
PORTB=0x06;
cbi(PORTD,lcd_rs);
cbi(PORTD,lcd_rw);
sbi(PORTD,lcd_en);
cbi(PORTD,lcd_en);
lcd_busy();
}
lcd_command(0x01);
lcd_senddata('A');
}
}
void lcd_busy()
{
unsigned char i,j;
for(i=0;i<50;i++) //A simple for loop for delay
for(j=0;j<255;j++);
}
void lcd_command(unsigned char a)
{
PORTB=a;
cbi(PORTD,PD1);
cbi(PORTD,PD2);
sbi(PORTD,PD0);
cbi(PORTD,PD0);
lcd_busy();
}
void lcd_senddata(unsigned char a)
{
PORTB=a;
sbi(PORTD,PD1);
cbi(PORTD,PD2);
sbi(PORTD,PD0);
cbi(PORTD,PD0);
lcd_busy();
}
thank you for your help in advance...................
Thu Aug 14 2008, 03:29 am
Does this program actually compile ?
You define init() inside main(), and have an extra bracket !
You define init() inside main(), and have an extra bracket !
Thu Aug 14 2008, 08:59 am
Hi Nikhil...look into what Exp_UK said.
The lcd_command(0x01); looks redundant.
Using 'Check busy-flag' method is always recommended over simple delays.
Try tinkering with the delay(increase it).
Insert a couple of NOPs between LCD_En sbi and cbi.
How have you connected the contrast pin?
The lcd_command(0x01); looks redundant.
Using 'Check busy-flag' method is always recommended over simple delays.
Try tinkering with the delay(increase it).
Insert a couple of NOPs between LCD_En sbi and cbi.
How have you connected the contrast pin?
Thu Aug 14 2008, 09:06 am
hi nikhil,
as u have already defined a function lcd_command() why did u not use it in the init routine ?
just re-orient ur code and check again:
main()
{
init();
lcd_command (0x80);
lcd_senddata('A');
}
init()
{
lcd_command(0x38);
lcd_command(0x0f);
lcd_command(0x01);
lcd_command(0x06);
}
good luck.
as u have already defined a function lcd_command() why did u not use it in the init routine ?
just re-orient ur code and check again:
main()
{
init();
lcd_command (0x80);
lcd_senddata('A');
}
init()
{
lcd_command(0x38);
lcd_command(0x0f);
lcd_command(0x01);
lcd_command(0x06);
}
good luck.
Fri Aug 15 2008, 06:53 pm
i hav changed d lind lcd_command(0x01) to lcd_command(0x80).....forcursor positioning and by giving some more dalay.........i finally got the message
Powered by e107 Forum System