20x4 LCD with atmega2560

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone,

 

I am trying a piece of code to make a 20x4 LCD to work with atmega2560. Lcd shows nothing at all. Am i doing something wrong in the code or in the hardware?

 

Hardware:

RS Connected to Port L 0

Enable Connected to Port L 1

db4 - db7 connected to pin 2 - pin 5 port L

 

#define F_CPU 16000000UL

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

#define MrLCDsDataDirection DDRL
#define MrLCDsControl PORTL
#define Lightswitch 1//enable
#define BipolarMood 0//reset
#define ReadWrite 7
#define MrLCDsMask |= (1<<Lightswitch | 1<<BipolarMood)

void Check_IF_Busy();
void Peek_A_Boo(void);
void Send_A_Command (unsigned char command);
void Send_A_Character (unsigned char character);

int main(void)

{
    MrLCDsDataDirection |= (1<<Lightswitch | 1<< BipolarMood);
    //_delay_ms(15);
    
    Send_A_Command(0x01); // clear the screen
    //_delay_ms(2);
    Send_A_Command(0x38); // clear the screen
    //_delay_us(50);
    Send_A_Command(0b00001110<<2); // clear the screen
    //_delay_us(50);
    
    Send_A_Character(0x41); //display character
    Send_A_Character(0x65); //display character
    Send_A_Character(0x4E); //display character
    Send_A_Character(0x0B); //display character
    Send_A_Character(0x69); //display character
    Send_A_Character(0x77); //display character
    Send_A_Character(0x83); //display character
    
    while (1) 
    {
        //
    }
    
}////////

void Check_IF_Busy()
{
    //
    MrLCDsDataDirection = 0;
    MrLCDsControl &= ~ 1<<BipolarMood;
    
    while (MrLCDsControl >= 0x80 ) //pin db7 is high 0b10001000 0x80
    
    {
        Peek_A_Boo();
    }
    
    MrLCDsDataDirection = 0XFF; 
    
    
    
}

void Peek_A_Boo()
{
        MrLCDsControl |= (1<<Lightswitch);
        asm volatile ("nop");
        asm volatile ("nop");        
        MrLCDsControl &= ~(1<<Lightswitch);
    
}
void Send_A_Command (unsigned char command)
{
        MrLCDsControl = command;
        MrLCDsDataDirection &= ~ (1<<BipolarMood);
        Peek_A_Boo();
        MrLCDsControl = 0;
}
void Send_A_Character (unsigned char character)
{
        MrLCDsControl = character;
        MrLCDsDataDirection |= (1<<BipolarMood);
        Peek_A_Boo();
        MrLCDsControl = 0;
}





 

This topic has a solution.

Jessi

Last Edited: Tue. May 30, 2017 - 10:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the search function of this site was actually working you could quickly locate previous threads on this MrLcd code library. You would have found very quickly that the general opinion is that it is crap and stupid. But since the search function here at AVRfreaks is broken, I'm telling you this instead. Do yourself a favour and find another LCD library. There are several.

 

I'd be surprised if anyone here would be interested in talking about something so silly as e.g. naming the Enable signal LightSwitch instead of ... uhmmm... "Enable". Not to mention "BipolarMood".

 

This stuff surfaces here not more often than maybe once a year or so nowadays. Where did you dig this up? Did someone recommend it?

 

Here's just one alternative: http://homepage.hispeed.ch/peter...

 

Have you looked in the "Projects" section here at AVRfreaks? There are projects from e.g. users 'alank2' and 'geckosenator' that, IIRC, are good. The thing to put into the search box in the projects section is "44780", leave all other settings to their defaults.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Sun. May 28, 2017 - 09:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is a 16 years old thread!! I'll try to split it into a new topic and fix the code.

 

Please use the code button <> when posting code.

 

Edit Thread  split but may have lost some code in the format, please check it and if it has been chopped just re-post the original code in the existing code box.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sun. May 28, 2017 - 10:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 If you are using a Mega2560 then it is probably on an Arduino board.   If it isn't, then I suggest that you get one of the Arduino Mega2560 boards that are available on eBay for about $9 USD.  Then you can use all the available Arduino libraries on this hardware platform to develop your application.   When finished, use ISP to load the working application hex file into the non-Arduino 2560 using Arduino's Sketch/Export Binary and AVRdude.

 

Check "The Arduino Cookbook" for the code to make double-sized digits on an LCD.   Useful and well-done.

 

Without using a library,a 20x4 LCD has non-intuitive addresses to write the data that you wish to display as characters on the LCD.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:

If the search function of this site was actually working you could quickly locate previous threads on this MrLcd code library. You would have found very quickly that the general opinion is that it is crap and stupid. But since the search function here at AVRfreaks is broken, I'm telling you this instead. Do yourself a favour and find another LCD library. There are several.

 

