[TUT] LCD tutorials - updated

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

LCD Tutorial

This tutorials is for people who like to use their LCD without understanding much about the working part of the LCD. This is my first attempt to write a tutorial so please bear my mistakes and point out if any occurs.

This tutorial explains how to program the LCD in an abstract view i.e. directly using the library functions without going into the depth of it.

Firstly I am using JHD162A LCD module which is compatible with HD44780. Now the LCD can come in various sizes. I am using a 16x2 LCD, which means 2 lines are there and each line can display a maximum of 16 characters. The LCD can be used in 4 bit mode or 8 bit mode depending upon your pin availability on our microcontroller or development board.
In 8 bit mode 8 data pins are there which sends a character(1 byte) directly to the LCD. In 4 bit mode the upper nibble is sent first and then lower nibble.
The 16 pins on JHD162A are

1  Vss
2  Vcc
3  Vee
4  RS
5  R/W
6  EN
7  DB0
8  DB1
9  DB2
10 DB3
11 DB4
12 DB5
13 DB6
14 DB7
15 LED+
16 LED-

DB0-DB7: Data Pins( use DB4-DB7 in 4 bit mode)

RS(Register Select) : 1 - Data is sent , 0 - Command is sent .

R/W(Read/Write) :1 - Read the LCD , 0 - Write to LCD. this pin is almost always low.

EN(Enable): to enable an operation . first make low(0) to send data and then set the other two control lines and when they are configured, bring EN high (1) and wait for the minimum amount of time required by the LCD and bring it low (0) again.

Vee: Contrast Adjust Pin. connect to a potentiometer.

Now to use it in 8 bit mode we need 8 data pins DB0-DB7 and 3 control pins. So total 11 pins are required. In 4 bit mode, we need DB4-DB7 and 3 control pins. So total 7 pins and required.Note that the data pins DB0-DB3 are left open and are not shorted to ground.The Vee pin is connected to the potentiometer and is varied from Vcc and Gnd. Pin 15 and 16 are used for backlight of LCD and can be connected to Vcc and Gnd respectively.

So till now, you have the basic idea to setup an LCD and connect it with your microcontroller. In this tutorial I am using LCD in 4 bit mode.

Before writing any code, first download the library written by Peter Fleury from his homepage - http://www.jump.to/fleury. The library written by him has excellent functions by which we can directly control the LCD without knowing what is going behind the scenes and using the built-in functions provided in the library.

First set the mode as 4 bit mode by writing LCD_IO_MODE=1 in the lcd.h file.

Change LCD_PORT if you want to use a different port for the LCD pins.

The four LCD data lines and the three control lines RS, R/W, EN can be on the same port or on different ports. Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on different ports.

int main(void)
{	
  lcd_init(LCD_DISP_ON);	/* initialize display, cursor off */
    while (1)					/* loop forever */ 
       {                           
       	 lcd_clrscr();                   /* clear the screen*/
	 lcd_puts("test program");  /* displays the string on lcd*/
 	_delay_ms(50);
        }	
}

This codes displays "test program" on your LCD.(without quotes) I have used delay because some time is required for the display to settle in.

The functions in the library which could be used are -

lcd_init (uint8_t dispAttr)-initialize display and select type of cursor.
lcd_putc(char c) -  to print a single charater on current cursor position
lcd_puts(const char* s) - to print a string without auto linefeed.
lcd_gotoxy(uint8_t x, uint8_t y) - xth position on the yth line. X varies from 0 to 15 and y is 0 or 1.
lcd_clrscr() - clears the screen .
lcd_home() "“ goes to the initial position, i.e. equivalent to lcd_gotoxy(0,0) 
lcd_puts_p (const char *progmem_s) - display string from program memory without auto linefeed. 
lcd_command (uint8_t cmd)-send LCD controller instruction command. 
lcd_data (uint8_t data)-send data byte to LCD controller

With the help of these basic functionalities you can display text on your LCD on both lines.

Please beware of delays. Proper delays are required for the text to properly display on screen or else it will blink or just displays once and go away. Play around with different types of functions given in the library.

e.g. lcd_command(LCD_MOVE_DISP_RIGHT) "“ moves the whole display one position right side.

Experiment it to display various kinds of symbols and text. One good code would be to show your text moving on the LCD. i.e. it enters from right and leaves from left "“ kind of rolling effect.

Problems which I have faced or mainly occurs with LCD:

The first problem to arise is you don't see anything on LCD although its on "“ change the value of contrast using potentiometer.

Black squares are seen "“ See that proper connection is there. i.e. if any two pins touch each other than this may occur. Also see the contrast pin.

Displays blinks- use a proper delay. Try out different values of delays

Typical symbols are displayed instead of text "“ see the connections again. If two pins are shorted, this might occur.

Hope you like and understood the tutorial and start programming the LCD and play around with it. Please give your feedback so that i can improve it.

Last Edited: Sun. Aug 2, 2009 - 06:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I used your code

#include 
#include 
#include "lcd.h"

int main(void)
{
lcd_init(LCD_DISP_ON); 					/* initialize display, cursor off */
while (1) 								/* loop forever */
{
lcd_clrscr(); 							/* clear the screen*/
lcd_puts(“test program”); 				/* displays the string on lcd*/
_delay_ms(50);
}
} 

with my atmega128:


And it's not working :/ (no reaction on LCD), can you help me pls?

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

it's working now :)

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

what was the error or problem?

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

I made an mistake setting pins for RS :)

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

Does anyone have a good link to the lcd lib???

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

link It's just a . in the end of link in the first post.

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

Hi, this is very good LCD library, library good work on my Atmega 8 or 16, bud when I use Atmega 128 don't work:( (Display don't initialize). Is any special setting in lcd.h or other setting for atmega128 ? I use port A,B,C,D or E (not F or G).
Thanks for answers:)

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

Quote:
when I use Atmega 128

mega103 compatibility fuse?

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

check the connections and modify the port connection list in lcd.h. i was using for PORTB. so if you want to use for other ports just change in .h file

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

hi, i just started manipulating my lcd for doing different works and i will share some with you and hope you share some with me so we can all learn

i tested few codes with my name and tried to shift it left or right i.e tried to make a rolling effect- text enters from one side and leaves from other. these codes i tried didn't work well althought i learnt new things and understood the working of lcd properly

// this program moves display right/left and some trouble shooting

#include 'lcd.h'
#include
#include
#include
#include
#include

