Jul-28th-2008

Using LCD Module with AVRs


When you start working with LCD modules you will start feeling the real power of MCU and your imaginations will be touching sky you will wonder how many exciting a powerful gadgets you can create and that’s so very easily.

LCD Modules can present textual information to user. It’s like a cheap “monitor” that you can hook in all of your gadgets. They come in various types. The most popular one can display 2 lines of 16 characters. These can be easily interfaced to MCU's, thanks to the API( Functions used to easily access the modules) we provide. LCD interfacing is just fun !

lcd module

Fig: A 16x2 LCD Module

 

PIN Configurations.

The lcd modules has 16 PINs for interfacing. The details are given below.

LCD Module Pin Configuration

1 VSS (GND Supply)

2 VCC (+5V)

3 VEE (Contrast Adjust)

4 RS
5 R/W
6 E
7 DB0
8 DB1
9 DB2
10 DB3
11 DB4
12 DB5
13 DB6
14 DB7
15 LED +
16 LED -

 

Connection with Board MINI.

The lcd module can be easily connected to the Board™ MINI the connection is as follows.

lcd modulec connection with avr

Fig: Connection

Connect the required pins of PORTC and PORTD as shown in the diagram. The PORTs are clearly marked in the board. Connect to PORTD using a 8 PIN connecter and to PORTC using a 6 PIN connecter. Then supply the LCD using the onboard 5V supply output using a 2 PIN connecter. Leave D0-D4 of LCD unconnected. Note all the required connecters are provided with the kit.

Adding LCD support to your project

To add LCD support to your C projects we have made a easy to use library. To use this library first create a new project in AVR Studio then copy the following files to your project folder. lcd.c lcd.h myutils.h from x:\xAPI\lcd-v20\ (where x:\ is your CD/DVD drive) then add them to your project by right clicking project view and selecting “Add Existing Source File(s)…” and then select the “lcd.c”. Similarly add “lcd.h” and “myutils.h” in Header Files section. Now you are ready to start coding LCD applications !!!
avr studio

Fig: Adding files to projects.

Programming.

In your main C file include the file lcd.h as #include “lcd.h” then initialize the LCD subsystem using a call to LCDInit(LS_BLINK|LS_ULINE); the argument specify the type of cursor required the LS_BLINK gives a blinking cursor. LS_ULINE gives a underlined cursor. To write any text call LCDWriteString("Welcome"); To write any number call void LCDWriteInt(int val,unsigned int field_length); This will print a integer contained in “val” . The field length is the length of field in which the number is printed.

For example LCDWriteInt(3,4); will print as follows

lcd module

While LCDWriteInt(123,5) will print as follows.

lcd module

 

To goto any particular position on screen call.

void LCDGotoXY(uint8_t x,uint8_t y);
For example the following will take the cursor to (11,1) i.e. 12th column of second line.
LCDGotoXY(11,1);
using lcd module  with avr microcontrollers

Fig: Cursor Positioning.

Now anything you write to LCD will be printed at (11,1).

Clearing the display

LCDClear();
This will clear the display and bring the cursor back to (0,0). There are two more functions that will go to specific position and print in one call.
LCDWriteStringXY(x,y,msg);
____________________________
x,y : the location where to print “msg” 
msg : the message to print 
Ex: LCDWriteStringXY(3,0,”hello”); 
    LCDWriteStringXY(8,1,”world”); 
Output:
using lcd module  with avr microcontrollers

Fig: Cursor Positioning.

Similarly there is a function for integers.
LCDWriteIntXY(x,y,num,field_length);
____________________________________
x,y : the location where to print “num”
num : the integer number to print  
field_length : the length of field (see LCDWriteInt() function above).
Now you know the basics of LCD interfacing lets jump to a sample program that will demonstrate the functions you learned. Note: The sample programs are available under “samples” folder in support CD. The hex files ready to burn are available under “hex” folder under the “samples” folder.

Sample Program


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

#include "lcd.h"