I'd be surprised if anyone here would be interested in talking about something so silly as e.g. naming the Enable signal LightSwitch instead of ... uhmmm... "Enable". Not to mention "BipolarMood".

 

This stuff surfaces here not more often than maybe once a year or so nowadays. Where did you dig this up? Did someone recommend it?

 

Here's just one alternative: http://homepage.hispeed.ch/peter...

 

Have you looked in the "Projects" section here at AVRfreaks? There are projects from e.g. users 'alank2' and 'geckosenator' that, IIRC, are good. The thing to put into the search box in the projects section is "44780", leave all other settings to their defaults.

 

“Any fool can make something complicated. It takes a genius to make it simple.”

Jessi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

Hello,

 If you are using a Mega2560 then it is probably on an Arduino board.   If it isn't, then I suggest that you get one of the Arduino Mega2560 boards that are available on eBay for about $9 USD.  Then you can use all the available Arduino libraries on this hardware platform to develop your application.   When finished, use ISP to load the working application hex file into the non-Arduino 2560 using Arduino's Sketch/Export Binary and AVRdude.

 

Check "The Arduino Cookbook" for the code to make double-sized digits on an LCD.   Useful and well-done.

 

Without using a library,a 20x4 LCD has non-intuitive addresses to write the data that you wish to display as characters on the LCD.

 

Thank you Simonetta for a kind reply. I just ordered an Arduino board as you recommended. I doubt that its gonna solve my problem as i think the problem lies in pin definitions. 

Jessi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you see two rows of dark boxes on the uninitialized display, indicating a proper contrast circuit?

http://www.avrfreaks.net/comment...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
display, indicating a prop
Hi theusch yes i can see them

Jessi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i wonder where freaks are? 

Jessi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jessi wrote:

i wonder where freaks are? 

If you're asking me: I left this thread, since my seriously meant advice was met with quite a snide remark.

 

I'll repeat: The MrLcd code is crap.

 

Also, your init sequence is not correct, and the comments are misleading:

    Send_A_Command(0x01); // clear the screen
    //_delay_ms(2);
    Send_A_Command(0x38); // clear the screen
    //_delay_us(50);
    Send_A_Command(0b00001110<<2); // clear the screen
    //_delay_us(50);

Either 0x01 or 0x38 is a ClearScreen. Not both. (0b00001110<<2 is just 0x38 in a different notation..) 

 

And it might be that the delays you've commented out are crucial.

 

I'm out. Again.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Mon. May 29, 2017 - 05:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:

jessi wrote:

i wonder where freaks are? 

If you're asking me: I left this thread, since my seriously meant advice was met with quite a snide remark.

 

I'll repeat: The MrLcd code is crap.

 

Also, your init sequence is not correct, and the comments are misleading:

    Send_A_Command(0x01); // clear the screen
    //_delay_ms(2);
    Send_A_Command(0x38); // clear the screen
    //_delay_us(50);
    Send_A_Command(0b00001110<<2); // clear the screen
    //_delay_us(50);

Either 0x01 or 0x38 is a ClearScreen. Not both. (0b00001110<<2 is just 0x38 in a different notation..) 

 

And it might be that the delays you've commented out are crucial.

 

I'm out. Again.

Thank you for this "bit" of guidance. I was not here to market mrlcd lib but to learn more about it. The idea was to engage a practical learning on how LCD's work rather than simply using someones library and display characters. 

 

"A candle looses nothing by lighting another candle"

 

:)

Jessi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"A candle looses nothing by lighting another candle"

Actually it does, it loses some heat while lighting up the other candle's wick. And depending on how it is being use it can also lose some wax.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

"A candle looses nothing by lighting another candle"

Actually it does, it loses some heat while lighting up the other candle's wick. And depending on how it is being use it can also lose some wax.

it will loose its wax anyways. and it gains heat while lighting another candle...:) you can conduct an experiment.

Jessi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jessi wrote:
Thank you for this "bit" of guidance. I was not here to market mrlcd lib but to learn more about it. The idea was to engage a practical learning on how LCD's work rather than simply using someones library and display characters.

 

Johan has tried to be helpful.    I suggest that you look at the well written libraries in his link.

 

I avoid replying to a "MrLcd" thread.   I suspect that most members behave the same way.

I see little point in going through every mistake in "MrLcd".   Especially when an OP appears to ignore advice.

 

Yes,  I think that learning "how to use" a proven library is an important lesson.    There is no need to understand how the black box works.    Just obey the rules for "what input is allowed" to go into the black box.

 

If you really want to learn how to make your own black box,   you study the source code of the proven library.   Understand how the code works.   And then try to write it yourself "under Exam conditions".

 

It seems wise to study a good implementation as part of your learning process.

I suppose that you could start with a bad example (mrLcd) and attempt to fix it yourself.    But this would be a secondary exercise after you have succeeded with the proven strategy.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

