Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I can write into the lcd.

Status
Not open for further replies.
Now it's blank. This is my modified code.

//Program to Display string on LCD using AVR Microcontroller (ATmega16)
/*
LCD DATA port----PORT B
signal port------PORT D
rs-------PD0
rw-------PD1
en-------PD2
*/

#include<avr/io.h>
#include<util/delay.h>

#define LCD_DATA PORTB //LCD data port

#define ctrl PORTD
#define en PD2 // enable signal
#define rw PD1 // read/write signal
#define rs PD0 // register select signal

void LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char data);

int main()
{
DDRB=0xff;
DDRD=0x07;
_delay_ms(20);
init_LCD(); // initialization of LCD
_delay_ms(50); // delay of 50 mili seconds
LCD_write_string("Welcome"); // function to print string on LCD
while(1); <-- Insert while loop to prevent program from exiting
}
...
...

That is actually good news, it indicates you were at least partial successful in initializing the LCD. Now as ckshivaram mentioned you need to replace the "return 0;" with a "while(1);" statement.

You never want to allow the program to exit from execution on a device without an OS. What will take control of the execution of processes if it did?

BigDog
 

KS0066 is Samsung equivalent of Hitachi HD44780. the two controllers are identical to each other..

so this is how to initialize the lcd.

PHP:
void inilcd(void)						  // initializing lcd
{
lcd_cmd(0x38);
lcd_cmd(0x0E);
lcd_cmd(0x01);
lcd_cmd(0x06);
}


--------------------------------------I just want to give this also------------------
PHP:
void lcd_data(unsigned char value)		// lcd data write function
{
lcd=value;
rs=1;
rw=0;
en=1;
DelayMs(1);
en=0;
}


PHP:
void lcd_cmd(unsigned char value)		// lcd command write function
{
lcd=value;
rs=0;
rw=0;
en=1;
DelayMs(1);
en=0;
}

I've been using this code for quite some projects...

---------- Post added at 15:47 ---------- Previous post was at 15:46 ----------

You never want to allow the program to exit from execution on a device without an OS. What will take control of the execution of processes if it did?

yeah.. :-D
 

Now it's blank. This is my modified code.

Its good , you have initialized it successfully, thats why lcd goes blank!!!
just make repeat the whole code by adding while(1) just after the program main or as said by ckshivaram. .
 

Hi romel,
Is it working in your hardware with a strobe delay of 1 ms? (as in your data and cmd function)

Just now I tried a large delay (1 ms in strobe)
as below:

PHP:
void LCD_STROBE(void)
	{
	EN = 1;
	__delay_ms(1);
	EN = 0;
	}

But not working!

It is working only if I give a very small delay , say 1 or .5 uS.

I am using 4 bit mode. But any way I don't know if it works or not in 8 bit mode (hardware).
Did you checked it in hardware ?
 

I have spent an entire day on this but in vain. There is no improvement at all. The output from the microcontroller is perfect and correct. The LCD is impassive. It's blank and there is no output at all. I have used potentiometer also. I tried this:- I gave supply to pins 1 and 2 of lcd and when I measured the voltages across different pins some pins showed 5v and others 0v. I couldn't understand this. Moreover the pin 3 is always at 5v though I connect 2V to that pin. Having said that the output from the microcontroller is perfect and therefore I have no other option but to blame the lcd. I will check with the new one and reply in this thread/forum.
 

Hi romel,vinod
I think you should use buzy flag it will solve your problem , for code see my last to last post--> lcdready() function is used there..
then try large delay, it will work!!!

Good Luck :)
 

Hi romel,
Is it working in your hardware with a strobe delay of 1 ms? (as in your data and cmd function)

Just now I tried a large delay (1 ms in strobe)
as below:

PHP:
void LCD_STROBE(void)
	{
	EN = 1;
	__delay_ms(1);
	EN = 0;
	}

But not working!

It is working only if I give a very small delay , say 1 or .5 uS.

I am using 4 bit mode. But any way I don't know if it works or not in 8 bit mode (hardware).
Did you checked it in hardware ?

yes.. it's working with my hardware. .anyway you can adjust the initialization if it will not work
 

Ivenki if your pin3(contrast pin) is at 5 volt your lcd will definitely go blank(as these black boxes will only appear if you give them low voltage, giving 5 volt means you have set contrast very low you cannot see the words if you give such high to contrast pin make it as low as black boxes appear) . . check your hardware remove all supply to pin3 and check whether it is not shorted with second pin(i.e vcc), you need to give ground or very low voltage(say 1 volt or less)..

Good Luck :)
 

but still a pot is required as too much contrast will show black boxes even though the characters are printed, you cannot see the characters except the black boxes...

I request you to try a small and simple logic instead of yours to confirm if LCD is working or not...

I somhow have a feeling that LCD has gone bad, as the black box appears only in line 1, and not in second line...........
 
Hello everyone. At last I got the output. You were right bigdogguru the problem was with the delays. I increased the delays from 1 ms to 50 ms and I got the output. I have another question. Is there any difference between atmega 16L and atmega 16A because I have bought 16A instead of L. Anyway it's working.

---------- Post added at 14:43 ---------- Previous post was at 14:42 ----------

Thank you everyone

---------- Post added at 14:45 ---------- Previous post was at 14:43 ----------

Engineers garage site is not opening. Don't know why. But the problem is I have to do the next step in my project which is serial interfacing ( I am not sure about the term). I saw the circuit diagram in that site but the site is not opening. So I need the circuit and the code. Please help me by providing the circuit (it uses max 232) and the code.
 

you can open another thread for serial interfacing because we will be discussing out of the topic if we discuss that here..
 

Hello ivenki,
So finally you solved your problem. Now I think it will be better if you post your final working code here at last. It will be good example program for those beginners who are having the same problem with the same hardware setup.
 

