AVR and LCD

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

hi guys, i want to build an application using the STK500 kit and any LCD display..any ideas how i can start? thanks

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

Find "Search" at the top of the page. Click it.
Fill in LCD and other keywords that you can imagine will help locating threads interesting to you(compiler language etc.).
Read the datasheet carefully of the any LCD you decide to buy.
Obide timing diagrams and initializing sequence.

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

"any" lcd can be a text lcd, a monochrome graphics lcd, or a color TFT lcd like for a cell phone. Start with the first one. Its simpler.

Imagecraft compiler user

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

For text LCDs, type HD44780 in the search field.

Regards,
Steve A.

The Board helps those that help themselves.

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

[url]https://www.avrfreaks.net/index.p... ... mp;t=66456 [/url]

Well, not sure if this link will work or not.
I had added it to the tuturial section but when clicking on that link it didn't show up. I guess someone didn't care for it and deleted (?)
Anyhow, it gives a bit of C code (ICCAV) with a companion text note on how it works. It is for the 4 bit mode of the standard Hitachi device HD44780.
I think that may help.
Good Luck

I'll believe corporations
are people when Texas executes one.

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

thanks tubecut.. i tried that link and it didnt work.. can you please upload it again?

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

thanks tubecut.. i tried that link and it didnt work.. can you please upload it again?

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

npat_avr: Yes, as I mentioned I could not locate it until I did a search of all post. I had placed it in the tutorial section. I will look a little later and see if I can just get the two files, the program (ICCAVR) and the text file that explained what I had done. THe biggest problem I have had as well as others has been to get the timing correct and that first initialization completed correctly.
If I can recover the tutorial files I will repost.
There are some really good tutorials in that section.

You can find the file's (one C code and one PDF) by clicking on the member's name and then select view all post selected in the window that opens.
I hope it offers some insight to using the LCD.

EDIT: Looking at the C file I see I did not include
the include files . I don't know if I still have them, recently had to re-install the OS (XP PRO) and some files have vanished. If you have a problem with the setbits I cab probably get that as it should have been included.

Attachment(s): 

I'll believe corporations
are people when Texas executes one.

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

thanks for your help..i will certainly try it..

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

Ok tubecut,I know this has been a while, but I am trying your code. What are the definitions in the LCD_commands.h file? Also I am using WinAVR and gcc. What other commands should I change for this? I have hooked up the LCD(HD44780) to port A as follows:

Port	Header	Function
A0 	1 	LCD D4
A1 	2 	LCD D5
A2 	3 	LCD D6
A3 	4 	LCD D7
A4 	5 	LCD R/~W
A5 	6 	LCD E
A6 	7 	LCD RS
A7 	8 	unused
GND	9 	GND
Vtg	10	Vcc 

I am going by the following link:

http://www.gnu.org/savannah-checkouts/non-gnu/avr-libc/user-manual/group__stdiodemo.html

I am using M16 and STK500. Thanks for your help.

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

I just started a project using the Electronic Assembly DOGM series displays. They are available in 1x8, 2x16, 3x16 lines, pos and neg films with many colors of backlights. They can run parallel or SPI, which is how I'm using mine. It was very easy to setup with the XMega, should be just as easy on any other chip. 8 bucks for the display, and 3 for the backlight. Also runs 5 or 3.3 volts.

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

npat_avr wrote:
Also I am using WinAVR and gcc....

I am using M16 and STK500.


In that case were you aware of this:

http://www.nongnu.org/avr-libc/u...

Which just happens to be a mega16 and an STK500 as well!

While at that link it'd be well worth taking a look through the entire user manual for avr-libc as there's lots of other "good stuff" there too.

EDIT: OK just found your other thread and realise you are aware of that after all.

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

yes I am aware of that link. I was really excited when I saw that. But when I started looking at it I was like wow this is way too complicated. Is there something simple just to check if the LCD is working or not? Something like storing a string say "hello world" in the EEPROM and display it on the LCD? Do I have to use the UART to do this?

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

