EMBEDDED SYSTEMS TUTORIAL 9- INTERFACING 16X2
LCD WITH AVR PART-2
Hi…. friends this time I am here with another article ,w...
USING INTEGERS ON LCD
You cannot use a integer on LCD directly for this you have to use a function itoa(), it converts an ...
Like an integer a floating point number cannot be used directly too , so to use an floating point no on LCD
we have to use...
Upcoming SlideShare
Loading in …5
×

Est 8 2 nd

667 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
667
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Est 8 2 nd

  1. 1. EMBEDDED SYSTEMS TUTORIAL 9- INTERFACING 16X2 LCD WITH AVR PART-2 Hi…. friends this time I am here with another article ,we are going to discuss some interesting functions and projects of LCD. In this tutorial we will learn about rotating a text , displaying integer and integers operations, displaying floating point numbers and their operations . ROTATING A TEXT STRING Rotating a text on LCD is a bit tricky thing, to do so we will change the position of text every time with some delay after clearing the screen so it will look like text is moving the sample code is given below just use this source code in your LCD project and text will look like moving/* * MOVINGTEXT.c * * Created: 1/12/2013 8:36:31 PM * Author: ABHILASH DIXIT */ #include #include #include #include #include #include <stdlib.h> <avr/io.h> <avr/pgmspace.h> <util/delay.h> "lcd.h" "lcd.c" int main(void) { while(1) { lcd_init(LCD_DISP_ON); for(int i=-10;i<16;i++) // setting an integer i to 0 and incrementing its value till 16 { lcd_gotoxy(i,0); // setting cursor to (i,0) lcd_puts("LCD"); // to display text if(i==13) i=0; _delay_ms(100); // some delay lcd_clrscr(); // clear display } } } So this was the trick to rotate the text string on the LCD.
  2. 2. USING INTEGERS ON LCD You cannot use a integer on LCD directly for this you have to use a function itoa(), it converts an integer in string form. So if we want to use integers in LCD we will first create a buffer of some size as char buf[8]; now lets suppose the number to be displayed is i , so we will use itoa() function for i to convert it in string form as itoa(i,buf,10); here 10 is for decimal, for hexadecimal we will use 16 and for binary we will use 2. Now finally i can be displayed using lcd_puts() command aslcd_puts(buf); so lets try a source code – in this program we will display a number i=0 and will increase its value till 10. /* * DISPLAY INTEGER.c * * Created: 1/12/2013 9:16:31 PM * Author: ABHILASH DIXIT */ #include <stdlib.h> #include <avr/io.h> #include <avr/pgmspace.h> #include "lcd.h" #include "lcd.c" #include <util/delay.h> int main() { while(1) { lcd_init(LCD_DISP_ON); int i=0; char buf[8]; lcd_gotoxy(0,0); lcd_puts("i="); for(i=0;i<=9;i++) { itoa(i,buf,10); lcd_gotoxy(2,0); lcd_puts(buf); _delay_ms(100); } } } USING A FLOATING POINT NUMBER // initializing display // setting value of integer i to 0 // initializing buffer // setting cursor position to (0,0) // displaying text // increasing value of i till 9 // using itoa() function // setting cursor position to (2,0) // displaying value of i every time // some delay
  3. 3. Like an integer a floating point number cannot be used directly too , so to use an floating point no on LCD we have to use some function called dtostrf() it converts an floating point number into string . let us suppose we have to display a floating point number say i on LCD. So first of all we have to create a buffer of some size char buf[8]; then we will use dtostrf () function with i to convert i in string form as dtostrf(i,10,6,buf); here 10 is for decimal and 6 is denoting numbers after decimal we can change it accordingly. Now the no i can be displayed using lcd_puts() command Here is the source code for simply displaying a floating point number i=1.12345 /* * DISPLAY FLOAT.c * * Created: 1/12/2013 9:26:31 PM * Author: ABHILASH DIXIT */ #include <stdlib.h> #include <avr/io.h> #include <avr/pgmspace.h> #include "lcd.h" #include "lcd.c" int main() { lcd_init(LCD_DISP_ON); float i=1.12345; char buf[8]; dtostrf(i,10,6,buf); lcd_puts(buf); } NOTE:- to use itoa() and dtostrf() we must include stdlib.h header file in beginning of the program . I hope it was a useful article for you all……in case of any query, doubt or critical view just leave a comment……..in next tutorial we well discuss about some other embedded systems topics till then ………..bye..

×