jessi wrote:
Thank you for this "bit" of guidance. I was not here to market mrlcd lib but to learn more about it. The idea was to engage a practical learning on how LCD's work rather than simply using someones library and display characters.

 

Johan has tried to be helpful.    I suggest that you look at the well written libraries in his link.

 

I avoid replying to a "MrLcd" thread.   I suspect that most members behave the same way.

I see little point in going through every mistake in "MrLcd".   Especially when an OP appears to ignore advice.

 

Yes,  I think that learning "how to use" a proven library is an important lesson.    There is no need to understand how the black box works.    Just obey the rules for "what input is allowed" to go into the black box.

 

If you really want to learn how to make your own black box,   you study the source code of the proven library.   Understand how the code works.   And then try to write it yourself "under Exam conditions".

 

It seems wise to study a good implementation as part of your learning process.

I suppose that you could start with a bad example (mrLcd) and attempt to fix it yourself. But this would be a secondary exercise after you have succeeded with the proven strategy.

 

David.

Hi david, i tried to follow this example from newbie hack and he showed a working code using similar kind of code. I definitely have some errors in this code but these errors are not in result of var names such as enable being labled as"lightswitch"  as johan emphasized upon. 

Jessi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At this point in time you probably don't know if you've got hardware problems, software problems or both. You want to minimise the unknowns otherwise you'll run around in circles. You could download the Arduino tools, load up a lcd sketch, generate a hex file that has a reasonable chance of working then get that working. That rules out hardware problems. Then you can concentrate on the software. Seems 'everyone' wants to 'learn' about lcds. They're a fiendish contraption that are designed to trip ip even the most experienced engineer. Search for the number of questions we've had like yours.....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

At this point in time you probably don't know if you've got hardware problems, software problems or both. You want to minimise the unknowns otherwise you'll run around in circles. You could download the Arduino tools, load up a lcd sketch, generate a hex file that has a reasonable chance of working then get that working. That rules out hardware problems. Then you can concentrate on the software. Seems 'everyone' wants to 'learn' about lcds. They're a fiendish contraption that are designed to trip ip even the most experienced engineer. Search for the number of questions we've had like yours.....

 

great solution proposed kartman, I have already done that successfully. I dont have any hardware problems.

Jessi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jessi wrote:
I was not here to market mrlcd lib but to learn more about it.

You are missing Johan's point.

 

The point is that "mrlcd lib" is something to avoid - not something to learn about!

 

http://www.avrfreaks.net/comment...

Last Edited: Tue. May 30, 2017 - 07:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

jessi wrote:
I was not here to market mrlcd lib but to learn more about it.

You are missing Johan's point.

 

The point is that "mrlcd lib" is something to avoid - not something to learn about!

 

 

ok but he should learn how to speak to a woman. 

i thought this forum will provide solution to problems but its the opposite here. Rather than discussing how an lcd works everyone is talking about irrelevant stuff. To hell with mrlcd and to hell with avr freaks. in my experience its just a stupid site where people are making arguments on the name of variables rather than discussing about how a thing should be. 

 

By the way i have already solved the prob, if someone wants to learn how to do this email me at jessi.wyne@gmail.com

 

 

 

 

Jessi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

jessi wrote:

I was not here to market mrlcd lib but to learn more about it.

 

You are missing Johan's point.

 

The point is that "mrlcd lib" is something to avoid - not something to learn about!

 

http://www.avrfreaks.net/comment...

the actual point was not about MrLCD it was about the LCD

Jessi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Jessi, realise we see much the same problem twice a week. As previously mentioned, start with a known good implementation to give yourself a baseline and work back from there. Or if you want to work from ground zero, get the hd44780 data sheet and work from that- but assumes you can read datasheets and interpret the information.
So starting with suspect code and saying it doesn't work is not a winning strategy. Unfortunately, you weren't happy with our service but i'd suggest you review the role you played as well. It is a fine art to formulate your question to get the response you expect.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
So starting with suspect code and saying it doesn't work is not a winning strategy. Unfortunately, you weren't happy with our service but i'd suggest you review the role you played as well. It is a fine art to formulate your question to get the response you expect.

 

I think freaks are really getting old and loosing their energy and passion to do more. Currently i know for sure that avr freak forums are of no use at-least for me as they failed to teach one simple example of how an LCD works with an AVR.

Scroll up and you will know how much your freaks have contributed in sorting out a simple LCD problem... 

 

Mr. Moderator 

Out there exists some good candles who don't lose their heat while lighting other candles.

 

Jessi

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well Jessi... if that is even your name.... you make it clear that the people here have not helped you so perhaps you should go elsewhere with your questions.

 

Locked.

 

Ross McKenzie ValuSoft Melbourne Australia

Topic locked