I found something on AVRBeginners.net. Will give that a try. Thanks.

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

I don't see how the avr-libc example could be much simpler - the whole point of the pre-written code is that you don't HAVE to understand it if you don't want to (or just begin to understand it later when you have more confidence about what's going on). The bottom line is that the HD44780 init sequence (and especially it's important timing requirements) IS complex - there's no getting away from that. If anything the avr-libc example is perhaps too simple - when I used it I had to flesh it out with some "escape sequences" to do things like cursor positioning, line clearing and so on. But the great thing about is is that it simply just works.

Cliff

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

Quote:

Is there something simple just to check if the LCD is working or not?

Yes.

4-bit version here: https://www.avrfreaks.net/index.p...
8-bit version here: https://www.avrfreaks.net/index.p...

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]

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

Wouldnt it be great if there was a place on avrfreaks for code examples?

Imagecraft compiler user

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

Quote:

Wouldnt it be great if there was a place on avrfreaks for code examples?

You mean the Tutorial Forum?

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

Thanks, Johann. That's a useful link. I guess Cliff is right there are no shortcuts here. But I would like to understand what I have. Plus I am fighting two battles here; I am new to the LCD and I am trying to understand someone else's code which is a task in itself. Not saying the code is bad or anything.

I know there's probably tons of LCD projects, but I will try and post my project because it is specific to STK500 and M16. (so you gurus won't have to answer the same questions over and over again.. as you did mine.. :)

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

ok i revisited my LCD after some time now. I am using code posted in an earlier post:


/*
Port	Header	Function
A0 	1 	LCD D4
A1 	2 	LCD D5
A2 	3 	LCD D6
A3 	4 	LCD D7
A4 	5 	LCD R/~W
A5 	6 	LCD E
A6 	7 	LCD RS
A7 	8 	unused
GND	9 	GND
VCC	10	Vcc 
*/




#define F_CPU 1000000
#include 
#include 

// Define LCD Register Select as PORTA, 0x10;
#define LCD_RS 7
// Define LCD Read/Write as PORTA, 0x20;
#define LCD_RW 5
// Define LCD Enable as PORTA, 0x40;
#define LCD_E 6

// DISPLAY ON, 2 LINE MODE
#define   PWR_CMD1   0x20
#define   PWR_CMD2   0x20
#define   PWR_CMD3   0xC0

// DISPLAY ON, CURSOR ON, BLINK ON
#define   DL_CMD1   0x00
#define   DL_CMD2   0xF0

// CLEAR DISPLAY COMMAND     
#define CLR_DSP1 0x00
#define CLR_DSP2 0x10

// ENTRY MODE SET
#define ENT_MOD1 0x00
#define ENT_MOD2 0x60

#define LINE1 0x80
#define LINE2 0xC0

#define NULL 0x00

const char BANNER_1[] = {"Control: 100"};
const char BANNER_2[] = {"Value: 127"};

void LCD_Delay (unsigned long int d);
void LCD_IO_INIT (void);
void LCD_INIT (void);
void LCD_PutCmd (char);
void LCD_PutChar (char);
void LCD_PutString (const char *);

void main (void) {
   DDRA = 0xFF;
   PORTA = 0xFF;

   LCD_IO_INIT ();
   LCD_INIT ();

   /*
   LCD_PutCmd (LINE1);
   LCD_PutString (result);
   LCD_PutCmd (LINE2);
   LCD_PutString (BANNER_2);
   */
}

void LCD_Delay (unsigned long int d) {
    unsigned long int n;
    for (n = 0; n < d; n++);
}

void LCD_IO_INIT (void) {
    DDRA = 0xFF; // PORTA is the LCD DATA AND CONTROL LINES
    PORTA = 0x00;
    PORTA |= (1<<LCD_RS);
   PORTA |= (1<<LCD_E);
   LCD_Delay (500); // Wait for the up LCD to power up         
}

