Discussion in "AVR Discussion Forum" started by    Nikhil K'wal    Aug 14, 2008.
Thu Aug 14 2008, 02:53 am
#1
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...................
Thu Aug 14 2008, 03:29 am
#2
Does this program actually compile ?

You define init() inside main(), and have an extra bracket !
Thu Aug 14 2008, 08:59 am
#3
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?
Thu Aug 14 2008, 09:06 am
#4
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.


Fri Aug 15 2008, 06:51 pm
#5
thnx 2 all of u........finally i got the message on LCD...........
Fri Aug 15 2008, 06:53 pm
#6
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
Sun Aug 17 2008, 07:55 pm
#7
[topic moved to avr discussion forum]
 Nikhil K'wal like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

MichaelGot
Tue May 14 2024, 04:08 pm
FrankTrelm
Tue May 14 2024, 10:39 am
BillyTum
Tue May 14 2024, 09:08 am
Loganbag
Tue May 14 2024, 04:05 am
MichaelMog
Tue May 14 2024, 03:58 am
ThomasGaxaW
Mon May 13 2024, 05:33 pm
RobertInfup
Mon May 13 2024, 04:28 pm
Joshuatem
Mon May 13 2024, 08:30 am