void main()
{
   unsigned char i;

   //Initialize LCD module
   InitLCD(LS_BLINK|LS_ULINE);

   //Clear the screen
   LCDClear();

   //Simple string printing
   LCDWriteString("Congrats ");

   //A string on line 2
   LCDWriteStringXY(0,1,"Loading ");

   //Print some numbers
   for (i=0;i<99;i+=1)
   {
      LCDWriteIntXY(9,1,i,3);
      LCDWriteStringXY(12,1,"%");
      _delay_loop_2(0);
      _delay_loop_2(0);
      _delay_loop_2(0);
      _delay_loop_2(0);

   }

   //Clear the screen
   LCDClear();

   //Some more text

   LCDWriteString("Hello world");
   LCDWriteStringXY(0,1,"By YourName Here");    // <--- Write ur NAME HERE !!!!!!!!!!!

   //Wait
   for(i=0;i<100;i++) _delay_loop_2(0);

   //Some More ......
   LCDClear();
   LCDWriteString("    eXtreme");
   LCDWriteStringXY(0,1,"  Electronics");

}

Advance Use – Configuring Connections.

The library is designed to be fully customizable. If you want to connect the LCD module to some different i/o ports of the MCU then you can do so easily. You just have to modify the lcd.h file. Let’s see how. Open lcd.h and find a section “LCD Connections” it looks like
lcd library setup for avr mcu

Fig: Configuring LCD Connection.

Set LCD_DATA to the port where you have connected the LCD data lines. Data Lines must be connected to any port say PORTB starting from pin-0 to pin-3. i.e. If you set #define LCD_DATA B you should connect like this :

PORTB.0->DATA4 PORTB.1->DATA5 PORTB.2->DATA6 PORTB.3->DATA7

The library uses advance 4-bit mode so DATA0-DATA-3 of LCD are not used, saving 4 MCU pins! Now set the port where you have connected LCD’s ‘E’ signal. In example it is PORTD so #define LCD_E D Then specify to which PIN of PORTD it is connected, this is done by #define LCD_E_POS PD6 So ‘E’ pin of LCD is connected to PORTD-6 In same way set RS and RW signals. And that’s all! So you saw how easy is to customize the library.

Downloads

Download this tutorials with all required files.(library and sample code included)

 

What's next ???

We will see what different Internal peripherals available on the AVR mcu and the methods of interface/communication from them. This will help you use internal peripheral like ADC,Timers,USARTs etc which will be covered in later tutorials.

Have fun and don’t forget to bookmark this page. If you think this tutorial has helped you please post a comment.