void main(void)
{
DDRC=0xff;
int i;

lcd_init(LCD_DISP_ON);
lcd_clrscr();

while(1)
{
lcd_clrscr();
lcd_puts("DARSH SHAH");
_delay_ms(50);
for(i=0;i<16;i++)
{lcd_command(LCD_MOVE_DISP_RIGHT);
_delay_ms(50);
}

}

this code writes darsh shah as a string and then it is shifted right one character at a time and out of display.
-----------------------------------------------------------------------------------------------
to go in other direction
for(i=0;i<16;i++)
{
lcd_command(LCD_MOVE_DISP_LEFT);
_delay_ms(50);
}
this code writes darsh shah as a string and then it is shifted left one character at a time and out of display.
-----------------------------------------------------------------------------------------------

if i write i<20 then after 16 characters which is lenght of LCD , blank spaces are shown for 4 spaces.

-----------------------------------------------------------------------------------------------

for continuous display some algorithm is needed.
array[]= darsh shah
for(i=0;i<16;i++)
{lcd_putc(array[i]);
_delay_ms(50);
lcd_command(LCD_MOVE_DISP_RIGHT);
_delay_ms(50);
}

then after 10 characters(darsh shah) junk letters are printed.total 6 junk letters.
in this code what happens is that first d is printed and then shifted one space and then a.
so afer darsh sh the text moves out as 8 characters+8 shifts. hence we want the last letter to print first.

------------------------------------------------------------------------------------------------
array[]=darsh shah
for(i=0;i<10;i++)
{lcd_putc(array[9-i]);
_delay_ms(50);
lcd_command(LCD_MOVE_DISP_RIGHT);
_delay_ms(50);
}

here in this code, h is printed then space , then ha then space, then hah then space and similarly
hahs hsrad will be printed but only hahs hs is printed due to space i.e. 16 characters.

-----------------------------------------------------------------------------------------------
array[]=darsh shah
for(i=0;i<10;i++)
{lcd_putc(array[9-i]);
_delay_ms(50);
lcd_command(LCD_MOVE_CURSOR_LEFT);
_delay_ms(50);
lcd_command(LCD_MOVE_DISP_RIGHT);
_delay_ms(50);
lcd_command(LCD_MOVE_CURSOR_LEFT);
_delay_ms(50);
}

in this code h is printed in first line and rest of it comes in 2nd line. so i need to figure it how to make it stay only on first line.

-----------------------------------------------------------------------------------------
array[]=darsh shah
for(i=0;i<26;i++)
{i<10?lcd_putc(array[9-i]):lcd_putc(' ');
_delay_ms(50);
lcd_command(LCD_MOVE_CURSOR_LEFT);
_delay_ms(50);
lcd_command(LCD_MOVE_DISP_RIGHT);
_delay_ms(50);
lcd_command(LCD_MOVE_CURSOR_LEFT);
_delay_ms(50);

}

the above code writes darsh shah as stated in above programs and now it also puts blank spaces till all the text is shifted to right and goes out of display section.

----------------------------------------------------------------------------------------------

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

for a complete rolling effect, i got this code. i dont know whose it is but i found it on net. so i claim that it is not mine but works very well.

one thing is that if text is less than 16 characters(lenght of lcd) then the beauty of code is not seen as whole lcd is not covered. for more characters it works beautifully.

#define STRING_LENGTH 27
#define LCD_MAX 15

void main()
{char array[STRING_LENGTH] = { "darsh shah loves avrfreaks" };
int i,j;
int start;
int end;

lcd_init(LCD_DISP_ON_CURSOR);
lcd_clrscr();
while(1)
{
for ( j = 0; j < STRING_LENGTH; j++ )
{
if ( j >= LCD_MAX )
lcd_gotoxy( 0, 0 );
else
lcd_gotoxy( LCD_MAX - j, 0 );

start = (j <= LCD_MAX) ? 0 : (j - LCD_MAX);

end = (j <= LCD_MAX) ? j : (start + LCD_MAX);

if ( end >= STRING_LENGTH )
end = STRING_LENGTH - 1;

for ( i = start; i <= end; i++ )
lcd_putc( array[i] );

_delay_ms(100);
}

lcd_clrscr();
}
}

this code does it. the text can be of any length u want. one optimixation required is that after the text ends, the screen is cleaared and again the rolling text starts.
--------------------------------------------------------------------------------------------------------------

hope you also contribute your codes so we can learn and experiment!!

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

ATMEL--Heart Beat
Nothing Impossible

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

So.. m.b. i'm dumb, but it's not working. No reaction at all.

I download library written by Peter Fleury, open his test_lcd.c and load it into AVRStudio 4.
It's compiled.
After that i take WH1602b LCD display (HD44780 based) and connect it to At90usbkey as shown at "Home > AVR Microcontroller Projects > Interfacing a HD44780 Based LCD to an AVR" fig. 2 - using 4-bits interface.

Port A using.
Connections tested 3+ counts.
Vcc = usb +5v (+4.8v tested).
in lcd.h i change XTAL from 4000000 to 8000000, as on usbkey 8Mh quarts

It's not working. No response. (by the way, LCD is good - tested at another plate. not avr)

Why?

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

Quote:
I download library written by Peter Fleury, open his test_lcd.c and load it into AVRStudio 4.
It's compiled.

But did you set the defines in LCD.h to match your setup?

Regards,
Steve A.

The Board helps those that help themselves.

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

Koshchi wrote:
Quote:
I download library written by Peter Fleury, open his test_lcd.c and load it into AVRStudio 4.
It's compiled.

But did you set the defines in LCD.h to match your setup?

Ports? Sure! So, i use port A as show on fig., and i dn't need to change anythng.

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

Hi all.
I get the library from his website, I make the project in AvrStudio4, but i get a lots of errors, and warnings.
Code:

Build started 26.8.2009 at 10:41:50
avr-gcc -mmcu=atmega128 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT lcdTest.o -MF dep/lcdTest.o.d -c ../lcdTest.c
In file included from ../lcdTest.c:16:
../lcd.h:22: error: expected declaration specifiers or '...' before 'FILE'
../lcdTest.c: In function 'main':
../lcdTest.c:20: error: 'LCD_DISP_ON' undeclared (first use in this function)
../lcdTest.c:20: error: (Each undeclared identifier is reported only once
../lcdTest.c:20: error: for each function it appears in.)
../lcdTest.c:20: error: too many arguments to function 'lcd_init'
../lcdTest.c:23: warning: implicit declaration of function 'lcd_clrscr'
../lcdTest.c:24: warning: implicit declaration of function 'lcd_puts'
make: *** [lcdTest.o] Error 1
Build failed with 5 errors and 2 warnings...

Why did I get this errors?
P.S. : I have an atmega128 and a 2x12 lcd.

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

Quote:

I get the library from his website

Which file? Who's webbsite?

One thing's for sure - those aren't Pete Fleury's files.

By the way, did you know that GCC comes with some LCD code?

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

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

Quote:
Which file? Who's webbsite?
I took the library from Pete Fleury's website: http://www.jump.to/fleury
Quote:
By the way, did you know that GCC comes with some LCD code?

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


Yes I know, but I don't have any examples, plus that I saw in the avr-gcc help that atmega128 is not included, and because of that I can't compile for atmega128, I got a lot of errors in the usart.c

rm -rf lcd.o hd44780.o lcd1.o uart.o lcd.elf dep/* lcd.hex lcd.eep lcd.lss lcd.map
Build succeeded with 0 Warnings...
avr-gcc -mmcu=atmega128 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT lcd.o -MF dep/lcd.o.d -c ../lcd.c
avr-gcc -mmcu=atmega128 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT hd44780.o -MF dep/hd44780.o.d -c ../hd44780.c
avr-gcc -mmcu=atmega128 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT lcd1.o -MF dep/lcd1.o.d -c ../lcd1.c
avr-gcc -mmcu=atmega128 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT uart.o -MF dep/uart.o.d -c ../uart.c
../uart.c: In function 'uart_init':
../uart.c:30: error: 'UCSRA' undeclared (first use in this function)
../uart.c:30: error: (Each undeclared identifier is reported only once
../uart.c:30: error: for each function it appears in.)
../uart.c:31: error: 'UBRRL' undeclared (first use in this function)
../uart.c:35: error: 'UCSRB' undeclared (first use in this function)
../uart.c: In function 'uart_putchar':
../uart.c:54: error: 'UCSRA' undeclared (first use in this function)
../uart.c:55: error: 'UDR' undeclared (first use in this function)
../uart.c: In function 'uart_getchar':
../uart.c:104: error: 'UCSRA' undeclared (first use in this function)
../uart.c:109: error: 'UDR' undeclared (first use in this function)
make: *** [uart.o] Error 1
Build failed with 9 errors and 0 warnings...

I have an 2*12 lcd, bought from this site: http://www.adelaida.ro/product_info.php?cPath=87_118_275&products_id=7586&osCsid=7b393d7d2884a1c8889d52e9425df74a. His datasheet is here: tp://www.adelaida.ro/adelaida/catalog/pub/TME/lcd/rc1202a-yhy-esx.pdf
When I saw that I got those errors I tried to male my own lcdinit() function.
I use the 8 bit interface(page 16).
Code:

#ifndef F_CPU
   #define F_CPU 4000000UL
#endif
#include 
#include 
#include 

#define DDR          DDRD // setare port
#define PORT         PORTD // setare bit
//definire pini de control
#define PIN          DDRG
#define PortPin      PORTG
#define RS           0
#define RW             1
#define E            2

#define N          0
#define F          0
#define B          1
#define C          1
#define D          1
#define S          1
#define ID          0

void initLCD(void);
void clearDisplay(void);

int main(void){
   
   DDRB |= (1<<PB5) | (1<<PB6);
   TCCR1A |= (1<<COM1A1) | (1<<COM1B1) | (1<<WGM10) | (1<<WGM11);
   TCCR1B |= (1<<CS00);
   OCR1A = 400; // alimentare contrast
   OCR1B = 400; // alimentare led
  
     initLCD();
     clearDisplay();
   PORT |= (1<<7);
a:

goto a;
  return 0;
}
void initLCD(void){
   DDR |= 0xff;
   PIN |= 0x07;
   _delay_ms(50);

   //PortPin |= 0x02;
   PORT |= (1<<5) | (1<<4) | (N<<3) | (F<<2);
   _delay_us(50);   

   PORT |= (1<<5) | (1<<4) | (N<<3) | (F<<2);
   _delay_us(50);

   PORT |= (1<<3) | (B<<2) | (C<<1) | (D<<0);
   _delay_us(50);

   PORT |= (1<<1);
   _delay_ms(5);

   PORT |= (1<<2) | (ID<<1) |(S<<0);
}

void clearDisplay(void){
   PORT |= (1<<0);
}

One row is totaly black:

P.S. : This atmega is new, and I don't set up the fuse bits for an external crystal(because I locked an atmega). I don't know what is the internal frequenci of the RC?

Attachment(s): 

Last Edited: Wed. Aug 26, 2009 - 10:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just took Fleury's code. Did nothing but edit the line in the Makefile to set "MCU = atmega128" and got:

D:\fleury>make

-------- begin --------
avr-gcc (WinAVR 20090313) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling: test_lcd.c
avr-gcc -c -mmcu=atmega128 -I. -gdwarf-2   -Os -funsigned-char -funsigned-bitfie
lds -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=test_lcd.l
st  -std=gnu99 -Wp,-M,-MP,-MT,test_lcd.o,-MF,.dep/test_lcd.o.d test_lcd.c -o tes
t_lcd.o

Compiling: lcd.c
avr-gcc -c -mmcu=atmega128 -I. -gdwarf-2   -Os -funsigned-char -funsigned-bitfie
lds -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=lcd.lst  -
std=gnu99 -Wp,-M,-MP,-MT,lcd.o,-MF,.dep/lcd.o.d lcd.c -o lcd.o

Linking: test_lcd.elf
avr-gcc -mmcu=atmega128 -I. -gdwarf-2   -Os -funsigned-char -funsigned-bitfields
 -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=test_lcd.o  -
std=gnu99 -Wp,-M,-MP,-MT,test_lcd.o,-MF,.dep/test_lcd.elf.d test_lcd.o lcd.o   -
-output test_lcd.elf -Wl,-Map=test_lcd.map,--cref    -lm

Creating load file for Flash: test_lcd.hex
avr-objcopy -O ihex -R .eeprom test_lcd.elf test_lcd.hex

Creating load file for EEPROM: test_lcd.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
        --change-section-lma .eeprom=0 -O ihex test_lcd.elf test_lcd.eep
c:\WinAVR-20090313\bin\avr-objcopy.exe: --change-section-lma .eeprom=0x00000000
never used

Creating Extended Listing: test_lcd.lss
avr-objdump -h -S test_lcd.elf > test_lcd.lss

Creating Symbol Table: test_lcd.sym
avr-nm -n test_lcd.elf > test_lcd.sym

Size after:
test_lcd.elf  :
section           size      addr
.data               42   8388864
.text             1134         0
.debug_aranges      64         0
.debug_pubnames    212         0
.debug_info       1879         0
.debug_abbrev      847         0
.debug_line       1624         0
.debug_frame       256         0
.debug_str         401         0
.debug_loc         708         0
Total             7167



Errors: none
-------- end --------

So where exactly do you think the problem is?

In the files I downloaded Flury's lcd.h has this on line 22:

 4-bit IO port mode (LCD_IO_MODE=1). 8-bit IO port mode not supported.

So if yuou have one that has "FILE" on line 22 I'd suggest it is the WRONG copy of lcd.h (in fact it might be the one from the WinAVR examples)

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

Quote:
I get the library from his website, I make the project in AvrStudio4, but i get a lots of errors, and warnings.
I said that I make the project with avrStudio4. I took only the ."c" and ".h" file.
Quote:
In the files I downloaded Flury's lcd.h has this on line 22:
Code:
4-bit IO port mode (LCD_IO_MODE=1). 8-bit IO port mode not supported.

So if yuou have one that has "FILE" on line 22 I'd suggest it is the WRONG copy of lcd.h (in fact it might be the one from the WinAVR examples)


I know, I did for the 4 bit, but when I saw that I have those errors I tried to make my own lcdinit() function.

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

OK if you want to use AVR Studio, I just did the following using that same set of untouched files I downloaded:

1) start Studio
2) new Project
3) AVR GCC
4) untick the create boxes (I already have directory and files)
5) set location to where the files are
6) next>>
7) AVR Simulator2 + atmega128
8) [finish]
9) In tree at left, right-click "Source files"
10) "Add existing source file(s)"
11) select both lcd.h and test_lcd.h in that directory then [open]
12) Build-rebuild all
13) err...
14) ... that's it....

Build started 26.8.2009 at 12:31:23
avr-gcc  -mmcu=atmega128 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT lcd.o -MF dep/lcd.o.d  -c  ../lcd.c
avr-gcc  -mmcu=atmega128 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT test_lcd.o -MF dep/test_lcd.o.d  -c  ../test_lcd.c
avr-gcc -mmcu=atmega128 -Wl,-Map=fleury.map lcd.o test_lcd.o     -o fleury.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature  fleury.elf fleury.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex fleury.elf fleury.eep || exit 0
avr-objdump -h -S fleury.elf > fleury.lss

AVR Memory Usage
----------------
Device: atmega128

Program:    1176 bytes (0.9% Full)
(.text + .data + .bootloader)

Data:         42 bytes (1.0% Full)
(.data + .bss + .noinit)


Build succeeded with 0 Warnings...

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

I could compile, but why, I did aprox. exactly the same thing.
I make a new project. I use the steps:

Quote:
9) In tree at left, right-click "Source files"
10) "Add existing source file(s)"
11) select both lcd.h and test_lcd.h in that directory then [open]

, and in my "main.c" I copy/paste the "test_lcd.c". But I don't copy the makefile as wel.
In the lcd.h file I modify:

#define LCD_PORT         PORTD        /**< port for the LCD lines   */
#define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */
#define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */
#define LCD_DATA2_PORT   LCD_PORT     /**< port for 4bit data bit 2 */
#define LCD_DATA3_PORT   LCD_PORT     /**< port for 4bit data bit 3 */
#define LCD_DATA0_PIN    0            /**< pin for 4bit data bit 0  */
#define LCD_DATA1_PIN    1            /**< pin for 4bit data bit 1  */
#define LCD_DATA2_PIN    2            /**< pin for 4bit data bit 2  */
#define LCD_DATA3_PIN    3            /**< pin for 4bit data bit 3  */
#define LCD_RS_PORT      LCD_PORT     /**< port for RS line         */
#define LCD_RS_PIN       4            /**< pin  for RS line         */
#define LCD_RW_PORT      LCD_PORT     /**< port for RW line         */
#define LCD_RW_PIN       5           /**< pin  for RW line         */
#define LCD_E_PORT       LCD_PORT     /**< port for Enable line     */
#define LCD_E_PIN        6            /**< pin  for Enable line     */

for port D, and in the test_lcd.c I comented these 2 lines:

    
    //DDRD &=~ (1 << PD2);        /* Pin PD2 input              */
    //PORTD |= (1 << PD2);        /* Pin PD2 pull-up enabled    */

and the wait_until_key_pressed() function, because I don't have a button on my bord.
I did all of that but is still doesn't worcking.
What did I do wrong?

Ok, forget all the thing I said above, now it's worcking. I don't belive. I own you :)
It wasn't worcking because i did not put any voltage on the led and contrast :( .

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

Quote:

I own you

I'm not very good on "urban" but is this the point where I get to say "I pwn you" ? :lol:

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

:)))))))))))))))))))))), ok, if you say so.
Now one more question.
I blocked one of my atmega128, because I did not set the fuses how it should be(with pony prog2000).
I saw on the controler datasheet that it is compatible with atmega103. You have to set the M103C fuse. Bur I do't understand in wich mode it is atmega128, and in wicth mode is atmega103.
And I want to set an external crystal with two C of 22pF.
But I dont now how. I saw in the table from the pdf that fuses “1” means unprogrammed while “0” means programmed, and in the pony prog security bits checked means programmed and unchecked means unprogramed.
I am a litle bit confused. A print screed would be great.
Please send me a link or same documentation.

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

Quote:

Bur I do't understand in wich mode it is atmega128, and in wicth mode is atmega103.

When a mega128 first arrives it has the M103C fuse enabled so behaves as a mega103. Usually the first thing anyone does (having paid all that money for a mega128 they might as well use it!) is to set the M103C fuse inactive. It's bit 1 of the extended fuse byte. By default that byte is 0xFD, set it to 0xFF

As for Ponyprog - I find it horrendously confusing to know which way up the fuse bits are (this is made worse by the fact that they have a tick box here you can invert the sense of the display/input). The best bet is to start by reading the fuse bytes. You know from the datasheet, for example, that the low fuse byte holds 0xE1 with SUT0, CKSEL3, CKSEL2, CKSEL1 active. So see whether Pony prog shows this as ticks against those entries or ticks against the inactive BODLEVEL, BODEN, SUT1 and CKSEL0

Cliff

[this is now off-topic for this LCD tutorial so you really should start a new thread with these questions in AVR Forum]

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

All I get is weird characters.(Asian)
All connections are good, contrast it working.
What could be wrong?

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

if you are using a usart system and displaying output on
lcd then it might be the baud rate problem. else verify the connections and also the delay given. i think you should also modify the library according to your own need.

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

AH! It's all working!!!
2 all other.
Be sure, that pin 3 - contrast adj IS connect to GND
through 3k Ohm. Then all be good.

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

Quote:

Be sure, that pin 3 - contrast adj IS connect to GND
through 3k Ohm. Then all be good.

Pulling it to 0V is not normally sufficient. Usually it needs a small positive voltage to get the contrast right so if Gnd worked for you then you were just lucky!

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

How many LCD libraries are there? Specifically, how does one display int/float values?

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

Quote:

How many LCD libraries are there? Specifically, how does one display int/float values?

There are many, many.

But it's not usually up to the library to display int/float values. Always assuming the library has some form of LCD_putstring() function you just need to use the C standard sprintf():

char buffer[20];

sprintf(buffer, "int=#d, float=#f", 54321, 3.1415926);
LCD_putstring(buffer);