void LCD_INIT (void) {
   LCD_PutCmd (PWR_CMD1);
   LCD_PutCmd (PWR_CMD2);
   LCD_PutCmd (PWR_CMD3);

   _delay_us(40);
   
   LCD_PutCmd (DL_CMD1);
   LCD_PutCmd (DL_CMD2);

   _delay_us(40);
   
   LCD_PutCmd (CLR_DSP1);
   LCD_PutCmd (CLR_DSP2);

   _delay_ms(2);

   LCD_PutCmd (ENT_MOD1);
   LCD_PutCmd (ENT_MOD2);

    LCD_Delay (500); // Wait for the LCD to boot up   
}
 
void LCD_PutCmd (char c) {
  PORTA &= ~(1<<LCD_RS);
  LCD_Delay (5); // Wait for the proper setup time to respond to the RS control line
  LCD_PutChar(c);
  LCD_Delay (5); // Wait for the proper setup time to respond to the command being applied
  PORTA |= (1<<LCD_RS);
}


void LCD_PutChar (char c) {
    PORTA |= (1<<LCD_E);
    LCD_Delay (5); // Wait for the proper setup time to respond to the E pulse   
    PORTA = c;
    LCD_Delay (5); // Wait for the proper setup time to respond to the character being applied
    PORTA &= ~(1<<LCD_E);
}
 
void LCD_PutString (const char *p) {
    char n = NULL; // Pointer position counter.
    while (p[n] != NULL) // Keep sending data until the NULL character is found.
         LCD_PutChar(p[n++]);
} 

I am using the Orient Display as follows:

http://character-lcd-lcds.shopei...

It is a 2x8 display.

I tried both PortA and PortB and when I turn the power on, there is nothing seen on the LCD display. Is there any simple test to check if the LCD is working or not? Something like putting a high on all PORTB pins and checking to see if the LCD shows anything? I checked both PortA and PortB with LED's and they work just fine. Thanks for your patience..

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

Simply apply power to the LCD (and appropriate voltage on the contrast pin). If the first line is all dark boxes and the second is completely blank, then it is working.

void LCD_Delay (unsigned long int d) { 
    unsigned long int n; 
    for (n = 0; n < d; n++); 
}

If you are using optimization, then this function will do nothing. It will be optimized out. You already have included, why not use it?

void LCD_PutChar (char c) { 
    PORTA |= (1<<LCD_E); 
    LCD_Delay (5); // Wait for the proper setup time to respond to the E pulse    
    PORTA = c; 
    LCD_Delay (5); // Wait for the proper setup time to respond to the character being applied 
    PORTA &= ~(1<<LCD_E); 
} 

You are sending all 8 bits of the data to PORTA, but you also have the control lines on PORTA. This can't possible work. Either use 8 bit mode with the data on one port and the control lines on another port, or use 4 bit mode (which means sending each half of the data separately).

Regards,
Steve A.

The Board helps those that help themselves.

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

The purpose of my demo code was to suply the simples possible program that gets an LCD up and going, and it should help you determining if you got all the wiring up of the LCD corect. Did you try it?

As you yourself has said, you are new to this. Why be stubborn and go for your own solution from the start? You have a lot of things that can go wrong - maybe all at the same time. This inevitabely leads to frustration, wild "shoot-from-the-hip" programming, and ultimately us really having to answer the same questions all over again. And the questions wil essentially be "Why cant I get it working at all?".

It is far easier to start with something that someone else has got going, and then modify it or get inspired by it. That way you are reducing the risk of facing several problems all at once. And when you do face problems your questions here will be "I have X and Y working but am having problems with Z". Much better.

The code I linked to is fairly adoptable to different wire-ups. Everything that needs to be changed is in the beginning of the source file with what I hope is straight-forward comments. Try it.

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]

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

Thanks Steve. I was using the schematic given in the following link:

[url]
http://www.gnu.org/savannah-chec...
[/url]

which has 4 bit data and control on the same port. But yes, you are correct I need to use 4 bit mode in my code.

Thanks for the suggestion,Johann. I will get working on your code to check if my LCD works. I guess I was being stubborn.. :(