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 !
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 ATmega8/ATmega168 etc.
The lcd module can be easily connected to the any 28 pin AVR MCU like ATmega8/ATmega168/ATmega328 etc. The diagram below shows the LCD connection with AVR MCUs port pins.
![]() |
Fig: Connection with 28 PIN AVR MCUs |
Connect the required pins of PORTB and PORTD as shown in the diagram. The PORTs are clearly marked in the board. For connection you will need single pin female to female wires. Supply the LCD using the onboard 5V supply output using a 2 PIN connecter. Leave D0-D4 of LCD unconnected.
Connection with 40 PIN MCUs like ATmega16/ATmega32
![]() |
Fig: Connection with 40 PIN AVR MCUs |
NOTE: The 10K Pot (RV1) is very important, so please don't omit that ! When powered on for the first time you need to adjust this pot to get a clear display. Without proper adjustment of this pot you can even get a completely blank display !
Prototyping Become much easier and looks neat if you use a Low Cost Development Board and a LCD Board.
The low cost development board has all the basic circuitry to support AVR MCU, while the LCD Board has all the basic circuitry for supporting LCD Module. Both the boards can be connected using a single pin female to female wires.
Fig. Interface with ATmega8. |
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 lcdlibv20.zip 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 !!!
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
![]() |
While LCDWriteInt(123,5) will print as follows.
![]() |
To goto any particular position on screen call.
| void LCDGotoXY(uint8_t x,uint8_t y); |
| LCDGotoXY(11,1); |
![]() |
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.
Writing Text at a specific position.
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:
|
Writing Number at a specific position.
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). |
Sample Program
#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h"
void main()
{
unsigned char i;
//Initialize LCD module
LCDInit(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![]() |
Fig: Configuring LCD Connection. |
Set LCD_DATA to the port where you have connected the LCD data lines. Then set LCD_DATA_POS to the starting pin of data lines. The LCD data lines D4 to D7 must be connected to consecutive pins starting from LCD_DATA_POS. For example if you wise to connect like this.
| PORTD (MCU) | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| DATA LINEs (LCD) | D4 | D5 | D6 | D7 |
You must configure like this
#define LCD_DATA D //Because we are using PORTD
#define LCD_DATA_POS 3 // Because LCD DATA4 is connected to PD3
Please note that LCD Data lines DATA0 to DATA3 are always unused only DATA4 to DATA7 are required.
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 PORTB so #define LCD_E B Then specify to which PIN of PORTB it is connected, this is done by #define LCD_E_POS PB4 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.
Videos
Downloads
- Core library files.
- AVR Studio Project for 28 PIN AVR MCUs (Tested on ATmega8).
- AVR Studio Project for 40 PIN AVR MCUs (Tested on ATmega32/ATmega16).
- HEX File ready to burn on ATmega8.
- HEX File ready to burn on ATmega16.
- HEX File ready to burn on ATmega32.
Custom Character ?
Some times we need to show characters that are not the part of standard character set, like some special symbols (say heart or symbols of other language like Hindi). In that case we can use custom characters. They are also easy to make and use. Full article on using custom characters on alphanumeric lcds is available here.
![]() |
Fig: Custom Char Demo ! See the heart and other symbols? |
Going Graphical ?
If you have more sophisticated display requirement then you may go for Graphical LCDs (GLCD) they can render graphics like Icons and bitmaps (images), support graphic primitives like line,circle, rectangle etc. Also they can draw text in different fonts and sizes. That means 100% fun! And they are cheap and very easy to get started (thanks to ProGFX.org). We have some beginners tutorials for it too. So why waiting? Go Graphical!
Have fun and don’t forget to bookmark this page. If you think this tutorial has helped you please post a comment.
Author
Avinash Gupta











Thanks so much for this info. the library and the instructions you provided was really really helpful. it was also easy to understand, even for a beginner like me.
Thanks!
Sir i wanted to reverse map the data ports.. hw is this possible? for eg need to connect d4 to pd6, d5 to pd5, d6 to pd4 and d7 to pd3..
how to do this..
Hello Avinash,
I have understood your program.I am using atmega8 MCU & Atmelstudio 4.I was not able to get the output.I think I am compiling code in the wrong fashion.I have added files as you have indicated.Can you tell me how to compile multiple source files..I am attaching my main function code for reference.I used all your source & header files..help greatly appreciated
Thank you..
#include
//#include “LCD.c”
#include “lcd.h”
#include “myutils.h”
int main()
{
InitLCD(LS_BLINK | LS_ULINE);
LCDClear();
LCDWriteString(“Greentech”);
return 0;
}
Hi Avinash,
First of all, thank you for the effort, it is appreciated.
I am trying to hook up a 16×2 char LCD with a ATMEGA328P. I did the connection as you suggest for the ATMEGA328 and programmed it with the the code you provide, but with modification in lcd.h (the definition part of RS, RW, E and data pins) to match the same configuration you provide for ATMEGA328. The LCD is lit but there is nothing happening. I can’t see the messages you put in the code. I am using the STK500 dev board. In the HW setting tab, the clock freq is set to 3.6MHZ. Could you please help me out. I don’t understant why it is not working
when using for the first time, use the same hardware as shown in the tutorial! it is not possible to debug your hardware form here !
Plase… i’m request LCD libarary for ATmega16,32 ..
Thanks for u…
azizmetronet@yahoo.com
Dear sir,
I think your tutorial and the library is very helpful. I should like to ask you if I may use your library for my robotic project in a students’ technical competition?
Yours faithfully
@Matthew,
Yes you can use them
Thank you
Hye Avinash and thanks for this tutorial !!! It’s help me a lot for my project.
I have one question… I want to use my LCD display in 8bit mode like this (with atmega16):
D7 => PORTC pin 7 to D0 => PORTC pin 0
R/E/RW => No change.
What I should modify ?? Is it easy to do?
Thanks
Aurélien
PS: Merry Christmas
Nice tutorial, thanks. My first running application with Atmega32 and LCD with large number of not working before. I have tried move all pins to port D, but display doesnot works correctly. I would like to get free C port for realtime chip on my kit (http://shop.onpa.cz/?kit-evb-4.3,27) and SDA and SCL pins. I will try move them on port B on my board tomorow. Thank again. Czech Republic
other wise you may try SoftI2C
http://extremeelectronics.co.in/avr-tutorials/ds1307-i2c-rtcc-interface-using-softi2c-lib/
This is very good and easy to use lcd library.
I have 2 questions: Is there possibility to make custom characters with this library?
How can I print character which exist in lcd rom but is not available throu keyboard? Like some lcd special characters. For example degree symbol ° is not available throu keyboard, or am I wrong?
Thanks,
regards
filip
@Filip,
Nice question. Although our internal version has support, yet the public version is short on that feature.
Soon we will release the custom char supported version.
Great, I’m looking forward this new edition.
If I want to display specific character from lcd ascii table should I write
LCDWriteString(223) ?
Instead write
LCDData(96);
you can use any valid ASCII code as parameter.
Nice project, helped me a lot!
Does this library handle 16×4 or 20×4 LCD-s with HD44780 controller?
Thanks, Attila
Thanks alot for providing this much of valuable information in easy to use LCD library.In this code i made two changes i.e.,1)connected R/W pin to GND,and commented LCDBusyLoop(); 2 times one at InitLCD and second at LCDByte(); insted of busy loop function i inserted a delay 10 ms, so here i saved one M.C.U pin.
2)I connected data pins(D4,D5,D6,D7) from LCD to higher nibble at MCUport(PD4,PD5,PD6,PD7)
with some changes at InitLCD();LCDByte();,it is working good.My question is it ok eliminate reading data from L.C.D or it’s needed,
Thanks&Regards
Murali,
Waiting for your reply….
Dear Mr. Avinash
Wonderful tutorial. I have a question. In the library you define l lcd.c following:
# ifndef F_CPU
# define F_CPU 12000000UL
If I use a crystal of 4, 8 or 16Mhz working properly the LCD, simply runs less or more speed, right.
But will it affect if I let something like this and use an 8MHz crystal of handling the USART and / or I2C?
Thanks, best regards.
Hello avinash,
If I want to use a single port (like B) for all the pins of an atmega16 then what all changes do I need to make in the associated files.
sorry, i meant port B of atmega16 for the lcd pins
extreme electronic is very good for learning electronics. thanks
hai avinash,i have a doubt.will the fuse bits vary from frequency to frequency.what will be the fuse bits for 8mhz crystal?
Chock the datasheet of the mcu you are using. Its given clearly. After that, to be certain, use http://www.engbedded.com/fusecalc/
Hey,
Thanks for the tutorial,
My dev board connections to the LCD are as follows,
PD0-PD7 go to the 8 control pins
PB6 goes to Rs
PB7 goes to R/W
and PC7 goes to E,
Please can you tell me what changes i have to make to the lcd.c to get it working….
Thanks
Sethu
PS: i’m using Atmega8 and i’m interfacing the LCD to a custom made dev board
thanx man, u indians are pretty good in tutorial writing easily for beginners. thanx again man
You may say that Avinash Ji is exceptional.
Great tutorials!
They are pretty useful for my diploma project.
Can you help me with the modifications needed for the 4×20 or 4×16 LCD?
Thank you again!
Thank you again Avinash for the tutorials!
I managed to make it 20×4.
Here is what I did:
I changed void LCDGotoXY at the end of “lcd.c” with this part:
********************************************
void LCDGotoXY(uint8_t x,uint8_t y)
{
if(x<40)
{
switch(y)
{
case 0://1 line starts at 0×80(0b10000000)
x|=0b10000000;
break;
case 1://2 line starts at 0xC0(0b11000000)
x|=0b11000000;
break;
case 2://3 line starts at 0×94(0b10010100)
x|=0b10010100;
break;
case 3://4 line starts at 0xD4(0b11010100)
x|=0b11010100;
break;
}
LCDCmd(x);
}
}
********************************************
Thank you again!
Hi Razvan
Can you help me with the modifications needed for the 4×20 or 4×16 LCD?
I tried your code and still did not work. did you made any other change?
thanks
Thanks so much. It’s just what I’m looking for. And it works perfectly. Thanks again.
@Diego Thanks !
Can I have this article in pdf form ? want to print them
Thank you
Whoooa!
That worked right out of the box. Amazing.
Thanks!
thanks sir for the module.
I need to show on LCD a function A^A+b, where a and b are introduced with the help of an 6×4 keypad which must have 0-9 , delete, ok, reset button and 10,20 and other values. The LCD is 16×2. Help me with the code in AVR please!!!!
Hello Mr. Avinash
I wrote the exact code you wrote as in the post,included source files and header files like you said,
earlier it was giving errors such as..
lcd.h:No such file or directory
../lcdtesting.c:7: error: ‘LS_ULINE’ undeclared (first use in this function)
../lcdtesting.c:7: error: (Each undeclared identifier is reported only once
../lcdtesting.c:7: error: for each function it appears in.)
../lcdtesting.c:25: error: ‘LS_ULINE’ undeclared (first use in this function)
Please help..
@Deepanshu Lulla
Dekh boss mere ko ise logo pe bahut gussa atta, samjha !
tere ko C ata kya ??? Mere ko to nei lagta tere ko zara bhi ata!
Clearly english me compiler error de raha aur tuhje us saltana bhi nei ata.
Ja jake koi aur kaam kar !
seriously!! even i have this problem pls help what can be done!!!
i cant understand Hindi!!
Haha, I must say some of your responses are so funny. It’s so true when they say “There are no stupid questions but only stupid people.”
@NotSoFunny !
Thanks ! Well said “There are no stupid questions but only stupid people.”
Hi man, this library is really a god thing!!!
I’m having some troublesand need some help.
When i try to print int or characters, lcd work fine. But when i try with strings, the lcd shows much black squares as characters i try to print… I think the problem is associated with the passing argument to the function, or the way the string is saved on program memory, but i dont know.
I’m working on linux-ubuntu, can the SO, or some routine of it, have something to do?
Thanks
Boss Thanks..When you said compiler error,I got it.
Marisha,did you copy the library components into your project destination folder.
Does this library works with atmega88??
Try and say it’s work or not.
well ,i did it,but it didn’t work,so i dont know if it was my mistake or this library doesnt work on atmega88,so that’s why i asked. thanks
@Nelson
* What is your crystal frequency.
*Write the connection of lcd and atmega 88 pin.
i will check.
Can I show the output voltage in a LCD .. IF yes can U tell me please ….
This dont work on atmega88 or something is wrong.Someone help me.Thanks
Hello
I´m trying to use the LCD at max frecuency but it doesn’t work, when I work with the internal clock at 8MHz it works just fine but when I try to use the external clock at 16MHz it doesn’t work.
How can I make it work ?
Hello Diego
Use the library provided by eXtreme Electronics, it will definitely work.If you are not able to work with MAX Frequency(16MHz) then buy the ready-mate board form the store…………
http://store.extremeelectronics.co.in/
hi avinash ,
i have a ready made atmega 32 board. in which lcd port is like that
pc0 rs
pc2 en
lcd data pin are
pc4 pc5 pc6 pc7
the RW pin is grounded in lcd port
i have used your code successfully with other port .
but in lcd port RW pin is grounded .
so how can i modified your code to use lcd with this board with RW pin grounded.
please help.
Are bhai kahan se le liya hai board?
Tere ko koi buri tarah se mamu bana diya hai!
badiya disign mein hamesa R/w pin hamesa connect rahta hai.kaun pagal design kiya hai bord ko.Ja usi se code maang!
maine bahut se code net me dekhe hai,
r/w ke bina bhi lcd ise kr sakte hai. but i am unable to understand these code completely .
check this :
http://www.pocketmagic.net/?p=447
http://www.ikalogic.com/ika-tach/
http://www.electronics-base.com/index.php/projects/complete-projects/110-avr-2×16-character-lcd-diplay-universal-code-library
yar thoda help ker do….
Mahendra net mein code search karne se aacha hai ki 16×2 lcd ka datasheet padho or samjho R/W pin kya hai or kyun use hota hai.
can any one help me in coading to display name on lcd interface with atmega32. i want to use portB.0=rs,portb.1=rw,portb.2= en and portB.4 to portB.7 to display data. m using code vision avr c compiler. plz help me in composing the code. my emailid is aki_a24@yahoo.com
#include
#include
#include “lcd.h”
void main()
{
LCDInit(0);
LCDClear();
LCDWriteString(“HELLO”);
}
i had used all lcdlib header file u have given…..
but its show 1 error … i am not able to make whts the error…
plzz
what does the error says ?
I’m using your library for lcd interfacing
as follows
#include
#include “lcd.h”
int main()
{
LCDInit(LS_BLINK|LS_ULINE);
LCDClear();
LCDWriteString(“Heloo”);
while(1);
}
it is showing errors
Error 5 atmega8LCDEE.elf section `.text’ will not fit in region `text’ E:\august_avrstudio\atmega8LCDEE\atmega8LCDEE\Debug 1 1 atmega8LCDEE
Error 6 region `text’ overflowed by 5038 bytes E:\august_avrstudio\atmega8LCDEE\atmega8LCDEE\Debug 1 1 atmega8LCDEE
Please help me
Regards
Bikash
Can you please tell me,whether you are using AVR Studio 4/5 or ATmel Studio 6 ? After that I will be able to help you.
Thank you
I’m using avr studio 5
Bikash, you are working with Atmel studio 5,then problem is with optimization setting.First of all go to project menu,then
go to properties in project menu.OR press ALT+F7.Then go to toolchain(you will find this leftside of the
screen ).Then click on (you will see this inside ).Click on ,change the
optimization level.Click on it and set it to .After that you have to rebuild the program.Go to
, click on rebuild solution or press CtrL+Alt+F7.Now you successfully get the output. I hope you understand the
process. Thank you
kindly see this for more information http://forum.extremeelectronics.co.in/index.php?topic=2509.0
Dear Avinash,
Please Provide PDF link.
Thanks in Anticipation.
Hi,
Thanks for this great library.
i’m using MEGA32,how i need to setting the fuse bits on burner?
sir
i am new with atmega coding n hardware . i want to interface LCD and Atmega16
as per your toutorial i made connection with portD and PORTB but i m not getting any out put at lcd please help me i would be very greatful to you
@Dheeraj
Use xBoard v2.0 to learn ATmega16 and LCD Interfacing once you learn it then go about implementing in your own hardware.
http://store.extremeelectronics.co.in/xBoard-v2.0.html
i have made connection according to your lcd.h file n programed atmega16 but i am not gettig any output at lcd plz help ..
Hello,
Im using LCD library from this article and there is a problem. When i initialise LCD with LCDinit(LS_NONE) i want to have cursor not visible. Right after flashing its ok but when i power down my circuit and power it up its going back to default blinking underlined cursor. Here is my code (i also tried to place LCDinit inside while loop but its same)
int main(void)
{
LCDInit(LS_NONE);
while(1)
{
LCDClear();
ds_conv();
DSconvTemp();
LCDWriteStringXY(2,0,tempBuf);
_delay_ms(1000);
}
}
Is there a way to make cursor be invisible by default? Or maybe i place LCDInit function in wrong place?
Does anyone have same problem Or maybe someone could please check if this happen for him. Initialise your LCD with LCDinit(LS_NONE) and then see if cursor is not visible, then power circuit down and see if is back to normal or still not visible. If its wokring please post here back and place your code where you initialised LCD. Thank you
Every time after powering on, just do a reset by pressing the reset button in your development kit and the cursor will not be shown.
I had the same problem and this works fine.
i copy you code and the atmel studio send a error.
“main must return int”
i ned help.
i found error. i´m in c++ and the project is c.
TKS
Dear Sir,
is it possible, to use a 8×1-module with your lcd-library?
Sincerely
PeterS
first of all thak u for such a good project i am 11 th class student and i made this proj. by directly burning the hex file given by u but when i go to the compiling process i get 2 warnings one is
1. e:/winavr-201……../lib/gcc/avr/include/until/delay.h:85:3:warning:#warning “F_CPU not defined for ”
2. LCDTEST.C:6:WARNING return type of ‘main’ is not ‘int’
plz give the sol. of this problem
@Akshay,
For that you need to have good understanding of C.
Hi Akshay,
this is not a problem, but a info to you. A good idea is, to take the following line in your main.c sourcecode:
#define F_CPU 8000000UL /*CPU clock in Hertz*/
You must write the right frequency of your CPU in the line.
Second, your main-function should begin with a:
int main(void)
{
…..
I hope, it helps.
Cheers
Peter
hi
Can I place the translated article along with the files in my website?
which language?
persian!
Hi Avinash,
I am using your code and have connected terminals in same manner as described in your article, i am using ATMEGA328P-PU. LCD backlit gets lit but nothing gets displayed.
Please help..
Thanks,
Ujjwal Soni
@Ujjwal,
Pay us the cost and get assembled and tested hardware.
Then only we can proceed.
@Ujjwal,
at first, is your hardware correct connected? In your software you must init the LCD-module at the right way. How do you put the data witch should be displayed to the LCD? Please post the code of your program.
Cheers
Peter
Hello,
first of all,thank you for making this great library and very very good tutorials on the subject of micro-controllers.I have two question for you if you can please answer:
1.How to print a number other than integer on the LCD display (for example 25.5 or so)? What should I modify in the lcd source code?
2. How to measure temperature with LM35 and Atmega8 but to have increments in half of the degree (for example measure temperature of 18.5 degrees Celsius)? Because as I can see in your tutorial of interfacing LM35 with Atmega8 you have resolution on one degree.
Thank you!
Hi Srdjan,
1. You have to change the integer (or float) to a string.
Code-snipped:
int main(void){
char mystr[16];
double myflt1, myflt2;
myflt1 = 3.14159;
myflt2 = myflt1*5.1324;
sprintf(mystr, “%.5f”, myflt2);
LCDWriteString(mystr);
}
sprintf makes this change. This string can be displayed at the LCD. Use the function “LCDWriteString(const char *msg);” from the library.
2. Your second problem is a little bit difficulter. One idea you’ll find at
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=128191
Search in Google to “atmega8″ and “lm35″.
Cheers
Peter
@Peter
Thank you very much on the reply.
I tried the code you provided, but I don’t get result as expected. I have run the simulation in Proteus ,and I keep getting ? on the screen. So it doesn’t prints the decimal number I want, but just the prints ?. can you please help with this,my programing skills in C are still not very good,I am learning.
Thanks,
Srdjan
@Srdjan,
the code-snipped is ok, but I think, you must change a little bit in your Makefile. Search in the Makefile the following line:
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
Delete the “#” at the beginning of the line and save the Makefile. Here comes the whole code again:
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
#include "lcd.h"
char mystr[10];
double myflt1, myflt2;
int main(void)
{
LCDInit(LS_NONE);
LCDClear();
myflt1 = 3.14159;
myflt2 = myflt1*5.1324;
sprintf(mystr, "%.3f", myflt2);
LCDWriteString(mystr);
}
In the line:
sprintf(mystr, “%.3f”, myflt2);
you can define the number of decimal places.
Info: I’m working with WinAVR
Hope it helps
Peter
@Srdjan,
I see, it’s a problem to post lines with angle brackets in it. The first three lines are the normal includes with angle brackets:
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
Cheers
Peter
@PeterS,
I would like to thank you for helping me with this.I didn’t respond right away because, I wanted to familiarize myself closer with WinAVR and makefile generation. Yes, you were right, the problem was in configuration of printf in the makefile. I generated the makefile again with the WinAVR mfile application, and with it a compiled your code, and run the ISIS simulation. Everything works like a charm now.
Thank again,
Cheers,
Srdjan
Hello Srdjan,
thank you for your reply. It makes me happy
If I can help you again, let me know.
Cheers
Peter