(replace # with percent symbol)

If the LCD library doesn't have an LCD_putstring() but just LCD_putchar() then construct the string function with:

void LCD_putstring(char * str) {
 while (*str) {
   LCD_putchar(*str++);
 }
}

PS If you use GCC things are possibly even easier as you just associate the lowest level LCD_putchar() function with an output file stream, assign this to stdout and then printf() output goes directly via the LCD_putchar() routine. (see example in manual)

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

hey thx for your toturial.

im trying to use and make this work, but it dosen't.

is it a must to use the avr gcc compiler? can't figure it out, so i try to use avr studio or code vision, by opening the lcd_test.c file but it kind of complains about everything... missing headers and other stuf. tryed to download headers like inttypes.h but it also complains about that.

how do your do it? i don't understand the tutorial :/

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

i might occur that you would not have included the header file. Also use lcd.h header file. if these also not work then best way is to copy the contects of lcd.h and lcd_test.c in same the file and compile. i think that would work.

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

What should i do to connect the legs of lcd to my desired legs of my AVR(atmega16)
when i tried to connect it to port c from thence two or three pins(in port C) are not working as output pins..

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

tilak!

Did you disable JTAG? (JTAG sits on 4 of the PORTC pins, and is enabled by default).

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

hey guys, im working with an HD44780 which is interface with an Atmega8 (L). i have downloaded peter fluery codes and setup the lcd accordingly. However, im not so sure how to set all the stuff in the library as i am planning to use the lcd in the 4-bit mode.

Could anyone help me? thanks so much for everything

Mark

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

Well it all hinges around his lcd.h.
The first thing to consider is:

/** 
 *  @name  Definitions for MCU Clock Frequency
 *  Adapt the MCU clock frequency in Hz to your target. 
 */
#define XTAL 4000000              /**< clock frequency in Hz, used to calculate delay timer */

Set the number here to be your CPU frequency in Hertz (and personally I'd suffix the letters "UL" onto the end of the constant too)

If yours is really an HD44780 this doesn't need to change:

/**
 * @name  Definition for LCD controller type
 * Use 0 for HD44780 controller, change to 1 for displays with KS0073 controller.
 */
#define LCD_CONTROLLER_KS0073 0  /**< Use 0 for HD44780 controller, 1 for KS0073 controller */

If your module is 16x2 then these lines should work unchanged, otherwise you may need to set the right values for your panel:

/** 
 *  @name  Definitions for Display Size 
 *  Change these definitions to adapt setting to your display
 */
#define LCD_LINES           2     /**< number of visible lines of the display */
#define LCD_DISP_LENGTH    16     /**< visibles characters per line of the display */
#define LCD_LINE_LENGTH  0x40     /**< internal line length of the display    */
#define LCD_START_LINE1  0x00     /**< DDRAM address of first char of line 1 */
#define LCD_START_LINE2  0x40     /**< DDRAM address of first char of line 2 */
#define LCD_START_LINE3  0x14     /**< DDRAM address of first char of line 3 */
#define LCD_START_LINE4  0x54     /**< DDRAM address of first char of line 4 */
#define LCD_WRAP_LINES      0     /**< 0: no wrap, 1: wrap at end of visibile line */

As you want to use 4-bit leave this as it is:

#define LCD_IO_MODE      1         /**< 0: memory mapped mode, 1: IO port mode */

And the following is the main place where you configure his code:

/**
 *  @name Definitions for 4-bit IO mode
 *  Change LCD_PORT if you want to use a different port for the LCD pins.
 *
 *  The four LCD data lines and the three control lines RS, RW, E can be on the 
 *  same port or on different ports. 
 *  Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on
 *  different ports. 
 *
 *  Normally the four data lines should be mapped to bit 0..3 on one port, but it
 *  is possible to connect these data lines in different order or even on different
 *  ports by adapting the LCD_DATAx_PORT and LCD_DATAx_PIN definitions.
 *  
 */
#define LCD_PORT         PORTA        /**< port for the LCD lines   */
#define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */
#define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */
#define LCD_DATA2_PORT   LCD_PORT     /**< port for 4bit data bit 2 */
#define LCD_DATA3_PORT   LCD_PORT     /**< port for 4bit data bit 3 */
#define LCD_DATA0_PIN    0            /**< pin for 4bit data bit 0  */
#define LCD_DATA1_PIN    1            /**< pin for 4bit data bit 1  */
#define LCD_DATA2_PIN    2            /**< pin for 4bit data bit 2  */
#define LCD_DATA3_PIN    3            /**< pin for 4bit data bit 3  */
#define LCD_RS_PORT      LCD_PORT     /**< port for RS line         */
#define LCD_RS_PIN       4            /**< pin  for RS line         */
#define LCD_RW_PORT      LCD_PORT     /**< port for RW line         */
#define LCD_RW_PIN       5            /**< pin  for RW line         */
#define LCD_E_PORT       LCD_PORT     /**< port for Enable line     */
#define LCD_E_PIN        6            /**< pin  for Enable line     */

As you can see it defaults to PORTA - you may want to change this?

One real nice thing about the Fleury code is that the PORT and bit for each of the 4 data bits and 3 control lines is spearately configurable so you can spread them around the ports of your AVR.

That's pretty much all there is to it.

Cliff

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

Hey Cliff,

thanks so much for the advice! haha i have changed all that is necessary already, though i am still unsure about the LCD_PORT- if i connect my avr_atmega8 (L) PORTD4..7 to DB4..7, would it mean that i have to write

#define LCD_PORT PORTD

Right now, i am experiencing problems with the building process- after building, it ends up with 3 errors:

Build started 26.11.2009 at 10:25:08
avr-gcc -mmcu=atmega8 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=1000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT LCD_testing.o -MF dep/LCD_testing.o.d -c ../LCD_testing.c
avr-gcc -mmcu=atmega8 -Wl,-Map=LCD_testing.map LCD_testing.o -o LCD_testing.elf
LCD_testing.o: In function `main':
D:\AVR\LCD_testing\default/../LCD_testing.c:7: undefined reference to `lcd_init'
D:\AVR\LCD_testing\default/../LCD_testing.c:11: undefined reference to `lcd_clrscr'
D:\AVR\LCD_testing\default/../LCD_testing.c:12: undefined reference to `lcd_puts'
make: *** [LCD_testing.elf] Error 1
Build failed with 3 errors and 0 warnings...
Thanks so much!

Mark

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

But those are just link errors meaning that the source file providing lcd_init(), lcd_clrscr() and lcd_puts() are not being built and linked into the project. I notice that the only input to your link is LCD_testing.o which suggests that you have not added lcd.c to the list of files to be built in the project.

Cliff

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

Hey Cliff,

haha so sorry, i was so stupid not to add the lcd.c. the building suceeded already, however, i am actually seeing a black screen here.

For my connections, i have:
PORTD1: Rs
PORTD2: R/W
PORTD3: E
PORTD4: DB4
PORTD5: DB5
PORTD6: DB6
PORTD7: DB7
- Do i need to change anything in lcd.h, i have left the commands alone, just only set

#define LCD_PORT PORTD

i am using a 4-bit mode! omgoodness C'MON LCD WORK!

Thanks so much again, Cliff. Sorry to be bothering you

Mark

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

if ure seeing a black screen please check your connections meticulously thats what worked for me

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

help needed.... i have tried it all but don't want to accept that both the LCDs that i have is broken, is their any way to check the functionality of an LCD to see if its ok. i have ran it on PORTA and PORTC but nothing is working, i am using the fluery's library in 4-bit mode.

i am programming it in linux ,
tell me if i can compile with the given makefile that came with the library or is it only for winavr. although its compiling fine with no errors.
also i have compiled with standard makefile : same result :(
please reply soon
TIA

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

how do you think you've broken in it?..have you soldered your connectors properly,some terminals might be shorted.Check that using a multimeter.

I don't have any idea about the linux part of your query,what i know is that if you supply 5V to the specified pins of the LCD ,it shows blackboxes even when not initalised properly.

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

ya thats what i am getting black boxes in the first row
and nothing else. actually i have a new lcd with me right now but its behaving exactly the same.

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

Quote:

i am getting black boxes in the first row

A telltale sign of the display not being properly initialized (or not initialized to use both rows and the contrast control voltage not being correct).

Quote:
actually i have a new lcd with me right now but its behaving exactly the same

Which is another indicator that the LCD(s) are not faulty. Either you have the connections wrong, or the software isn't doing what it should.

You now need to work with one problem at any given time. Do not poke at everything at once.

1) What did you do for contrast control (often called Vee, and AFAIK always on pin 3 of the LCD module)? What does the data sheet say about this voltage? Some display modules require a negative voltage here. For most display modules an adjustable voltage around 0.5 to 1 Volts is what is required. Arrange a 10 or 20K pot as a voltage divider feeding this pin.

2) Double check your wiring.

3) Double check that you have altered everything required in the s/w "setup", eg #defines for port and pin names. Eg did you fix the #define of LCD_DATA0_PIN and the six others?

4) Check the timings of the software. One thing that might reveal broken timing constraints is to lower the AVR frequency if you have the provisions for that. The idea is not to lower it permanently, but temporarily as a test for this hypothesis. Eg if you are running your AVR at 8 MHz and lowering that to 1 MHz makes the LCD start working then you have just detected a probable timing problem.

Again, not everything at once. Be systematic. Stop and think. If you get an advice here to do a specific test - do that and only that and report the results.

We've seen sooooo many LCD woes here over the years and close to all have eventually been solved if given advice has been followed.

First advice: Patience.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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 johan for keeping me trying.
at last it finally worked.
the most important thing i learned from this is , if nothing seems to be wrong then one of your basic assumptions must be rechecked. The mistake i was doing was really basic, may be stupid.
I read the library documentation and found that the interface pins for data pins in 4-bit mode are 11-14 pin no. rather than 7-10. since it was written DB0 for 7 to DB3 for 10, and i just assumed those connections.

i am just happy that it finally worked and now i can communicate between two atmegas without the need for a terminal.

thanks again all of you.

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

http://www.jump.to/fleury ----> is not there any more???

I cant find the library???

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

Fleury's page/code is still visible at:

http://homepage.hispeed.ch/peter...

(top hit for "Fleury LCD" at Google)

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

Can someone help me please?
I trying to init my LCD 16x2 in 4bit mode.
I have add to the source files the lcd.c and in to the headers file the lcd.h.
I am using the fleury cd lib
When i write this code for example :

#include
#include
#include "lcd.h"