but still a pot is required as too much contrast will show black boxes even though the characters are printed, you cannot see the characters except the black boxes...

hi ckshivaram
Actually, you can see characters(if you directly ground pin3), the black boxes will appear dim and you will see dark characters; here is pic. --> Photo0159.jpg Photo0162.jpg
sorry for my bad camera :twisted:


I somhow have a feeling that LCD has gone bad, as the black box appears only in line 1, and not in second line...........

For jhd162A, if you see black boxes appearing in first line it means that all your connections to lcd are fine. . it shows that your lcd will work , Dont worry :)
Here is pic --> Photo0160.jpg



Hello everyone. At last I got the output. You were right bigdogguru the problem was with the delays. I increased the delays from 1 ms to 50 ms and I got the output. I have another question. Is there any difference between atmega 16L and atmega 16A because I have bought 16A instead of L. Anyway it's working.

You guyz are getting such delay problems because you are not using busy flag(i know it will work without it but for better working let lcd interrupt your micro after each command is being sent). .
 

You guyz are getting such delay problems because you are not using busy flag(i know it will work without it but for better working let lcd interrupt your micro after each command is being sent). .

this is good idea.. also explained in the datasheet.
 
Last edited:

I changed nothing in the code except that I increased the delays from 1ms to 50 or 100 ms.

//Program to Display string on LCD using AVR Microcontroller (ATmega16)
/*
LCD DATA port----PORT B
signal port------PORT D
rs-------PD0
rw-------PD1
en-------PD2
*/

#include<avr/io.h>
#include<util/delay.h>

#define LCD_DATA PORTA //LCD data

#define ctrl PORTD
#define en PD2 // enable signal
#define rw PD1 // read/write signal
#define rs PD0 // register select signal

void LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char data);

int main()
{
DDRA=0xff;
DDRD=0x07;
_delay_ms(100);
init_LCD(); // initialization of LCD
_delay_ms(50); // delay of 50 mili seconds
LCD_write_string("Welcome"); // function to print string on LCD
return 0;
}

void init_LCD(void)
{
LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode
_delay_ms(50);

LCD_cmd(0x01); // clear LCD
_delay_ms(50);

LCD_cmd(0x0E); // cursor ON
_delay_ms(50);

LCD_cmd(0x80); // ---8 go to first line and --0 is for 0th position
_delay_ms(50);
return;
}

void LCD_cmd(unsigned char cmd)
{
LCD_DATA=cmd;
ctrl =(0<<rs)|(0<<rw)|(1<<en);
_delay_ms(50);
ctrl =(0<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return;
}

void LCD_write(unsigned char data)
{
LCD_DATA= data;
ctrl = (1<<rs)|(0<<rw)|(1<<en);
_delay_ms(50);
ctrl = (1<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return ;
}

void LCD_write_string(unsigned char *str) //store address value of the string in pointer *str
{
int i=0;
while(str!='\0') // loop will go on till the NULL character in the string
{
LCD_write(str); // sending data on LCD byte by byte
i++;
}
return;
}
 

Here is your code for lcd using busy flag :
----------------------------------------------------------------------------------------------------------------------------------
//Program to Display string on LCD using AVR Microcontroller (ATmega16)
/*
LCD DATA port----PORT A
signal port------PORT D
rs-------PD0
rw-------PD1
en-------PD2
*/

#include<avr/io.h>
#include<util/delay.h>

#define LCD_DATA PORTA //LCD data

#define ctrl PORTD
#define en PD2 // enable signal
#define rw PD1 // read/write signal
#define rs PD0 // register select signal

sbit busy = PA7; //busy bit of lcd(D7 of lcd 14th pin)or use [#define busy PA7]

void LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char data);

void lcdready();

int main()
{
DDRA=0xff;
DDRD=0x07;
_delay_ms(100);
init_LCD(); // initialization of LCD
_delay_ms(50); // delay of 50 mili seconds
LCD_write_string("Welcome"); // function to print string on LCD
return 0;
}

void init_LCD(void)
{
LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode
_delay_ms(50);

LCD_cmd(0x01); // clear LCD
_delay_ms(50);

LCD_cmd(0x0E); // cursor ON
_delay_ms(50);

LCD_cmd(0x80); // ---8 go to first line and --0 is for 0th position
_delay_ms(50);
return;
}

void LCD_cmd(unsigned char cmd)
{
lcdready();
LCD_DATA=cmd;
ctrl =(0<<rs)|(0<<rw)|(1<<en);
_delay_ms(50);
ctrl =(0<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return;
}

void LCD_write(unsigned char data)
{
lcdready();
LCD_DATA= data;
ctrl = (1<<rs)|(0<<rw)|(1<<en);
_delay_ms(50);
ctrl = (1<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return ;
}

void LCD_write_string(unsigned char *str) //store address value of the string in pointer *str
{
int i=0;
while(str!='\0') // loop will go on till the NULL character in the string
{
LCD_write(str); // sending data on LCD byte by byte
i++;
}
return;
}

void lcdready()
{
busy = 1;
rs = 0;
rw = 1;
while(busy==1)
{

en = 0;
_delay_ms(1);
en = 1;

}

return;

}

there is no change in your hardware, i have just added lcdready function in your program
Try this using different delay or delay you were using earlier when lcd is not working, i bet it will work now!!! :twisted:
 

hello Ivenki
I think it is not good to use 50 ms everywhere. Because you are wasting time in loops....
Just think if you need to display a string 'hello world' then it will take 1 second to display the string, according to your program!!!
 

yes.. that's a waste of time.. in my case it's still working without that much of delay.. I just added 5ms delay after the initialization.. hihi :twisted:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top