100 Responses to “Using LCD Module with AVRs”

  1. 1
    Abhijeet Says:

    Thanks for the tutorials n carry on… rest assured there are many people learning something from them! Can’t wait for the next articles!

  2. 2
    Using the Analog To Digital Converter. | eXtreme Electronics Says:

    [...] ForLCD Interfacing See- “LCD Interfacing Tutorial” [...]

  3. 3
    Using IR remote with AVR MCUs | eXtreme Electronics Says:

    [...] the key code of the various keys on your remote control. To learn more about LCD interface with AVRs see this. The connection is different for ATmega8 and ATmega16/32 so I am giving both [...]

  4. 4
    Nick Says:

    Why is this lcd display being operated using 2 ports? Can it be set up to use only one?

  5. 5
    Nick Says:

    Oops i’m an idiot. This site was very helpful, THANKS!

  6. 6
    bla Says:

    wonderful site, but your css-layout seems to be broken on
    http://extremeelectronics.co.in/avr-tutorials/using-lcd-module-with-avrs/
    (tables are not displayed correctly!)

  7. 7
    Avinash Says:

    @bla

    Hi,
    Thanks for reporting! Ya the content just now looks horrible!!! Yesterday I applied a new theme and due to lack of time cannot complete it properly.

    I will clean everything soon.

  8. 8
    Avinash Says:

    @bla

    I have edited the page, now the layout is much better and readable.

  9. 9
    Interfacing Temperature Sensor with AVR Microcontrollers - LM35 | eXtreme Electronics Says:

    [...] Using LCD Modules with AVRs. [...]

  10. 10
    yaksha Says:

    Hi,
    I managed to burn the hex file onto the MCu but im unable to see the output on the LCD. how can i fix this?

  11. 11
    Avinash Says:

    Check the following

    1)The Code is for ATmega8 MCU
    2) See the connection section in lcd.h file and confirm that they are same as the physical connection u made.
    3)Connect a 10K POT between Vcc and GND and the centre PIN to PIN 3 of LCD (contrast) and adjust it till chars are visible. But as in circuit above u can also GND this PIN.
    4)Pls check all connection

    We can discuss further on this in forum
    http://forum.extremeelectronics.co.in/viewforum.php?f=2

  12. 12
    pooja Says:

    Thanks for the Tutorials… I need a help that how the data trnasmitted to LCD and where the data is stored to display on the LCD.Pls kindly clear my doubt by explaining the transfer of data to LCD…

  13. 13
    Avinash Says:

    Hello Pooja
    :)

    To know the internals pls explore the source code and see this link

    http://forum.extremeelectronics.co.in/viewtopic.php?f=3&t=9

  14. 14
    Jonathan Says:

    Hi.

    Thanks! After trying out like 6 other lcd libraries out there on my ATMEGA-128 @ 16Mhz, yours is the only one I could get to work! Thanks!

  15. 15
    Avinash Says:

    Hello Jonathan,
    :)
    Nice to meet you! I am happy that my codes are helping peoples.

  16. 16
    levitis_leviathan Says:

    Avinash: Great library! Easy to use and modify. A question, however: How can I print the value of a variable, such as the character contained in the serial UDR register, to the LCD?

  17. 17
    Avinash Says:

    Hello Levitis,

    Yes you can print the content of a varriable.

    1)char type : USE function LCDData(char_varriable);
    2)int type see: LCDWriteInt() & LCDWriteIntXY() functions.

    :) Have a nice day !

  18. 18
    Mozard Dia Says:

    Thank you very much!
    How can i configure the library file to use it with a 4 lines 20 characters LCS?Please any help.

  19. 19
    Avinash Says:

    Hello,

    The 4 line modules are actually 2 LCD module pack into one.
    I think they are accessed like two different modules. They have 2 HD44780 controllers in them.

  20. 20
    Rakesh Says:

    Can u explain the functions that you wrote in the lcd.h file..

  21. 21
    Andrei911 Says:

    It helped me a lot, thanks. You are doing a good job ;)

  22. 22
    ankit agarwal Says:

    Dear Avinash,
    When i am compling your code it is giving 5 errors and it is saying that “lcd.h : no such file or directory exist” what should i do…

  23. 23
    Easy 24C I2C Serial EEPROM Interfacing with AVR Microcontrollers | eXtreme Electronics Says:

    [...] program demonstrate the use of external EEPROM interfaing functions. The program makes use of the LCD library for AVRs to display information in a 16×2 LCD display. The program first writes 8Kbytes of data to a 24c64 [...]

  24. 24
    suhas Says:

    in this statement how to select portb(4-7) instead of 0-3?
    #define LCD_DATA C //Port PC0-PC3 are connected to D4-D7

    code is very useful. Thank you..

  25. 25
    Elizabeth Says:

    Great ideas, is there a place to elaborate on this all?

  26. 26
    RaditPunakawan Says:

    Wew..thx bro! this lib is very helpful!!! now i can working on my final project…..lol

  27. 27
    Erik Diaz Says:

    La pagina es espectacular, soy fanatico de los AVR…
    en su sitio he encontrado cosas muy buenas!!

    Thanks…
    Saludos desde CHILE!!!

  28. 28
    santosh Says:

    can we do the program for LCD through WINAVR for ATMEGA16??????????????????

  29. 29
    Avinash Says:

    @SANTOSH

    SO WHAT IS THE THAT LONG PAGE ABOUT ???

    DON’T POST SUCH SILLY QUESTIONS!

  30. 30
    sanjay Says:

    my lcd data pins are connected to portb as
    DATA 4 – PINB 4
    DATA 5 – PINB 5
    DATA 6 – PINB 6
    DATA 7 – PINB 7

    can you give the right modification in lcd.h connection

  31. 31
    Avinash Says:

    @ Sanjay

    Tell me the position of RS/RW/ and E Pins
    also the MCU in use

    Currently you can only use LOWER NIBBLE OF A PORT (i.e. bit 0-3) for data port.

    And you are trying to use higher nibble (i.e. bit 4-7) which is NOT possible.

    :) Thankyou.

  32. 32
    sanjay Says:

    the pin cinfiguration is as
    RS – PB.0
    RW – PB.1
    EN – PB.3
    D0 – PB.4
    D1 – PB.5
    D2 – PB.6
    D3 – PB.7
    and working in 4bit mode

  33. 33
    Aditiya Says:

    Thanks for your tutorial,

    I have some question about your tutorial, I’ve been used codevision avr before, and now migrate to winavr, my LCD data port belong to PORT C4, C5, C6, C7

    how to set my data port in your lcd.h ?

  34. 34
    Varun Says:

    First of all……thank you very very much Avinash. Brilliant job with the tuts. Hats off….
    I did try this out with ATmega8 and it worked A ok.
    But now want to try this out with ATmega32 and the code doesnt seem to work.
    Before trying it out with ATmega32 i did chance the code in lcd.h file like shown below.
    But i don’t seem to get any o/p.

    Can you please help and tell me why this code only works for ATmega8 and not ATmega32 ?

    #define LCD_DATA C //Port PC0-PC3 are connected to D4-D7

    #define LCD_E D //Enable OR strobe signal
    #define LCD_E_POS PD6 //Position of enable in above port

    #define LCD_RS D
    #define LCD_RS_POS PD4

    #define LCD_RW D
    #define LCD_RW_POS PD5

  35. 35
    Avinash Says:

    @Varun
    Yes it works with ATmega8/16/32 and many more. Just check the CPU speed you set. In AVR Studio Give exact CPU frequency(crystal) in actual use.

  36. 36
    Andriu Says:

    Thank tou very much Avinash.
    I have tried it but it did not work. I am using AVR Studio for an ATMEGA8.
    When I try to Build the project there are two errors:
    “… Section .text will not fit in region text”
    and
    “… region text overflowed by 3506 bytes”

    Please, could you help me with this?

    Thank you

  37. 37
    Avinash Says:

    @Andriu,

    The problem is that you have OPTIMIZATION turned off. Go to Project->Configuration and change optimization to O2. And report to me if it solved the problem. :)

  38. 38
    Andriu Says:

    You were right, now it is built, but nothing is written in the LCD.
    It seems to write only the first line and a few seconds later, it seems to write the two lines of the LCD but there are no characters, all the points get black.
    I have a 10K pot and move the contrast but it does not work. Either it is all white or all black, the characters are not printed.
    In project options I have selected FREquency 12000000 Hz. Is it correct?

    Thank you again for your time

  39. 39
    Andriu Says:

    Hello,

    I have been trying and I can not make it work.
    I have connected ENABLE at PB5, RS at PB4 and RW at PD7.
    Can be there the problem? Should I connect all of them to the same port?

    Thank you, Avinash

  40. 40
    Avinash Says:

    @Andriu,

    What is the freq of crystal u r usin?
    and tell me the details of connection (all pins)

  41. 41
    Andriu Says:

    I am using STK500 and I amtrying to make it work at 1 MHz.
    I have changed in lcd.c and lcd.h: #define F_CPU 1000000UL
    In Project, Configuration options, Frequency: 1000000 Hz
    and when I program I select:
    – Fuses: Internal RC osc 1Mhz (I have also tried Ext. Clock)

    Connections:
    PB0 –> data 4 (11 in LCD)
    PB1 –> data 5 (12 in LCD)
    PB2 –> data 6 (13 in LCD)
    PB3 –> data 7 (14 in LCD)
    PB4 –> RS (4 in LCD)
    PB5 –> ENABLE (6 in LCD)
    PD7 –> RW (5 in LCD)

    The first line of the display is black and the second is white.
    I have repeated the assembly with a new LCD and new cables and the same is happening again. I guess I am forgetting something.

  42. 42
    Avinash Says:

    @Andriu,

    Have u edited the lcd.h file’s connection section ???

  43. 43
    Andriu Says:

    Yes, I have edited the lcd.h file. This is the text:
    #ifndef F_CPU
    #define F_CPU 1000000UL
    #endif

    #define LCD_DATA B //Port PB0-PB3 are connected to D4-D7

    #define LCD_E B //Enable OR strobe signal
    #define LCD_E_POS PB5 //Position of enable in above port

    #define LCD_RS B
    #define LCD_RS_POS PB4

    #define LCD_RW D
    #define LCD_RW_POS PD7

  44. 44
    shashi Says:

    hey nice tutorial avinash….
    if i connected the lm 35 to adc0 and humidity sensor to adc1 how to write the code for it can you help me for this

  45. 45
    Andriu Says:

    Avinash,

    thank you very much. At last I managed to make it work. I do not know why (your code seems to me all right), the atmega was in an infinite loop when I called to InitLCD().

    I have changed in function void LCDBusyLoop() the condition while (busy) for while(busy==0×00) to force it to leave the loop. And in main() I write

    InitLCD(LS_ULINE);
    LCDClear();
    LCDWriteStringXY(0,0, ” “);
    LCDWriteStringXY(0, 0, “Hello World”);

    Somehow it works.
    Again, thank you very much for the code and for your answers.
    Best regards from Spain

  46. 46
    Dollar Says:

    Avinash,
    Thanks a lot for your nice working Tutorial. I have become successful in LCD programming using ur files..
    A little problem is that it sometimes does not want to start instantly. After switch off/on of power, it then starts….Why is that..?

  47. 47
    Andrei Says:

    Hy!
    Thank you for these gresat tutorials.
    I have managed to get my 2X16 LCD to work on PORT B, but I noticed that I need that port for other things(on Atmega 16).
    I’ve connected the LCD to PORT C:
    PC 0-3 to LCD 11-14
    PC4 – RS
    PC5 – RW
    PC6 – E
    I also edited the lcd.h as it follows:
    #define LCD_DATA C //Port PC0-PC3 are connected to D4-D7

    #define LCD_E C //Enable OR strobe signal
    #define LCD_E_POS PC6 //Position of enable in above port

    #define LCD_RS C
    #define LCD_RS_POS PC4

    #define LCD_RW C
    #define LCD_RW_POS PC5

    The lcd doesn’t working, it shows only the first line with all points on.
    I have also checked the connections with a multimeter. Everything is ok.
    Please help me!

  48. 48
    Bhargav Says:

    @Andrei

    While using PORTC in ATmega16 you need to disable the JTAG functionality which is by default enabled on the ATmega16.
    See that u have disabled the JTAG functionality first.
    To disable the JTAG u need to change the high fuse bits…

  49. 49
    Andrei Says:

    Thanks for the respone. but it still doesn’t work.
    I have disabled the JTAG option and the result is the same.
    ..with AVR Burn-o-mat i wrote D9 on hfuse

  50. 50
    Andrei Says:

    ..and another thing, if i reset the MCU, one time lcd displays one line full oh pixels, and other time it shows 2 lines. I don’t know what is the problem.

  51. 51
    Bhargav Says:

    @Andrei
    please tell ur gmail id.

  52. 52
    Bhargav Says:

    R u able to do that with other ports

  53. 53
    Andrei Says:

    I have only an yahoo account bboyandru

  54. 54
    Andrei Says:

    and yes, with port B it worked

  55. 55
    Andrei Says:

    It ain’t working anymore, neither with PORT B :(

  56. 56
    Andrei Says:

    Yes!!!!
    It is working, on PORTC too, thank you so much for your time.

    The problem was that in lcd.c I have modified LCDBusyLoop function as mentioned above ( while(busy==0×00) ). I replaced with while(busy) as Avinash wrote first and is working. And with PORT C the problem was with disabling JTAG.

    Thank you so much!

  57. 57
    Tandy Says:

    Hey just wanted to check whether the LCD display you are using uses a HD44780 controller or a KS0066 controller.

    And also to check if you know whether there are any differences between them.

    Thanks

  58. 58
    Avinash Says:

    @Trandy

    They are HD44780 based

  59. 59
    Krishna Says:

    hi thanks a lot buddy!

    I have a small question please, I did all the connections properly and compiled your sample program successfully. I also accordingly changed the 12000000UL to 16000000UL in both the c file and the header file (libraries) since I’m using an external 16MHz crystal.

    My problem is that it shows all black on the first line in each box. I have no idea why, any ideas?

    thanks man :P

  60. 60
    Krishna Says:

    oh btw im using the atmega32. This is for a uni project im working on so it needs an lcd and I was lucky I found yours :) thank you!

  61. 61
    Avinash Says:

    Hey Man (Krishan),

    Do u think you can use the external crystal by just hooking the crystal to MCU? Also pls see above comments, u need to disable JTAG to use PORTC on ATmega32

  62. 62
    Krishna Says:

    Hi!

    The external crystal is connected to the mcu. Yes sure thanks I’ll disable the JTAG on the atmega32 via the fuse bits and see what happens.

    btw that was a fast reply :P

  63. 63
    Krishna Says:

    Dude you are the best! it works!! The jtag was the issue :P

    Also I just want to confirm in your tutorial it says that: LCDWriteInt(int val,unsigned int field_length);

    val is a integer value, whatever that may be, will be displayed. So if I had a global value named ‘distance’ instead of ‘val’ (since my project calculates distance), whatever value that the program calculates and stores into distance it would be displayed on the lcd.

  64. 64
    AVR Project – Relay Timer with ATmega8 AVR MCU | eXtreme Electronics Says:

    [...] program use our LCD driver library more details of which can be found in here. Use avr-gcc + AVR Studio to [...]

  65. 65
    krishna Says:

    how do i add header files in case i m using winavr(programmers notepad n makefile) instead of Avrstudio..??

  66. 66
    Avinash Says:

    @Krishna No need to add headers files just put then project dir

  67. 67
    Kostas Says:

    Nice Tutorial.Well i am one of those who has this problem, especially with portC and my jtag fuse is disabled but the problem remains.I have atmega32 with external crystal 8 mhz and using AVRSTUDIO 4 .I am sure that i have disabled JTAG fuse bit but if i am wrong here are my fuse bits : hbits are 0xD9 and lowbits 0xFD.I need immediately to use portc for Lcd only!With other ports there are no problems, its working well!Any help and reply if possible…
    Thanks

  68. 68
    Avinash Says:

    @Kostas
    Use High Fuse = 0xC9 and Low Fuse = 0xFF

  69. 69
    Andy Says:

    hey buddy! just would like to say many thanks for the libraries, they work great.

    I just have a question please. Here’s a small snippet of code.

    int main(void)
    {
    // Initialize the LCD
    InitLCD(LS_BLINK|LS_ULINE);

    //Clear the screen
    LCDClear();

    welcome(); // Welcome the user to the device

    // Initialization code here for the timers and some variables
    sei(); // Enable global interrupts

    for(;;)
    {
    // Would like some code to run here
    }
    return 0;
    }

  70. 70
    Andy Says:

    My question is that the function welcome() displays my name, and then the name of the project perfectly, however after that no code in the infinite for(;;) loop runs. I would liked to have some calculation routine there however if the LCD libraries are enabled (that is, not commented out) the for(;;) loop and the code inside it won’t run. However if the libraries initialization are commented out then access to the for(;;) loop is restored and code in it runs.

    I noticed this on the built-in debugging (im using atmega32 with the simulator also being being atmega32 within avrstudio). Also in practice, the code that was in the for(;;) routine never ran.

    During debugging, when the simulator comes to the line:
    InitLCD(LS_BLINK|LS_ULINE); <–

    AVRStudio then switches to LCD.c towards start of the line:
    initLCD(unint8_t style)

    Then when F11 is pressed again to resume debugging it goes to the delay_basic.h file to the line:
    _delay_loop+_2(uint16_6 __count)

  71. 71
    Andy Says:

    Then when F11 is pressed again it goes to the delay.h line to the _delay_ms(double_ms) function. It’s here that it is forever stuck in the while loop:

    while(__ticks)
    {
    _delay_loop_2((F_CPU)/4e3) / 10);
    _ticks–;
    {

    So I think this is probably the reason why any code in the for(;;) routine in the main function never runs. Any ideas? Please help thank you…

    PS: Sorry for bridging the question over 3 posts, I didn’t think it would allow the post to be all in one.

  72. 72
    kanha Says:

    hii
    avinash thanks for the tutorial..
    i m trying this api for atmega16l..
    what should be the frequency of mcu and what will be the fuse bits corresponding to that frequency..

  73. 73
    Mohit Agarwal Says:

    hi
    thnx for your gr8 tut
    ihave some problem
    the pin cinfiguration I used is as
    RS – PB.0
    RW – PB.1
    EN – PB.3
    D0 – PB.4
    D1 – PB.5
    D2 – PB.6
    D3 – PB.7
    and working in 4bit mode
    where do i have to make changes in the lcd.h file for the data pins and what should i write
    plz urgent

  74. 74
    Kostas Says:

    Hmm….Ainstain said that two things are infinite: the universe and human stupidity; and I’m not sure about the universe.I fixed it ,it was in front of my eyes, hardware problem.The DIP connector i used for PORTC it was backwards etc:Port0-port1….ground-Vcc for the other ports and for portC were Port7-Port6…ground-Vcc.Well i deserve the title “the ..rk of the week”:P.Thanks for your quick answer Avinash and keep your great work going on and on.

  75. 75
    binal Says:

    hey avinash i want to print the degree symbol on the lcd..plz could you help me wid that..thanking..waiting for your reply…

  76. 76
    Varun Says:

    Hey avinash…..Your lib worked great on 16×2 LCD…..i was wondering whether i cud use the same lib for a 16×4 LCD module…

  77. 77
    monang Says:

    why I cant access the forum.extreem electronics

  78. 78
    Avinash Says:

    @Monang

    Some hacker attacked the server and injected malicious code in it so I have to stop the site. I will restart it once every thing is corrected. It was very horrible experience.

  79. 79
    Ravi Kiran Says:

    Sir,
    Your way of teaching AVR is awesome…. I did not read any text book but understood AVR and able to use it for my projects.

    I have problem with the LCD library that you have provided on the website. My problem is my LCD is connected to port B and I want to change the library code for it. The LCD uses databits D0-D3. The connections are made as follows-

    RS-PB.0
    RW-PB.1
    EN-PB.3
    D0-PB.4
    D1-PB.5
    D2-PB.6
    D3-PB.7

    In the library code it is given that Px.0-Px.3 should be connected to D4-D7 of LCD. But my development board does not allow that. So please tell me how to connect PB.4-PB.7 pins of AVR to LCD’s D0-D3 data pins.

    Thank You

  80. 80
    Interfacing DS1307 RTC Chip with AVR Microcontroller | eXtreme Electronics Says:

    [...] LCD Interfacing library for Atmel AVR MCUs [...]

  81. 81
    Jimi Says:

    HI Avinash,

    This tutorial is of great use.

    I have a small question, I am trying to display characters on lcd sent via serial port. But when i send ‘a’, lcd displays ‘97′. Can you tell me how to convert ASCII to letter to display ‘a’.

    My code is:

    data = USARTReadChar(); //reads the letter
    itoa(data,buf,16); //converts to ASCII
    send_lcd_str(buf); //this function displays only strings

    Thanks.

  82. 82
    Avinash Says:

    @Jimi

    The code will be like this

    char data[2];

    data[0] = USARTReadChar(); //reads the letter
    data[1]=’\0′;

    send_lcd_str(data); //this function displays only strings

  83. 83
    Varun Says:

    Hey avinash…..Your lib worked great on 16×2 LCD…..i was wondering whether i cud use the same lib for a 16×4 LCD module…

  84. 84
    Oscar Says:

    Avinash,

    I was hoping you could elaborate more on your comments below. I would also like to use these libraries to control a 4X20 LCD and don’t really know where to start in editing the libraries.

    Avinash Says:
    Hello,
    The 4 line modules are actually 2 LCD module pack into one.
    I think they are accessed like two different modules. They have 2 HD44780 controllers in them.
    February 20th, 2009 at 12:45 pm

  85. 85
    danial Says:

    hello avinash,
    your library is very easy to us,i use it for interfacing 16*2 lcd module but for 16*4 its not working.plz help to use it with 16*4 .

  86. 86
    Ian Says:

    Dear Avinash,
    This page and your code was very helpful. I’ve got an LCD module working on PORTB of an ATTiny2313. Can you help with the following. I would like to turn the cursor off. I looked up the codes for the HD44780 and found the cursor off code. I tried adding the following to lcd.h
    #define LS_NONE 0B00000000
    Then I initialised the lcd with InitLCD(LS_NONE);
    I still get both a flashing and underlined cursor. Is there any way to turn it off?

  87. 87
    Avinash Says:

    @Ian

    I also tried to give command as per the datasheet but could not turn off the cursor. I don’t know whats the problem. If you find a solution please share with me. Thanks :)

  88. 88
    seema Says:

    Hello Avinash,
    You said you have two different codes for ATMega8 and ATMega16/32
    I am using ATMega16 so can you give the code or I can use ATMega8 code with some changes . I have already made some changes as per your tutorial. But I am using same lcd.c, “lcd.h” and “myutils.h file with only these changes:
    LCD CONNECTIONS
    *************************************************/
    #define LCD_DATA B //Port PB0-PB3 are connected to D4-D7
    #define LCD_E B //Enable OR strobe signal
    #define LCD_E_POS PB4 //Position of enable in above port
    #define LCD_RS C
    #define LCD_RS_POS PC7
    #define LCD_RW C
    #define LCD_RW_POS PC6
    Is it correct or I need to change something else also

  89. 89
    seema Says:

    hey avinash ,
    my comment is still in waiting …..would you please accept it.
    Please help my program is not working .

  90. 90
    seema Says:

    Hey I am sorry avinash , m new in this field ….but I didnt found ATMega16 code in your tutorial ….as you said you have written codes for ATMega16 also . can you please send me that link .
    If there is no code in your tutorial then is it possible to make some changes in ATMega8 code to use in ATmega16.

    thanking you
    Seema

  91. 91
    Sarunas Says:

    Hi, great website and library
    I found that cursor does’t react to ULINE and NONE(as was said), so I looked at lcd datasheet, and found that function set command have to be befor.
    so int the LCDInit(…) write

    LCDCmd(0b00101000);//function set 4-bit,2 line 5×7 dot format
    LCDCmd(0b00001100|style);//Display On

    and it works perfectly

    thank’s

  92. 92
    Avinash Says:

    @Sarunas
    :)

    Many thanks for solving the problem. I will try it out.

  93. 93
    Rohan Says:

    Avinash

    thats really cool as your others. But is seems to me your library doesnt work for the blue lcd. its ok for the green.
    Is the blue differ from green except led color?

  94. 94
    Avinash Says:

    @Rohan

    It works flawlessly on BLUE LCDs too !!! I have tested with many modules.
    Just use your Common Sense and you will get it working (I won’t give a silly tip so as how to use blue LCD as any one with brain can figure it out in less than 2 minute)

  95. 95
    seema Says:

    Hello Avinash ,

    HAPPY NEW YEAR and may god you and fulfill your dreams. hey avinash I didnt found atmega16 code for LCD display . would you please help me to get a code for atmega16 . m using 2×8 and 2×16 lcd display . In your tutorial its given only for atmega8 .
    thanking you

  96. 96
    Avinash Says:

    @Seema

    Its for all AVR so will work with ATmega16 too !

  97. 97
    ritesh Says:

    hey avinash….

    good work man…do you have any thing with LCD connected to RS-232. so that I can send data from PC to LCD.

    Ritesh

  98. 98
    ritesh Says:

    ritesh Says:
    hey avinash….
    good work man…do you have any tutorial with LCD connected to RS-232. so that I can send data from PC to LCD.
    Ritesh

  99. 99
    Boki Says:

    Thx,it works great! Finally!

    Can u tell me how to make scrolling text?

  100. 100
    joel Says:

    hello avinash….
    thank u coz u r very helpful…
    i hav interfaced 3 circuits(metal detector,natural gas detector,temperature detector) to atmega8 and this atmega8 controller is interfaced with gsm modem for sendin message to mobile phone when any 1 of the circuit o/p is positive….
    i.e…when metal/gas is detected we should get sms to our mobile…but regarding temperature after 30 seconds from the time we switch on the controller,wat ever temperature is detected we should recieve sms…pls help me with program…

Leave a Reply

Comments

    • Del Chann: Hello is it possible to use this board to interface with a smoke sensor, motion sensor,...
    • Elijah Nicolia: May I consider part regarding your main guide to my personal site
    • Tifany Wiebusch: I go along with you actually, I believe! Might this become doable for you to have...
    • Sinopteek: When i try to run this software under OpenSuSe 11.2 (x64), i’ll have next error:...
    • kapil: @Dhananjay I used that its working and it can programme 3 to 4 times after that there is a...
    • Dhananjay: Sir, At present I am using progisp to flash AT89SXX with usbasp(with modified firmware)....
    • Shashi Jain: plz dont fight wid each other…k i accept my fault… neway m not a rich person...

Video