DDRB=0x0F;
DDRD=0xF0;
int main(void)
{
lcd_init(LCD_DISP_ON);

for(;;)
{
lcd_clrscr();
lcd_puts(“program”);
_delay_ms(50);

}
it show me this erors:
../lcd.h:188: error: expected ')' before 'dispAttr'
../displej.c:5: error: expected identifier or '(' before 'volatile'
../displej.c:5: error: expected ')' before '(' token
../displej.c:6: error: expected identifier or '(' before 'volatile'
../displej.c:6: error: expected ')' before '(' token
../displej.c: In function 'main':
../displej.c:9: warning: implicit declaration of function 'lcd_init'
../displej.c:14: error: stray '\223' in program
../displej.c:14: error: stray '\224' in program
../displej.c:14: error: 'program' undeclared (first use in this function)
../displej.c:14: error: (Each undeclared identifier is reported only once
../displej.c:14: error: for each function it appears in.)
I spend my last 2 days about this and I cud found the problem.
Please can you help me and answer my?
If someone can help me,send me the answer in mail please. lacikeNZ@gmail.com

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

The line in question in lcd.h is:

extern void lcd_init(uint8_t dispAttr);

so it sounds like it's the uint8_t it may be obecting to. Yet ultimately leads to (it includes sfr_defs.h which includes inttypes.h which includes stdint.h.

So I'd maybe check a small test program where uint8_t is used and make sure your system knows this typedef?

Alternatively if you edited lcd.h above line 188 to change either:

#define LCD_LINES           2     /**< number of visible lines of the display */
#define LCD_DISP_LENGTH    16     /**< visibles characters per line of the display */
#define LCD_LINE_LENGTH  0x40     /**< internal line length of the display    */
#define LCD_START_LINE1  0x00     /**< DDRAM address of first char of line 1 */
#define LCD_START_LINE2  0x40     /**< DDRAM address of first char of line 2 */
#define LCD_START_LINE3  0x14     /**< DDRAM address of first char of line 3 */
#define LCD_START_LINE4  0x54     /**< DDRAM address of first char of line 4 */
#define LCD_WRAP_LINES      0     /**< 0: no wrap, 1: wrap at end of visibile line */

or

#define LCD_IO_MODE      1         /**< 0: memory mapped mode, 1: IO port mode */
#if LCD_IO_MODE

#define LCD_PORT         PORTA        /**< port for the LCD lines   */
#define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */
#define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */
#define LCD_DATA2_PORT   LCD_PORT     /**< port for 4bit data bit 2 */
#define LCD_DATA3_PORT   LCD_PORT     /**< port for 4bit data bit 3 */
#define LCD_DATA0_PIN    0            /**< pin for 4bit data bit 0  */
#define LCD_DATA1_PIN    1            /**< pin for 4bit data bit 1  */
#define LCD_DATA2_PIN    2            /**< pin for 4bit data bit 2  */
#define LCD_DATA3_PIN    3            /**< pin for 4bit data bit 3  */
#define LCD_RS_PORT      LCD_PORT     /**< port for RS line         */
#define LCD_RS_PIN       4            /**< pin  for RS line         */
#define LCD_RW_PORT      LCD_PORT     /**< port for RW line         */
#define LCD_RW_PIN       5            /**< pin  for RW line         */
#define LCD_E_PORT       LCD_PORT     /**< port for Enable line     */
#define LCD_E_PIN        6            /**< pin  for Enable line     */

then I'd check those edits for anything that may have a knock on effect to line 188 just below.

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

This

lcd_puts(“program”); 

does not contain quote characters that the compiler likes.

Are you editing your source files with Word or Wordpad or so...? If so change to using an editor for source code, that does not auto-replace "quoted text" with “quoted text”.

N.B.: This problem is separate from the one Cliff discusses. Both problems needs to be dealt with.

And please learn to use the CODE tags so that you can present code here in a readable manner (indentation preserved, no smilies substituted etc). Something like this...

#include
#include
#include "lcd.h"

DDRB=0x0F;
DDRD=0xF0;
int main(void)
{
   lcd_init(LCD_DISP_ON);

   for(;;)
   {
      lcd_clrscr();
      lcd_puts(“program”);
      _delay_ms(50);

   }

Like that it also becomes quite clear that a curly-brace is missing in your code. It might just be a copy-paste-problem, but if so you need to be more meticulous when doing those operations.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

the best tutorial till date...
thnx man

darshshah wrote:
LCD Tutorials
This tutorials is for people who like to use their LCD without understanding much about the working part of the LCD. This is my first attempt to write a tutorial so please bear my mistakes and point out if any occurs.

This tutorial explains how to program the LCD in an abstract view i.e. directly using the library functions without going into the depth of it.
Firstly I am using JHD162A LCD module which is compatible with HD44780. Now the LCD can come in various sizes. I am using a 16x2 LCD, which means 2 lines are there and each line can display a maximum of 16 characters. The lcd can be used in 4 bit mode or 8 bit mode depending upon your pin availability on our microcontroller or development board.
In 8 bit mode 8 data pins are there which sends a character(1 byte) directly to the lcd. In 4 bit mode the upper nibble is sent first and then lower nibble.
The 16 pins on JHD162A are
1 Vss
2 Vcc
3 Vee
4 RS
5 R/W
6 EN
7 DB0
8 DB1
9 DB2
10 DB3
11 DB4
12 DB5
13 DB6
14 DB7
15 LED+
16 LED-

DB0-DB7: Data Pins( use DB4-DB7 in 4 bit mode)

RS(Register Select) : 1 - Data is sent , 0 - Command is sent .

R/W(Read/Write) :1 - Read the lcd , 0 - Write to lcd. this pin is almost always low.

EN(Enable): to enable an operation . first make low(0) to send data and then set the other two control lines and when they are configured, bring EN high (1) and wait for the minimum amount of time required by the lcd and bring it low (0) again.

Vee: Contrast Adjust Pin. connect to a potentiometer.

Now to use it in 8 bit mode we need 8 data pins DB0-DB7 and 3 control pins. So total 11 pins are required. In 4 bit mode, we need DB4-DB7 and 3 control pins. So total 7 pins and required.Note that the data pins DB0-DB3 are left open and are not shorted to ground.The Vee pin is connected to the potentiometer and is varied from Vcc and Gnd. Pin 15 and 16 are used for backlight of lcd and can be connected to Vcc and Gnd respectively.
So till now, you have the basic idea to setup a lcd and connect it with your microcontroller. In this tutorial I am using lcd in 4 bit mode.

Before writing any code, first download the library written by Peter Fleury from his homepage - http://www.jump.to/fleury. The library written by him has excellent functions by which we can directly control the lcd without knowing what is going behind the scenes and using the built-in functions provided in the library.
First set the mode as 4 bit mode by writing LCD_IO_MODE=1 in the lcd.h file.
Change LCD_PORT if you want to use a different port for the LCD pins.
The four LCD data lines and the three control lines RS, R/W, EN can be on the same port or on different ports. Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on different ports.

Code:
int main(void)
{
lcd_init(LCD_DISP_ON); /* initialize display, cursor off */
while (1) /* loop forever */
{
lcd_clrscr(); /* clear the screen*/
lcd_puts(“test program”); /* displays the string on lcd*/
_delay_ms(50);
}
}
This codes displays “test program“ on your lcd.(without quotes)
I have used delay because some time is required for the display to settle in.

The functions in the library which could be used are -

lcd_init (uint8_t dispAttr)-initialize display and select type of cursor.
lcd_putc(char c) - to print a single charater on current cursor position
lcd_puts(const char* s) - to print a string without auto linefeed.
lcd_gotoxy(uint8_t x, uint8_t y) - xth position on the yth line. X varies from 0 to 15 and y is 0 or 1.
lcd_clrscr() - clears the screen .
lcd_home() – goes to the initial position, i.e. equivalent to lcd_gotoxy(0,0)
lcd_puts_p (const char *progmem_s) - display string from program memory without auto linefeed.
lcd_command (uint8_t cmd)-send LCD controller instruction command.
lcd_data (uint8_t data)-send data byte to LCD controller

With the help of these basic functionalities you can display text on your lcd on both lines.
Please beware of delays. Proper delays are required for the text to properly display on screen or else it will blink or just displays once and go away. Play around with different types of functions given in the library.
e.g. lcd_command(LCD_MOVE_DISP_RIGHT) – moves the whole display one position right side.
Experiment it to display various kinds of symbols and text. One good code would be to show your text moving on the lcd. i.e. it enters from right and leaves from left – kind of rolling effect.

Problems which I have faced or mainly occurs with lcd-

The first problem to arise is you don’t see anything on lcd although its on – change the value of contrast using potentiometer.

Black squares are seen – See that proper connection is there. i.e. if any two pins touch each other than this may occur. Also see the contrast pin.

Displays blinks- use a proper delay. Try out different values of delays

Typical symbols are displayed instead of text – see the connections again. If two pins are shorted, this might occur.

Hope you like and understood the tutorial and start programming the lcd and play around with it.please give your feedback so that i can improve it.

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

I am using ATmega8(L) with 16x1 LCD. First of all thank you for this tutorial. It finally worked. However there is a slight problem: Only the first eight characters show up. The rest of them doesn't. Any ideas about why this is happening? I have done pin configuration in lcd.h
Mind you, the first eight characters works pretty fine. The rest of them don't.

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

The other 8 may be at a different RAM address. Try writing to every RAM location and see if anything appears. They might be at 0x20 or 0x40 or something?

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

Quote:

Only the first eight characters show up. The rest of them doesn't.

Although physically arranged as a display with one line of 16 characters, logically it is two lines of eight characters. And the second line does not begin at the address after the one that the first ended at.

You must set the DDRAM address to get to the ninth and following characters. I'd wager that they start at address 0x40.

Please note that you will have to init your display to 2 lines (again, although physically one line it is logically two lines).

For a good document outlining the addressing scheme for many different displays, go here: http://www.optrex.com/engineerin... , and download the Character LCD User's Manual . Go to page 17 to see what I am talking about.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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 for those replies. I have no clue what is wrong. I have a 16X1 display. Although I agree with you that logically they are two 8x1 displays(I confirmed in the Datasheet) . I have set my #define LCD_LINES to 1 and doing my init() with lcd_init(LCD_DISP_ON);

Here are my lcd.h (
http://pastebin.com/m63c22ef2 )and main.c( http://pastebin.com/m62ca78f6 )

Thank you

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

Yes but your main is just using lcd_puts() - what are you doing about addressing to 0x20 or 0x40 beyond character 8?

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

Surely you need to say this.

#define LCD_LINES           2     /**< number of visible lines of the display */
#define LCD_DISP_LENGTH     8     /**< visibles characters per line of the display */

Otherwise you will not be able to write a string across position 7 and 8.

Untested. I do not have a 16x1 display.

David.

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

Quote:

I have set my #define LCD_LINES to 1 and doing my init() with lcd_init(LCD_DISP_ON);

A (logically) two-line display will happily be initialized as a one-liner, but then only the first logical line is usable/functional.

I'd go with Davids suggestion above for a start.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Just to note that there's an outside possibility you may also have to "play" with this too:

#define LCD_START_LINE2  0x40     /**< DDRAM address of first char of line 2 */

(though the likelihood is that the second 8 are mapped to 0x40)

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

@david.prentice
I tried it. But now there is no display at all. After experimenting for a while, I found out that as soon as I set the LCD_LINES to 2 (without altering other variables) the, display turn blank
@clawson
So what else should I do? I am just using the library.

Should I really play with DRAM2 address? what about #define LCD_LINE_LENGTH 0x40 ?
Remember: that me turning LCD_LINE to 2 completely washes the display.

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

Two suggestions:
1:
Keep the

#define LCD_LINES           2     /**< number of visible lines of the display */ 

and try to adjust the contrast. It might be that you need a different contrast setting when the display is in two line mode.

2: Go back to that

#define LCD_LINES           1     /**< number of visible lines of the display */

and then write a veeeery long string on it. Like

lcd_puts("ABCDEFGHIJKLMNOP QRSTUVWXYZabcdef ghijklmnopqrstyv wxyz0123456789Maryhadalittlelamb");

and see if the second line displays anything. This will (probaably) write to the DDRAM sequentially, and any characters going into addresses not mapped to a physical character cell will go into the binary void, as far as you are concerned right now. It just might be that you get this on the display:

ABCDEFGHry had a

An alternative is to just flood the display continously with characters, like so (sketchy):

char c = 'A';
while (1)
{
   lcd_putchar(c);
   c++;
   if (c > 'Z')
   {
      c = 'A';
   }
}

By taking this intermediate approach you will not have to worry about addressing the second logical line. If it is active it will eventually get filled with characters. Once you are there, then worry about if you need to do something special to address the second logical line, and how.

Fault-seeking is very much about testing and working with as small chunks of the problem at hand as possible. Many small steps will probably get you to the finish line faster, than a try at one giant leap.

HTH!

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

I am speechless. That contrast thing did the trick. I have no words to pay my gratitude. Thanks a zillon.
PS: As I was in so much hurry to thank you, I didn't checked the rest of the stuff.

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

Quote:

Thanks a zillon.
As I was in so much hurry to thank you, I didn't checked the rest of the stuff.

You're most welcome.

And you don't need to test stuff beyond getting things working. The old saying is still valid:

Quote:
If it ain't broke - don't fix it.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Hi,

I am having a compiling problem with the code. I have followed the great directions that clawson posted with the difference that I added "lcd.h" to the header file, "lcd.c" and "test_lcd.c" to the source files. When I build, I get the following errors:

Build started 5.2.2010 at 17:46:18
avr-gcc -mmcu=atmega8 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT lcd.o -MF dep/lcd.o.d -c ../lcd.c
../lcd.c: In function 'toggle_e':
../lcd.c:120: error: 'PORTA' undeclared (first use in this function)
../lcd.c:120: error: (Each undeclared identifier is reported only once
../lcd.c:120: error: for each function it appears in.)
../lcd.c: In function 'lcd_write':
../lcd.c:141: error: 'PORTA' undeclared (first use in this function)
../lcd.c: In function 'lcd_read':
../lcd.c:222: error: 'PORTA' undeclared (first use in this function)
../lcd.c: In function 'lcd_init':
../lcd.c:528: error: 'PORTA' undeclared (first use in this function)
make: *** [lcd.o] Error 1
Build failed with 6 errors and 0 warnings...

the definition of portA is in lcd.h. I am supposed to put that in the "header files" tree, right?

Thanks for any help and thanks for the great tutorial

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

All port names are defined as a consequence of
1) Setting the AVR model in the project options, and
2) Doing

#include 

in any source file that needs to use the ports.

The LCD library you are using is doing 2) where needed, and you have done 1) setting it to ATmega8. But...

You need to read the data sheet for the ATmega8 - it does not have a PORTA.

Your problem is that you are telling the LCD library to use a port that does not exist.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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 for pointing that out to me! It compiles now :-)

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

Hi, I am having extreme difficulty sending anything to my 2x16 lcd. I am using the cerebot 2 and the pmodCLS. The code compiles with no errors but nothing goes to the lcd. My code is listed below. Please, if anyone can tell me where I am going wrong it would be greatly appreciated! Thanks

#include
#include
#include
#include
#include
#include
#include "CerebotII.h"
#include "StdTypes.h"

char s[]="CLS Demo Project ";
char tmp;

void SPI_MasterInit();
void SPI_sendChar(char spiData);
void SPIsendString(char string[]);
void SPImoveString(char s[]);

int main(void)
{
void SPI_MasterInit(void)
{
// Set MOSI, SS and SCK output, all others input
DDRB |= (1 << bnJD1)|(1 << bnJD2)|(1 << bnJD4);
prtJD3 &= ~(1 << bnJD3);
prtJD1 |= (1 << bnJD1); //hold SS line high
// Enable SPI, Master, set clock rate fck/64 =~125k bps
SPCR = (1 << SPE)|(1 << MSTR)|(1 << SPR1);
void SPI_sendChar(char spiData)
{
BYTE i;
prtJD1 &= ~(1 << bnJD1); //lower SS pin
for (i = 0; i < 4; i ++) //waste some clock cycles
asm volatile("nop");
SPDR = spiData; //Start transmission
while(!(SPSR & (1 << SPIF)) ) //Wait for transmission to complete
;
prtJD1 |= (1 << bnJD1); //return SS pin high
for (i = 0; i < 4; i ++) //waste some clock cycles
asm volatile("nop");
}
void
SPIsendString(char string[])
{
unsigned int length, i;
length = strlen(string); //calculates the length of the string.
for(i = 0; i < length; i++)
{
SPI_sendChar(string[i]); //send byte
}
return;
}void SPImoveString(char s[])
{
tmp=s[0]; //save first character
for (int i=0;i s[i]=s[i+1]; // shifts characters to the left
}
s[strlen(s)]=tmp; //switch the first character with the last one
/* escape sequence */
SPI_sendChar(0x65);
SPI_sendChar(0x1B); // ESC character
SPI_sendChar(0x5B); // [ character
SPI_sendChar(0x30); // zero
SPI_sendChar(0x6A); // j- command for clear display and home cursor
SPIsendString(s); // sends the string
_delay_ms(1000); // aproximately 1 sec delay
_delay_ms(1000);
}
return 0;
}
return 0;

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

Edit your post and surround the code with CODE tags so that it becomes readable. I guess few will bother with reading it as it looks right now.

The LCD display you are using seems to have an I2C/SPI interface, which is something different from the basic parallel interface discussed in this thread. Maybe start a new thread for your problem, so that it gets better exposure and not being camouflaged in here?

As I read your code you have functions inside functions. I was under the impression that this is not allowed in C. Are you posting the correct stuff correctly?

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Finally figured it out!

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

Hi again,

The display only gives me black squares as my output. I have a 10k pot that I am using to change the contrast, however it will only make the black squares lighter. I am pretty sure that I have made my connections correctly as I have checked them a couple of times. What are other causes of getting these black squares on the LCD that I could check? Thanks a lot.

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

hudaheck!

How did you hook up the resistor? It should be a voltage divider, ie one end to VCC, other end to GND, wiper to contrast pin on LCD.

What does the display data sheet say about contrast voltage? Some modules require a negative voltage.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

I have the VCC as the input to the pot, gnd going to gnd, and the output pin of the pot going to the contrast pin of the lcd. Looking at different websites, I have set my contrast so when uninitialized, there is a row of black squares on the top row and nothing on the bottom row. (I am using a 2x16 LCD)

Here is the datasheet:

[url] http://www.sparkfun.com/datashee...

Maybe I am missing it, but I dont see anything about the contrast voltage in there. I read in earlier posts on this thread that instead of VCC, the resistor was connected to GND, however that does not change anything for me.

There are some websites I have been looking at which mention including a voltage divider with the R/S, RW, and E lines. Do you know if this is necessary?

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

Quote:

There are some websites I have been looking at which mention including a voltage divider with the R/S, RW, and E lines.

Those are digital signal lines, and the only reason to put a voltage divider on thonse that can think of is to do level conversion (eg a 5 volt system is using a max 3.3 Volt display module.). Not the first thing you should bother with if you ask me.

Quote:

I have the VCC as the input to the pot, gnd going to gnd, and the output pin of the pot going to the contrast pin of the lcd.

A pot is "directionless" in my world, so I can't make heads or tails of your description with "inputs" and "outputs". But the data sheet you linked to has a drawing of how it should be. That drawing also implies that you do not need a negative contrast voltage.

Another cause of getting black squares is that the display is not properly initialized. It seems that this is the most likely cause, and that you should work on that.

1. Double-check the wire up.
2. Double-check the timing in code.
3. Double-check everything else.
4. Drink coffee and walk the dog.
5. GOTO 1

:wink:

EDIT: I see now that the display you have uses a KS0066 controller, which is a clone of the HD44780. Similar but not identical. Does the LCD code you are using have a switch (eg a #define) to specify the controller?

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Instead of trying the Peter Fleury code, I am actually using one that you had attached on an earlier post.

http://www.avrfreaks.net/index.p...

I have changed the port to portb using the atmega8 but everything else remains the same. As I have checked step number 1, when checking the timing of the code I have set the frequency to be 4 MHz under the configuration options in AVR studio. Would this have anything to do with improper timing?

I am thinking about jumping to step 4 pretty soon :-)

Oh I just saw your edit. I do not know if that code has a define for that type of controller

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

Quote:

code I have set the frequency to be 4 MHz under the configuration options in AVR studio

Yes.

Please note that the settings for the project does not affect what frequency the AVR will run at. It is the other way around - the setting tells the compiler what frequency the AVR is actually running at.

The code in my post that you are trying out now has been used repeatedly with success. I would say that it is proven. (There could be some KS077 complication..)

I think it is time now for you to tell us exactly how you have the display module hooked up.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Thank you so much for taking the time to help me with my problem. Yes, I trust your code and the Fleury code, I believe that this is my mistake somewhere.

The thing is I also have another LCD that I have been testing on also to no success which I do not think has that KS077 complication. This is the datasheet:

http://www.parallax.com/Portals/...

This datasheet also mentions those resistors that I asked about earlier.

Lets talk about this LCD. Everything is connected to PORTB as previously mentioned. RS is going to pin0, RW to pin1, E to pin2. Nothing is connected to pin3. DB4 is going to pin4, DB5 to pin5, DB6 to pin6 and DB7 to pin7. I am using an stk500 to make these connections and everything is connected to expansion port 1. I am using the VTG and the GND of the expansion port as VCC and GND.

On the LCD screen, pin0 is going to GND, pin1 is going to VCC and pin3 is going to the 10k pot. I have nothing connected to DB0-DB3 as I want this to be in 4bit mode. I also have nothing connected to pins 15 and 16 because I don't need the back light to be on.

I am going to check these connections again and hopefully I will catch some sort of careless error that I didint see before. Do you notice an error in my connections? Thanks again!

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

Quote:
Thank you so much for taking the time to help me with my problem.

We live to serve.. :D

Quote:
I also have another LCD that I have been testing on also to no success which I do not think has that KS077 complication.

Corect, that is a genuine HD44780-based display according to the sheet.

Quote:
On the LCD screen, pin0 is going to GND, pin1 is going to VCC and pin3 is going to the 10k pot. I have nothing connected to DB0-DB3 as I want this to be in 4bit mode. I also have nothing connected to pins 15 and 16 because I don't need the back light to be on.

This seems mildly confusing. LCD pins are numbered from 1 (one), not 0 (zero).
Assuming you just slipped a little I read that you have

LCD Pin1 to VCC
LCD Pin2 to GND
LCD Pin3 to the contrast control pot
LCD Pin 4 (RS) to AVR pin 0
LCD pin 5 (R/W) to AVR pin 1
LCD pin 6 (E) to AVR pin 2
LCD Pin11 to Pin14 (DB4-DB7) connected to AVR pin 4 to 7

Seems reasonable, but: What port on the AVR?
And also: What AVR model?

(I'm hunting for eg possible alternate functions activated. Standard case is JTAG on some AVR models being factory enabled, thus inhibiting normal digital IO on four pins, usually on PORTC).

Any other info that might help us pinpoint the problem would also be grand, eg what board is the AVR sitting on (is it a STK500, or a breadboard, or a...?)

Can you take a photo of the setup and attach to a post here? (Remember to resize it to eg 640x480 to keep js happy :D )

We'd also like a clear and definite statement on what clock speed the AVR is actually running at. (Internal 8 MHZ / 8 = 1 MHz? External clock source, eg the STK500 clock generator? What frequency then? Or something else?) Have you set the frequency in the project options/makefile to match that?

Quote:
This datasheet also mentions those resistors that I asked about earlier.

Those are pull-downs for E and DB4-DB7. The data sheet says the examples are for a BasicStamp, so I suspect that the pull-downs are specific for that. I've connected several different LCD models to an AVR, and never needed those.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

I am using an STK500 board and I am using an ATMega8. The ATMega8 is mounted on the stk. Everything is connected to PORTB. I havent done anything to change the clock speed so I am not sure what the frequency is. When I go to "HW Settings" it says that the clock generator is 3686400. I set the frequency under configuration options to that as well.

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

Quote:

I havent done anything to change the clock speed so I am not sure what the frequency is.

If you didn't touch the fuses of the AVR then it is running from the internal oscillator. 1 MHz. Make sure that in the project options the compiler is set to the same (1000000 Hz). Clean. Rebuild. Reprogram the AVR.

When you turn the pot, can you make the black boxes disappear? Placing a voltmeter on pin 3 on the LCD, what voltage do you have there? Can you see it being 5 Volts with the pot at one end, and zero Volts with the pot at the other end?

IIRC the programming interface is on PORTB on the ATmega8. Try these two, one at a time:

1) After programming the hex to the AVR flash, lift one end of the 6-lead flat cable that is on the STK500 so that you don't have the STK500 programming circuitry connected to the AVR thus not interfering with the LCD comms. Cycle power. Maybe press the reset button on the STK500.

2) Move the LCD to PORTD. Change the code (mine or Fleury's) accordingly. Re-build. Re-flash.

Small moves now. One thing at a time. When frustration starts to get to you - take a good break and do something pleasant. Return with a calm and fresh mind. Be methodical. No shots in the dark.

While it may take a while, You'll get there!

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

When I changed to 1MHz, it didint make a difference. When I took the 6 pin cable out it also didint make a difference. I tested the output of the pot with a voltmeter and it would change from 0-5 V and I could get a good contrast at around 0.4 V.

When I changed it to PORTD it worked! Woohoo! :-D

Hmm, why dosent PORTB work? Looking at the data sheet I couldn't find anything that makes it too much different from PORTD.

But thank you so much for your help! I really appreciate the encouragement you gave me as well as the baby steps to help me to display "4-bit avr-gcc" haha

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

For 28pin chips in an STK500 PB6 and PB7 do NOT appear on the PORTB header pins. They are actually on PORTE labelled as X1/X2. I think everyone who'd ever used 28 pin chips on the STK500 has been bitten by this at some stage.

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

Can some one help me? I'm trying to compile Fleury's code in AVR Studio with lcd_test.c. But I'm getting errors. I followed clawson's steps and have added lcd.h and lcd.c into my project but it's still not working!

avr-gcc  -mmcu=atmega324p -Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT lcdtest.o -MF dep/lcdtest.o.d  -c  ../lcdtest.c
../lcdtest.c: In function 'main':
../lcdtest.c:60: warning: implicit declaration of function 'lcd_init'
../lcdtest.c:60: error: 'LCD_DISP_ON' undeclared (first use in this function)
../lcdtest.c:60: error: (Each undeclared identifier is reported only once
../lcdtest.c:60: error: for each function it appears in.)
../lcdtest.c:71: warning: implicit declaration of function 'lcd_puts'
../lcdtest.c:77: warning: implicit declaration of function 'lcd_gotoxy'
../lcdtest.c:80: warning: implicit declaration of function 'lcd_putc'
../lcdtest.c:91: warning: implicit declaration of function 'lcd_command'
../lcdtest.c:91: error: 'LCD_DISP_ON_CURSOR' undeclared (first use in this function)
../lcdtest.c:107: warning: implicit declaration of function 'lcd_puts_P'
../lcdtest.c:111: error: 'LCD_MOVE_DISP_LEFT' undeclared (first use in this function)
../lcdtest.c:148: error: 'LCD_CGRAM' undeclared (first use in this function)
../lcdtest.c:151: warning: implicit declaration of function 'lcd_data'
make: *** [lcdtest.o] Error 1
Build failed with 6 errors and 7 warnings...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Show us how you included it in main.c. That is, do you have:

#include "lcd.h"

at the top of that file?

Regards,
Steve A.

The Board helps those that help themselves.

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

Koshchi wrote:
Show us how you included it in main.c. That is, do you have:

#include "lcd.h"

at the top of that file?

I straight copied lcd_test.c into main.c and yes I have that include at the top.

Also, AVR studio is configured for an atmega324p if that makes any difference.

EDIT: I changed

#include "lcd.h"

to

#include 

and it compiled fine. Why is this?

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

Where is lcd.h located?

Regards,
Steve A.

The Board helps those that help themselves.

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

Koshchi wrote:
Where is lcd.h located?

In a directory away from WinAVR and all the Atmel stuff.

EDIT: I moved lcd.h and lcd.c into my project directory and it compiles fine with

#include "lcd.h"

Please excuse my ignorance, i didn't realize that's how it worked.

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

Hi,
great tutorial on HD44780 based lcds.
Today I bought a 16x4 display but It turns out to be SED1278 based. I've tried to use library in this tutorial but I've failed. Only the backlight is on and nothing on the display.
Someone else tried this?

Is there a good tutorial on SED1278?

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

The SED1278 is an HD44780 clone. The only difference might be the initialization sequence. I have yet to find a datasheet that specifies what that sequence is.

Regards,
Steve A.

The Board helps those that help themselves.

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

Here is the datasheet of my LCD
http://home.comet.bg/datasheets/...

I'm trying to make 4bit mode to safe some space on the pcb. My avr is ATMega8535.

Clock is default to 1Mhz

LCD DB4 <--> PB1
LCD DB5 <--> PB2
LCD DB6 <--> PB3
LCD DB7 <--> PB4
LCD E <--> PB5
LCD R/W <--> PB6
LCD RS <--> PB7

PS: I'm so stupid. I checked the direction the lcd pins are and I had mixed up the pins.

Sorry for being so stupid.

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

please help
I am not experiance in Avr.My lcd is not display no characters only display black box. i am using atmega32 and jhd629-204a display. edited lcd.h code below

/**
* @name Definitions for MCU Clock Frequency
* Adapt the MCU clock frequency in Hz to your target.
*/
#define XTAL 11059200 /**< clock frequency in Hz, used to calculate delay timer */

/**
* @name Definition for LCD controller type
* Use 0 for HD44780 controller, change to 1 for displays with KS0073 controller.
*/
#define LCD_CONTROLLER_KS0073 0 /**< Use 0 for HD44780 controller, 1 for KS0073 controller */

/**
* @name Definitions for Display Size
* Change these definitions to adapt setting to your display
*/
#define LCD_LINES 4 /**< number of visible lines of the display */
#define LCD_DISP_LENGTH 20 /**< visibles characters per line of the display */
#define LCD_LINE_LENGTH 0x50 /**< internal line length of the display */
#define LCD_START_LINE1 0x00 /**< DDRAM address of first char of line 1 */
#define LCD_START_LINE2 0x40 /**< DDRAM address of first char of line 2 */
#define LCD_START_LINE3 0x14 /**< DDRAM address of first char of line 3 */
#define LCD_START_LINE4 0x54 /**< DDRAM address of first char of line 4 */
#define LCD_WRAP_LINES 0 /**< 0: no wrap, 1: wrap at end of visibile line */

#define LCD_IO_MODE 1 /**< 0: memory mapped mode, 1: IO port mode */
#if LCD_IO_MODE
/**
* @name Definitions for 4-bit IO mode
* Change LCD_PORT if you want to use a different port for the LCD pins.
*
* The four LCD data lines and the three control lines RS, RW, E can be on the
* same port or on different ports.
* Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on
* different ports.
*
* Normally the four data lines should be mapped to bit 0..3 on one port, but it
* is possible to connect these data lines in different order or even on different
* ports by adapting the LCD_DATAx_PORT and LCD_DATAx_PIN definitions.
*
*/
#define LCD_PORT PORTA /**< port for the LCD lines */
#define LCD_DATA0_PORT LCD_PORT /**< port for 4bit data bit 0 */
#define LCD_DATA1_PORT LCD_PORT /**< port for 4bit data bit 1 */
#define LCD_DATA2_PORT LCD_PORT /**< port for 4bit data bit 2 */
#define LCD_DATA3_PORT LCD_PORT /**< port for 4bit data bit 3 */
#define LCD_DATA0_PIN 4 /**< pin for 4bit data bit 0 */
#define LCD_DATA1_PIN 5 /**< pin for 4bit data bit 1 */
#define LCD_DATA2_PIN 6 /**< pin for 4bit data bit 2 */
#define LCD_DATA3_PIN 7 /**< pin for 4bit data bit 3 */
#define LCD_RS_PORT LCD_PORT /**< port for RS line */
#define LCD_RS_PIN 2 /**< pin for RS line */
#define LCD_RW_PORT LCD_PORT /**< port for RW line */
#define LCD_RW_PIN 1 /**< pin for RW line */
#define LCD_E_PORT LCD_PORT /**< port for Enable line */
#define LCD_E_PIN 3 /**< pin for Enable line */

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

Turn the contrast pot.

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

Playng with Fleury library for 1x16 display OP16034. Changing lines in lcd.h not changed for lcd everything.

#define LCD_LINES           2     /**< number of visible lines of the display */
#define LCD_DISP_LENGTH    16     /**< visibles characters per line of the display */
#define LCD_LINE_LENGTH  0x40     /**< internal line length of the display    */
#define LCD_START_LINE1  0x00     /**< DDRAM address of first char of line 1 */
#define LCD_START_LINE2  0x40     /**< DDRAM address of first char of lin

With Google I seeing :
http://www.mikroe.com/forum/view...
for idea making lcd working in main.c :

#include 
#include "lcd.h" //lcd.c and lcd.h are located in project dir.
#include 

void main()
{
  
lcd_init(LCD_DISP_ON);
lcd_clrscr();
	
lcd_gotoxy(0,0);
lcd_puts("lcd test");

lcd_gotoxy(0,1);
lcd_puts("test OK!");


}

Please help me!

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

Quote:
1x16 display

#define LCD_LINES           2     /**< number of visible lines of the display */ 

?

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

After changing lines in few day not changed at all for my lcd. On the lcd only 8 characters. Only making changes in lcd.h, I can make code not working at all. After changing main.c it works but I am not like this.

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

Quote:

After changing lines in few day not changed at all for my lcd. On the lcd only 8 characters. Only making changes in lcd.h, I can make code not working at all. After changing main.c it works but I am not like this.

And you changed that LCD_LINES value that Johan identified?

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

Hi ;
This is my code of EEPROM interface :

#include
#include "util/delay.h"
#include
#include
#include "i2c.h"
#include "lcd.h"

void Wait()
{
uint8_t i;
for(i=0;i<10;i++)
_delay_loop_2(0);
}

void main()
{
//Varriables

unsigned int num,unit,ten,hundred,tenth;
unsigned char buff0,buff1,buff2,buff3,buff;

lcd_init(LCD_DISP_ON); // lcd initialize
EEOpen(); // I2c Start

lcd_puts( "EEPROM TEST");
Wait();
lcd_clrscr();

EEWriteByte(9,250) // Write in EEPROM

lcd_puts( "Written IN EEPROM ");
Wait();
lcd_clrscr();

num=EEReadByte(9); // Read From EEPROM

//UNIT
unit=(num%10);
itoa( unit , buff0, 10);
lcd_gotoxy(3,1);
lcd_puts(buff0);

//TENS
ten=(num/10)%10;
itoa( ten , buff1, 10);
lcd_gotoxy(2,1);
lcd_puts(buff1);

//HUNDRED
hundred=(num/100)%10;
itoa( hundred , buff2, 10);
lcd_gotoxy(1,1);
lcd_puts(buff2);

//Thousand
tenth=(num/1000);
itoa( tenth , buff3, 10);
lcd_gotoxy(0,1);
lcd_puts(buff3);
}

i am getting output as 0001 but i supposed to get 0257 on my lcd
i converted integer to string using itoa function, using unsigned char so 0 to 255 number comes correctly, unsigned char ranges from 0 to 255, what should i do now.,

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

Silly question but why not simply:

itoa( num , buff3, 10); 
lcd_puts(buff3);

Or is all the jiggery-pokery simply to have leading 0 padding? One way would simply be to use sprintf():

sprintf(buff3, "%04d", num);
lcd_puts(buff3);

Or if you don't want the code expense of sprintf() then you can simply massage the output of the itoa():

itoa( num , buff3, 10); 
for (i=4-strlen(buff3); i; i--) {
  lcd_putc('0');
}
lcd_puts(buff3);

Cliff

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

hello guys,

can anyone tell me how one should add the lcd.h file to the list of libraries found in avrstudio.

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

Quote:

can anyone tell me how one should add the lcd.h file to the list of libraries found in avrstudio.

Why on earth would you want to do that? The fact is that libraries are .a files that contain binary code that has been pre-compiled. Sure they are usually accompanied by a .h file that documents the API that they offer but that's not something you'd add to the list there - all you do with .h files is #include them.

In this case this isn't even a library anyway (even though the author rather confusingly describes it as such). The code is simply a .c/.h combination. You add the .c to the list of files to be compiled and you #include the .h file in your own .c files that need to use the API offered by the lcd.c

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

Quote:
Posted: Mar 24, 2010 - 10:05 PM
Playng with Fleury library for 1x16 display OP16034. Changing lines in lcd.h not changed for lcd everything.

......
If I modifi lcd.h I can see only 8 character. How need turn lcd.h code for see one line 16 characters without tricking in main code?

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

i cannot access the 2nd line in my 16x2 lcd in 4 bit mode please help....
please send me the commands ....
i tried to write more than 90 characters in first line but still the second line did not show anything

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

tmedap and tilak: There is a special instruction to activate the second line. and even though a 1x16 display is physically one line, technically it is two 1x8 lines.

Quote:
please send me the commands ....

Set the line bit in the last Function Set instruction to 1. For details, look in the data sheet for your display. Or any HD44780 data sheet.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

I'm messing around with the code you posted here:
http://www.avrfreaks.net/index.p...

and I can't get it to work. At this point I've tried 5 different tutorials with all different configs and I haven't been able to get anything going yet. Yours has been the most promising with all "blocks" showing up on my lcd but no text.

I'm using an STK500 board, with an ATmega8 running on the Ext Clock at 3.686 MHz. I have a 10k wiper pot with the out pins at Vdd (5.0v), and GND and the middle pin going to pin 3 of the HD44780. Here's my pin setup:
Board - LCD (function)
PD 0 - Pin 4 (RS)
PD 1 - Pin 5 (R/W)
PD 2 - Pin 6 (EN)
PD 3 - EMPTY
PD 4 - Pin 11 (DB4)
PD 5 - Pin 12 (DB5)
PD 6 - Pin 13 (DB6)
PD 7 - Pin 14 (DB7)

Pin 15 for backlight tied to Vdd
Pin 16 tied to common ground (with Pin 1, and one end of wiper pot)

Adjustment of the wiper pot does nothing, all boxes on 2x16 display lit up. I didn't change anything from your file.

Any ideas what it could be? I've been banging my head against a wall with this thing for a few days, I can't seem to get anything to work. I don't have a voltmeter here to check my voltages on the wiper pot but I might be able to go to the lab at school and do so a bit later. Thanks for any help.

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

Have you actually turned the contrast pot? For almost all displays the pot wiper should be close to the GND end.

Do you have make and model for the LCD display? (A few displays actually requires a negative contrast voltage, which should be stated in the display data sheet.)

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

http://www.sparkfun.com/commerce...

That's the exact LCD. I've turned the pot back and forth with no change in contrast. I was able to find a friend with a multimeter so I'm borrowing that this evening, and I'll post back with my results, I'm starting to think that the pot itself isn't working. Are the solid boxes a sign of an incorrect contrast?

As a side note I've also tried tying Pin 3 of the LCD (contrast control) to GND and it gave me the same output as if I have the pot there.

EDIT: Okay, tested it on a multimeter. The voltage read at pin 3 is definitely varying as I turn the pot. The only interesting thing I found is that even though I'm programming it at 5.0v through AVR Studio, I'm reading 8.55v at every Vtg-GND on the STK500. Could this be related?

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

Thank u "JohanEkdahl"
It was really helpful
now i can run the lcd without libraries

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

4it operation of 16x2 LCD(TEST SET UP & TEST CODE)

NO EXTERNAL LIBRARIES REQUIRED

FOR ATMEGA16 AND ATMEGA32 can be used in others with WINAVR

lcd connection------(ATMEGA16 AND ATMEGA32)

1 VSS----GROUND-(0V)
2 VCC----VCC-(5V)
3 VEE----GROUND-(0V)
4 RS-----PA1-(2nd pin of PORTA)
5 RW-----GROUND-(0V)
6 E------PA2-(1st pin of PORTA)
7 DB0----N/C
8 DB1----N/C
9 DB2----N/C
10 DB3----N/C
11 DB4----PA4-(4th pin of PORTA)
12 DB5----PA5-(5th pin of PORTA)
13 DB6----PA6-(6th pin of PORTA)
14 DB7----PA7-(7th pin of PORTA)
15 LED+ --VCC-(5V)
16 LED- --GROUND THROUGH 150ohm

LCD CODE

#include 
#include 
#define rs PORTA|=(1<<1)	//Printing mod
#define crs PORTA&=(~(1<<1))//command mode selection
#define clear() crs;en(0x01);rs		//use this to clear display



void en(char a)// display function
{
	PORTA|=(0XF0&a);
	PORTA&=(0X0F|a);
	_delay_ms(1);
	PORTA|=((1<<0));
	_delay_ms(1);
	PORTA&=(~(1<<0));
	_delay_ms(1);
	
	PORTA|=(0XF0&(a<<4));
	PORTA&=(0X0F|(a<<4));
	_delay_ms(2);
	PORTA|=((1<<0));
	_delay_ms(1);
	PORTA&=(~(1<<0));
	_delay_ms(1);
}

void lin(void)//lcd initiate fuction
{
	 DDRA=0XFF;

  PORTA|=(0XF0&0x20);
	PORTA&=(0X0F|0x20);
	_delay_ms(2);
	PORTA|=((1<<0));
	_delay_ms(2);
	PORTA&=(~(1<<0));
	_delay_ms(2);
  en(0x28);
  en(0xc);
  en(0x06);
  en(0x01);
}

void ds (char c[],int a,int b)
  //for printing strings
  {
   char t='a';
	if(a==0){t=0x80|b;}
	if(a==1){t=0xc0|b;}
	crs;
	en(t);
	rs;
	a=0;
	while(c[a]!='\0')
	{
		en(c[a]);
		a++;
	}
	
  }




 void di(int a,int b,int c)
 //for printing intiger function
 {
	int f,e=0;
	char t='a';
	for(f=a;f>0;f=f/10){e++;}
	crs;
	if(b==0){t=0x80|(c+e-1);}
	if(b==1){t=0xc0|(c+e-1);}
	en(t);
	en(0x04);
	rs;
	for(;a>0;a=a/10){en(0x30+(a%10));}
	crs;
	en(0x06);
	rs;
 }

void cmd(char a)
{
    crs;
    en(a);
    rs;
}

int main(void)
{
        lin(); //initiates the lcd to 4bit mode 2 line without a cursor 

        ds("Hi There!!!!",0,0);       //prints  at first line from 1st position
 
        ds("I am TILAK",1,3);       //prints  at 2nd line from 4th position

       _delay_ms(500);_delay_ms(500);   //waits 1 second

        clear(); //clears display

        char b[]="My age is ";

        _delay_ms(500); //wait 0.5 second

        cmd(0x18);  // shifts entire display right see lcd commands in "HD44780"  datasheet

        ds(b,0,5);       //prints  in first line and from 6th position

        di(5,1,8);    // prints <5> in 2nd line from 9th position

        int mml=990;

       di(mml,1,2); //prints <990> in second line from 3rd position


/* from examples you have already understood that you have to pass 3 parameters
to "ds" and "di" function
for strings use "ds" function and pass the ds("string you want to print",0-for 1st line or 1-for 2nd line,0-15 position where to start in that line
similarly for integers use "di" function */ 

}

JUST COPY THE FUNCTIONS AND #DEFINES TO YOUR PROGRAM AND RUN "OR" RUN THIS PROGRAM WITH DIFFERENT STRINGS

IF YOU WANT TO USE DIFFERENT PORT CHANGE ALL "PORTA" TO "PORTB" or "PORTC"(disable JTAG before using PORTC) or "PORTD" WHICHEVER YOU WANT!!!(Ctrl+R "Shortcut in windows")

Please inform me if any correction required(tilak.pati@yahoo.com)
contact me for further assistance always HAPPY TO HELP and THANK U "JohanEkdahl"

Quote:
IT IS BEST TO GO WITH THE DATASHEET

Last Edited: Thu. Jul 1, 2010 - 07:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

NO EXTERNAL LIBRARIES REQUIRED

Quote:

JUST COPY THE FUNCTIONS AND #DEFINES TO YOUR PROGRAM AND RUN "

Do you understand what the word "irony" means? :lol:

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

clawson wrote:
irony

When i was trying to run a lcd with those big external libraries i faced much difficulty. The more i tried hard to understand the more i got confused. So i here tried to make some functions for those people who just need one character on their screen and they will start understanding te process.
Quote:
NO LIBRARIES REQUIRED

these were the terms which i usually searched for.
So i wrote this if someone(a fool like me)(no offence) searches for this string might get this post.

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

But surely you understand that the code you have presented IS a library itself? That to me at least seems ironic.

True it may be truly awful, virtually commentless code with meaningless function names making it almost impossible to follow simply for the sake of brevity but it IS "library code".

The difference with the Stang and Fleury "library code" is that functionally it may be very close but they have chosen to pad it out with comments, easily redfinable constants and sensible use of variable and function names.

IMAO.

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

Quote:
The more i tried hard to understand the more i got confused.
This type of thing would confuse me:

void lin(void)

It is not very obvious what "lin" stands for. Is there some reason that you did not want to call it something more obvious, like "lcd_init"?

And quite frankly, anyone trying to use your code would probably be far more frustrated than, say, the Fleury code, since for most people it would simply not work.

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

and THANK U "JohanEkdahl"

I know I can be an *ss-hole from time to time, quite frequently whining etc. I do try to stay out of glorifying myself. But the line is drawn right here.

While I understand that my demo code has helped you write the code you present above and got your LCD working, I'll have to say that the code above is quite crappy. Compared to my code you've managed to
- Remove symbolic names for LCD commands, instead having hexadecimal values in the executable code (aka known as "magic numbers"),
- Messed up the init function so it is quite unreadable, and certainly does not follow the init sequence stipulated in the 44780 data sheets,
- Chose totally incomprehensible names of functions and meaningless names for parameters and variables (a, b, c, d, e..)
- Failed to define eg port names so that you need to change only one place if you want to use another port (instead, you have "PORTA" in about twenty places).

Also:
- the function di(...) seems to be a function that outputs n integer in hexadecimal format (hard to tell, as it is more or less incomprehensible). First: You should keep conversion from integer to string separate from the actual output to the LCD. Second: There is a standard function that can do the conversion for you: itoa() . Instead of the unreadable gibberish, you'd end up with something like:

int i = 
char aString[7];
itoa(aString, i, 10);
LcdSendStr(aString);

and (of-course)

void LcdSendString(char * theString)
{
   char * pChar;
   while (*p != 0)
   {
      LcdSendCharacter(*p);
   }
}

(All code above sketchy, as I am not at a computer with avr-gcc right now).

I would recommend you to start refactoring your code based on these comments.

I would recommend anyone else to stay away from the code as displayed above, going for either one of the "libraries" (for real-word use) or my demos (for testing setup etc).

Sorry, tilak, but it had to be said..

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

JohanEkdahl wrote:
I would recommend anyone else to stay away from the code as displayed above, going for either one of the "libraries" (for real-word use) or my demos (for testing setup etc).

Even i would request to stay away from my code !!!!!!!!

It is best to go with the datasheet.
It is just a test set up for those who need to see their lcd working(iff they fail with other great codes available)...NOTHING MORE...:oops:

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

Quote:

It is just a test set up for those who need to see their lcd working

But Johan already said it violates the HD44780 spec. - exactly how does that make it a valid test?

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

it is working smoothly in every situation.

The functiondoes print integers in their decimal form .

I thought using library functions will require more memory and increase unnecessary MCU load...(i am not clear about it)

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

Quote:
it is working smoothly in every situation.

Proof? If it violates the specifications, do you not think it is likely that it will fail in some circumstances?
Quote:
I thought [...] (i am not clear about it)

Assumption and ignorance is the mother of many foul-ups.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

I am using avr studio4. I downloaded fleury's library.But whenever i try to add lcd.c and test_lcd.c under add existing source files, it is blocked with a message saying that the file contains illegal characters.

Please help.

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

Sounds like they are corrupt. What happens if you try to edit them with something like Notepad.exe outside of Studio?

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

Thank you for replying
I can edit it in notepad.No problems there. But can't add it as a source file in studio.
Is there any new version of avrstudio with an inbuilt lcd library file?
The code i am trying to compile was originally written using codevision which has a lcd library. I did make all the changes in the header files needed for avrstudio4 .So will the lcd part of my code work if i manage to integrate pfleury's code into avrstudio4 ?

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

Quote:
Is there any new version of avrstudio with an inbuilt lcd library file?

No.

Quote:
The code i am trying to compile was originally written using codevision which has a lcd library. I did make all the changes in the header files needed for avrstudio4 .So will the lcd part of my code work if i manage to integrate pfleury's code into avrstudio4 ?

If you're asking "does CodeVision's and Fleury's LCD lib have the same API?" then: No.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

I included the lcd source file as a function in my original code and called it to the main program
and added lcd.h to existing header files.
Build failed with one error:

cc1.exe: error: C:\Documents and Settings\user1\Desktop\us project\lcd.h: not a directory
How do i get around this problem?

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

IIRC there has been reports about AVR Studio not handling file paths with spaces in them correctly.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

so all i need to do is rename the folder???

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

Do you want me to guarantee that that is all you need to do? I won't.

Instead of asking, and waiting for an answer - don't you think that you'd have an answer all by yourself by now if you just had tried it? :roll:

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Quote:

cc1.exe: error: C:\Documents and Settings\user1\Desktop\us project\lcd.h: not a directory
How do i get around this problem?

That error sounds like you use -I on the command line but instead of naming "-IC:\Documents and Settings\user1\Desktop\us project\" as the directory to look in you actually added the filename to the end "-IC:\Documents and Settings\user1\Desktop\us project\lcd.h"

If you are going to use -I then give directory names, not filenames.

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

@ JohanEkdahl, i had already tried it out before asking that question and found that it wasn't working :). Just wanted to recheck if i had understood correctly.

@clawson,
I am sorry but i don't understand.Could you please elucidate.

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

Quote:

Could you please elucidate.

Well I could but I just noticed a far more serious problem. Your error was:

cc1.exe: error: C:\Documents and Settings\user1\Desktop\us project\lcd.h: not a directory 

I'd start by working out why on earth cc1.exe was being invoked. There is no cc1.exe for the AVR8's that this LCD code is written for. The tool that should be invoked to build avr-gcc programs on Windows is called avr-gcc.exe so I'd start by fixing that.

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

ok. managed to solve all the other problems. Used another lcd library.Now i have an error

c:/winavr-20090313/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr5/crtm16.o:(.init9+0x0): undefined reference to `main'

what does this mean? Does it only imply a problem in my code or does it refer to anything in the new library?

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

It simply means that you have no main() function in the project. Every C program needs one. You need to write one.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

But i did write a main function!

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

But the compiler obviously doesn't see it.

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

But i did write a main function!

- Check spelling
- Check casing
- Check that the file with the main function actually has been added to the project

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

i am interfacing my JHD162A LCD with my atmega 8 uC with fuse bits set for internal clock of 1MHz.i have changed some things in header file like Xtal frequency to 1000000Ul, lcd data ports as my conveinence.my program is-
#define F_CPU 100000UL // defines the clock speed
#include // includes input/output header file
#include // includes delay header file
#include"lcd.h" //include lcd.h
#include"lcd.c" //include lcd.c

int main (void)
{
while(1)
{
lcd_init(LCD_DISP_ON);
lcd_puts("Hello... 123\n Testing");
}

return 1;
}

when i build it, it shows error-
rm -rf l.o lcd.o l.elf dep/* l.hex l.eep l.lss l.map
Build succeeded with 0 Warnings...
avr-gcc -mmcu=atmega8 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT l.o -MF dep/l.o.d -c ../l.c
avr-gcc -mmcu=atmega8 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT lcd.o -MF dep/lcd.o.d -c ../lcd.c
avr-gcc -mmcu=atmega8 -Wl,-Map=l.map l.o lcd.o -o l.elf
lcd.o: In function `lcd_command':
C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:356: multiple definition of `lcd_command'
l.o:C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:356: first defined here
lcd.o: In function `lcd_data':
C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:368: multiple definition of `lcd_data'
l.o:C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:368: first defined here
lcd.o: In function `lcd_gotoxy':
C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:387: multiple definition of `lcd_gotoxy'
l.o:C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:387: first defined here
lcd.o: In function `lcd_getxy':
C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:410: multiple definition of `lcd_getxy'
l.o:C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:410: first defined here
lcd.o: In function `lcd_clrscr':
C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:419: multiple definition of `lcd_clrscr'
l.o:C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:419: first defined here
lcd.o: In function `lcd_home':
C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:428: multiple definition of `lcd_home'
l.o:C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:428: first defined here
lcd.o: In function `lcd_putc':
C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:438: multiple definition of `lcd_putc'
l.o:C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:438: first defined here
lcd.o: In function `lcd_puts':
C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:486: multiple definition of `lcd_puts'
l.o:C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:486: first defined here
lcd.o: In function `lcd_puts_p':
C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:503: multiple definition of `lcd_puts_p'
l.o:C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:503: first defined here
lcd.o: In function `lcd_init':
C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:522: multiple definition of `lcd_init'
l.o:C:\Users\ashish\Desktop\c\lcd\default/../lcd.c:522: first defined here
make: *** [l.elf] Error 1
Build failed with 1 errors and 0 warnings...

please tell what to do

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

You #include ONLY the .h, not the .c, you just add the .c to the list of files to be compiled and then the linker will join them (you already have achieved this anyway and that's why you got multi-def's - one for the copy in the linked file and one for the copy in the #include copy)

Cliff

PS suggest you read Managing large projects which explains splitting functionality across multiple .c files.

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

ok, ya i removed #include"lcd.c" it shows no errors now, i burned it on my microcontroller, but lcd shows lower row having black boxes, i have checked there is no shorting of pins on my lcd,

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

Quote:

but lcd shows lower row having black boxes

Ah! The good ol' "the black boxes are coming"... :D

Have you set up the LCD routines to initialize the LCD for two lines?

lcd_puts("Hello... 123\n Testing");

Depending on the functionality you might find that "\n" does not have the effect you expect..

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

i have also tried burning
int main(void)
{
lcd_init(LCD_DISP_ON); /* initialize display, cursor off */
while (1) /* loop forever */
{
lcd_clrscr(); /* clear the screen*/
lcd_puts(“test program”); /* displays the string on lcd*/
_delay_ms(50);
}
}
but the same problem

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

Quote:

i have also tried burning
[...]
but the same problem

Again: Have you adjusted the setup/init-sequence so that the display is initialized to use two lines?

All multi-line LCD displays that I know of come up in one-line mode by default.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

can u tell how to adjust it

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

Can I just remind you that the purpose of this thread is to discuss the tutorial in the first post. Not to diagnose some implementation problem you have. If you tell me what you want the thread to be called I will cut the most recent posts from the end of this thread and put a new thread under your chosen name in AVR Forum.

Moderator.

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

now i can see text on my lcd but the backlight is not glowing, i have made necessary connections.

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

we have to set optimization in project configuration options also???

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

ashish.master2 wrote:
can u tell how to adjust it

No, because you haven't told us what LCD "library" you are using.

Quote:
we have to set optimization in project configuration options also???

How could we possibly tell? For the same reason as above.

---

I agree with Cliff. This thread is turning ridiculous. Instead of being a discussion of the tutorial as such it has turned into the megalomaniac LCD support thread. There are a few other threads that also suffers from this (the timer/PWM tutorials comes to mind).

What can we do about this? One suggestion would be to cut this thread into three:
- The tutorial proper.
- A separate thread for discussing the contents of the tutorial.
- A separate thread for the LCD support that now makes up the bulk of this thread.
The tutorial proper would have links to the two ther threads explaining their respective purpose, and then be locked.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Johan,

To be honest I don't know what can be done about this - you have to applaud newcomers with an LCD problem for having bothered to use "search" to get here in the first place and I guess it's inevitable they'll just tag their query onto the end so I could chop the threads but I bet a pound to a penny that it'd be the actual "tutorial" thread itself that these newcomers continue to tag their queries onto.

All I can really do is "excise" the noise from time to time but, to do that, the user has to tell me what they want the thread called or else they won't have a clue where to go looking to find it (not everyone knows about "find all posts by user XXX")

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

Cliff!

I suggested the tutorial thread proper be locked. The newcomers would then have to select one of the links which could be called:

-I want to ask a question about why my LCD is not working or similar
-I want to discuss or correct the contents of this tutorial

Would they select the applicable link correctly? Maybe not. Forget it...

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

The site has a wiki page that is totally underused. The tutorials themselves should be there, and this forum be discussions about the tutorials, similar to the projects.

Regards,
Steve A.

The Board helps those that help themselves.

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

Hello,

first of all i have to say i am beginner :)

I followed these steps, and i finally made my 16x2 LCD work :)

But i bought today 40x4 LCD.

I have two questions regarding making it work:

how do i have to config lcd.h file?

the display has two E terminals.

did anyone tried to make such display work?

PS: i have ATMEGA88

thank You!

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

The HD44780 controller that these displays use can handle at most 80 character cells. Since 4x40 = 160 such a display has two HD44780 on board. They share all signals except the E line which is separate for each half of the display.

As far as I know Peter Fleury's "library" does not support 4x40 displays.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Yes, it has two E lines, i am not sure if there is HD44780 because when i wire it to AVR and leave set HD it does not display anything at all (at least first two lines)and if i change in lcd.h controller to KS it shows just first row - not characters, just black squares

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

Quote:

if i change in lcd.h controller to KS it shows just first row - not characters, just black squares

Contrast control?

If you change only your E line to E2 and leave everything else as it is, will are the two last lines filled with black boxes now?

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

I have to check :D

regarding the contrast, i have read in datasheet that if YOu want to control LCD contrast from "outside" You should desolder resistor R12, which i saw is there, that is why i did not connect the pin.

thank YOU!

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

Could you provide a link to a "product page" or the data sheet?

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Yes,

This is first
http://www.gme.sk/_dokumentace/dokumenty/513/513-127/dsh.513-127.1.pdf

And second one
http://www.gme.sk/_dokumentace/dokumenty/513/513-080/dsh.513-080.1.pdf

I did not search for prouct pages because on the first datasheet i found that LED backlight voltage should be within range of 4,2 to 5V. So i tried to turn the backlight on, nothing happened. so then i was measuring forward voltages of the LED sections and realized that supply voltage is almost 11V....damn :)

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

Quote:
realized that supply voltage is almost 11V

Wall-wart?

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

sorry, what does it mean? hehehe

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

When I type "wall wart" into Google Images it says:

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

Hehehe exactly :) sorry :)

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

I was about to post a question but i managed to fix the problem while writing :)

Thank you for the tutorial and for the great AVR forum you have here, it's been really helpful.

I'm using PORTC(0-3) -> D4-D7, PD5-RW, PD6-RS and PD7-E.
The problem was on the JTAG, i wasn't disabling it properly (twice within four cycles).

I'll go play with it now, thanks again.

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

Hey guys,
I have been having a great difficulty the past few nights to run a 44780 compatible(at least I think so) display, which I bought on eBay from a Chinese seller.

I tried to write my own code for driving it and I've been following this tutorial http://www.8051projects.net/lcd-interfacing/introduction.php. A friend of mine did it with a PIC MCU and suggested it to me. I'm using a mega16L in 8bit mode. The display is a single-line 16 character one.

The thing is that I don't see anything on the display. Nor cursor, nor anything else.

And when I send a command for the cursor to go to it's home address, the B/F doesn't go low.

Here's my code. I'll be gratefull if someone can take a peek and tell me if he sees anything not right :)

#define F_CPU 8000000UL
#define DATA PORTA

#include 
#include 
#include 

//RS - B1
//R/W - B0
//E - B2
//D0-7 - A0-7

void EN(unsigned char value){if(value) {PORTB |= 4;} else {PORTB &= ~4;}}
void RW(unsigned char value){if(value) {PORTB |= 1;} else {PORTB &= ~1;}}
void RS(unsigned char value){if(value) {PORTB |= 2;} else {PORTB &= ~2;}}

void LCD_busy(void){
	PORTD = 0b00100000; //busy signal LED on
	DDRA = 0x00;
	RW(1);
	RS(0);
	EN(1);
	while(PINA & 0x80 == 0x80) { EN(0); EN(1);}; //wait
	EN(0);
	DDRA = 0xFF;
	PORTD = 0; //busy signal LED off
}

void LCD_command(unsigned char value){       
	RS(0);
	RW(0);
	EN(1);
	DATA = value;   
	_delay_ms(10);
	EN(0);
	LCD_busy();
}

void LCD_sendData(char value){        
	RS(1);
	RW(0);
	EN(1);
	DATA = value; 
	_delay_ms(20);
	EN(0);
    LCD_busy();          
}

void LCD_sendString(char *value){
     while(*value)              
       LCD_sendData(*value++);  
}


void LCD_init(void){
	
	
	LCD_command(0x30);//8bit 1 line 5x7 dots
	LCD_command(0x01);//clrscr;
	LCD_command(0x06);//auto increment, no shift
	LCD_command(0x0F);//lcd on cursor blinking
	LCD_command(0x80);//go home

}




int main(void){ 
	DDRB = 0xFF; PORTB = 0x00; // RS, RW, E are output;
	DDRD = 0x40; PORTD = 0x00; // signaling
	DDRA = 0xFF; //DATA ouput
	_delay_ms(100); //Vcc stability
		
	LCD_init();

 	while(1){   
		
			
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I tried to write my own code for driving it

Then, to test the electronics (contrast setting etc) why not use one of the many proven libraries for avr-gcc/HD44780 and then you can make your own bazillionth attempt at reinventing the wheel when you are sure the electronics is working OK. Maybe try either the HD44780 code that shipped with your compiler or Fleury or Stang libs.

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

1. Somewhere in this thread there is one or more link(s) to minimal LCD-demos posted by me on this site. They are fairly adoptable to different pin-outs. The point with those are i) that they have been proven to work and ii) they are the simplest possible. They make for a good proof of having eg your wire-up correct.

2. Although it might work, your init sequence is not according to spec in the HD44780 data sheet.

3. You are trying to handle the busy flag. Don't bother with this until you've got the LCD working. Instead, rely on running the AVR slow, and use delays where needed. (My demo code is good for running to up to at least 8 MHz).

4. You have the data pins on port A. Is this an AVR with the ADC on port A, and if so: Did you connect AVCC?

My $.02 - HTH!

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

@clawson:
Sorry for the late response!

Till now I have tried four different libs for this type of LCD and none of them worked. I then decided to write my own. So yeah I tried the so called easy stuff :)

@JohanEkdahl:
1. I'll try to find your library and try it.
3. Tried it @ 1 MHz(internal RC) and I think this is slow enough. But the thing is that I didn't manage to run it even with the factory delays given in the data sheets.
4. I'm beginning to see my problem here :) I didn't bother to connect AVCC cause I didn't use the ADC. Will try this out immediately!

Thank you for the kind help!

btw what does "My $.02 - HTH!" mean?

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

But you are far better using proven code to prove your electronic wiring.

Quote:

what does "My $.02 - HTH!" mean?

"My two cents" (in England it's "my two penneth"). It means "my small contribution to the discussion".

"HTH" - Hope That Helps.

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

Quote:

@JohanEkdahl:
1. I'll try to find your library and try it.

Its not a library. It's the smallest LCD demo possible. Just inits and write a string. You'll find it here: http://www.avrfreaks.net/index.p...

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Hi,

I have a problem with my lcd display. I tried to program it in C, however what i got is just 1 row of black squares (one line is black while nothing is displayed on the second one), i tried few codes from that thread with the same result

recently I noticed that even when I erase all the data from my ATMEGA8 lcd is the same (1 row black - 2 row nothing)

I'm using lcd from FORDATA company.

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

Quote:
1 row black - 2 row nothing)

Bad initialization.

Start by using someone else's proven code, and then use that to write your own if you really feel you need to.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Hi guys,

For a while i'm struggling to learn about LCDs but i have some problems with string,integer and characters.

As far i know only strings and characters can send to the display and when i need to send some integer i need to convert them to string(it is true?)
I try to convert int to char but with no luck:

char C;
int i=1;
C=(char)i;
putc(C);

And int to srt:

char C;
int i=1;
itoa(i, C, 10);
puts(C);

The same doesn't work :(
for itoa i use: stdlib.h library.

ps. I use an 2x16 LCD (HD44780 compatible) and Atmega 8(1Mhz internal clock).
can somebody help me out.

Thanks in advanced.

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

Quote:

but with no luck

And what is character 0x01 in the LCD's character set then? (unlikely to be '1' that would usually be 0x31)
Quote:

for itoa i use:

itoa() is the function to use but there's no evidence of you doing so here?

char Cbuff [8]; 
int i=1; 
itoa(i, Cbuff, 10); 
for (i=0; i

There are FAR better ways to do this but I tried to keep close to your own code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
char C;
int i=1;
C=(char)i;

But all that does is change the number from a 16 bit int to an 8 bit int.

char C;
int i=1;
itoa(i, C, 10);

Almost there. itoa() converts the integer to a string, not a single character. An int could produce a string up to 6 characters long (when converting to decimal, longer if converting to a lower base such as binary). Plus you need one more character for the terminating NULL:

char s[7];
int i = 1;
itoa(i, s, 10);
puts(s);

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

can somebody help me out.

Yes, partly you yourself. You need to get a good book on the C programming language and read it.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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 guys!

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

HI I am using atmega16 board and when i run a simple program for lcd display i get error messages sayong lcd.h n such file or directory, where do i find it and what is it taht i am doing wrong. plz help.

Thanks

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

Quote:

a simple program for lcd display

It seems you didn't write that program yourself, so tell us where you found it and we will be in a better position to help.

Quote:

what is it taht i am doing wrong

Missing lcd.h. That is obvious from the error message. :roll:

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

ITs the program from avr tutorial, i need to include lcd.h library files but i dint fine it in the link provided.
thnx

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

Quote:

but i dint fine it in the link provided

What link?

(pulling teeth anyone?)

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

Lets assume that it is the LCD "library" that is at the start of this thread - the one by Peter Fleury ( http://www.jump.to/fleury ).

If so, then follow the link, then at the left click Libraries. Then download the lcdlibrary.zip in which you will find the file lcd.h. Put that file in your project directory.

When you don't get the LCD to work - which you most likely won't - before asking any further questions please read the documentation for Peter Fleurys LCD routines (to be found on the same web-site).

ATTENTION MODERATOR: Could you please edit the very first post in this thread and insert a blank between the link to Fleurys stuff and the period that follows. The forum software has the nasty habit of including the period in the link, rendering it dysfunctional.

[done - I took the opportunity to try and tidy it up a bit - I'd never read it before and didn't realise what a mess such an important tutorial was!]

Thank you, and of-course you did the ReallyTidyThing[tm], and put URL tags around it rather than just the space to keep the period away from it.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

hi, what i mean to ask is where do i need to export/save the lcd.h file in my program? i tried saving it in the header files but on compiling i still get the error 'library not found'

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

Quote:

i still get the error 'library not found'

That's not the same error as you had before (which was "no such file or directory").

Please do a build, copy the output and paste here verbatim. Less guesswork for us makes for a faster and more to the point answer to you.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/bin/ld.exe: cannot find -lC:\WinAVR-20100110\avr\include\avr\lcd

What does this error means. I am using atmega16. please reply.

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

That is an incomplete error message. It probably wrapped to the next line, and you didn't manage to copy/paste it all.

The error is from the linker, and I'll speculate that it is actually "lcd.o" that it can not find. Could you post a copy of the complete output from the build? (All lines)

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Build started 19.8.2010 at 12:43:50
avr-gcc -mmcu=atmega16 -Wl,-Map=test3.map lcd.o test1.o -o test3.elf
avr-gcc: lcd.o: No such file or directory
make: *** [test3.elf] Error 1
Build failed with 1 errors and 0 warnings...

now this error is coming. I am testing my lcd right now but its not working right now.

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

The error message is from the linking stage, trying to combine lcd.o and test1.o into test3.elf. For some reason lcd.o is missing.

Is this an AVR Studio project? If so, could you just ZIP the whole thing up and attach it to a post here?

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

This is the screenshot.

Attachment(s): 

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

yahooooo..!!! its working... i have not added lcd.c into the source file. so by adding it my program is running... thanks johan... :)

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

Glad that it worked out. Still one thing to correct that might bite you in the future: Remove lcd.h from the Source files folder in the project. (It will then appear under Header files automagically, since lcd.c #includes it.)

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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

Hello. I am trying to simulate the LM016L lcd interfaced with ATMEGA16 on proteus. But it is not working. I have used the code written on this forum and also the header file "lcd.h" So please tell me what can be the possible reason for it? Is it a HD44780 based LCD? And what changes i have to make in the header file?


#include 
#include 
#include "lcd.h"

int main(void)
{
lcd_init(LCD_DISP_ON);                /* initialize display, cursor off */
while (1)                         /* loop forever */
{
lcd_clrscr();                      /* clear the screen*/
lcd_puts("test program");             /* displays the string on lcd*/
_delay_ms(50);
}
} 
Last Edited: Thu. Aug 19, 2010 - 05:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Screenshot.

Attachment(s): 

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

Quote:

on proteus.

Waste of time - wire up a real AVR and do what you want to do on that. A real AVR behaves exactly like a real AVR not some half baked simulator.

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

Yes, it is HD44780, and I agree with Cliff, wire it up for real.

Regards,
Steve A.

The Board helps those that help themselves.

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

On a more official note can I just say that this thread is NOT to diagnose every last HD44780 implementation problem that comes up (10+ pages is too much). The idea of the Tutorial Forum is for authors to present a tutorial in the first post then allow others to contribute ideas/corrections to that article in subsequent posts. For general LCD implementation problems/questions please start a new thread in AVR Forum (but thanks for using "Search" which presumably is why you got here in the first place!)

Moderator.

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

hello,
i am trying to interface lcd with the ATMEGA16 but nothing is displayed on the screen. the pins description are:

1  Vss 
2  Vcc 
3  Vee 
4  RS 
5  R/W 
6  EN 
7  DB0 
8  DB1 
9  DB2 
10 DB3 
11 DB4 
12 DB5 
13 DB6 
14 DB7 
15 LED+ 
16 LED- 

and i have downloaded the source file from the link given on first page and also the code written on first page. What possible changes should i do the header file so that the lcd starts working. I have connected lcd to port B.

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

You did follow the link to Peter Fleury's site which shows exactly how to connect it in both 8bit and 4bit (preferable) modes? The diagrams are here:

http://homepage.hispeed.ch/peter...

They simply work.

In the 4 bit picture:

he's using PORTA of that AVR, just switch his connections in the same order over to PORTB for your AVR then in the lcd.h from the Fleury code just change:

#define LCD_PORT         PORTA        /**< port for the LCD lines   */

to be PORTB.

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

Thanks and i have done possible changes in the header file but still its not working. I am uploading the image of the board i am using. Please see to it. It has 16MHz crystal oscillator.

Attachment(s): 

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

Quote:
You did follow the link to Peter Fleury's site which shows exactly how to connect it in both 8bit and 4bit (preferable) modes?
The Fleury library doesn't really support 8 bit mode. The 8 bit diagram on that page shows how to connect in memory mapped mode which can only be used on AVRs with an external SRAM interface.
Quote:
I am uploading the image of the board i am using.
And how is that going to help us? We certainly can't see how the LCD is hooked up from the photo. The connection diagram that you posted earlier shows the 4 data lines going to D0-D3. This will not work. In 4 bit mode you need to hook to D4-D7.

Regards,
Steve A.

The Board helps those that help themselves.

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

hi everyone

I am using codevision avr which has an inbuilt lcd library file. So i wrote the code, compiled it, built the hex file and burnt it into my atmega16.

But all my lcd shows is 16 blocks. I compiled the lcd demo code available in codevision too..but the lcd shows the same result.

i am using jdh21a lcd display.

Please help.

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

What was the return value from the call to lcd_init()?

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

Quote:

But all my lcd shows is 16 blocks.

What are your arrangements for contrast control?

The Google oracle know nothing about "jdh21a" apart from this thread. Could you give a better description, or a web link to a good product page? Is it a 2x8, 1x16, 2x16 or something else?

Describe how you have your LCD wired up to the AVR.

"Ziggy really sang, screwed up eyes and screwed down hairdo. Like some cat from Japan, he could lick 'em by smiling. He could leave 'em to hang. He came on so loaded man, well [..] and snow white tan. [Bowie]

 

"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]