Lcd
a 16 pin lcd have following pin connection
Printing Functions
Now once the connections have
been made, we are ready to display something on our screenSome of the general
LCD functions which you must know are:
lcd_clear()
Clears the lcd. Remember! Call
this function before the while(1) loop, otherwise you won’t be able to see
anything!
lcd_gotoxy(x,y)
Place the cursor at coordinates
(x,y) and start writing from there. The first coordinate is (0,0). Hence, x
ranges from 0 to 15 and y from 0 to 1 in our LCD.
Example: you want to display
something starting from the 5th character in second line, then the function
would be
lcd_gotoxy(5,1);
lcd_putchar(char c)
To display a single character.
E.g.,
lcd_putchar(‘H’);
lcd_putsf(constant string)
To display a constant string.
Eg,
lcd_putsf(“IIT Kanpur ”);
lcd_puts(char arr)
To display a variable string, ie
an array of characters (data type char) in C language .
e.g., You have an array char c[10] which keeps
on changing. Then to display it, the function would be called as
lcd_puts(c);
Now we have seen that only
characters or strings (constant or variable) can be displayed on the LCD. But
quite often we have to display values of numeric variables, which is not
possible directly. Hence we need to first convert that numeric value to a
string and then display it. For e.g., if we have a variable of type integer,
say int k, and we need to display the value of k (which changes every
now and then, 200 now and 250 after a second... and so on). For this, we use
the C functions itoa() and ftoa(), but remember to include the
header file <stdlib.h> to use these C functions.
itoa(int val, char arr[])
It stores the
value of integer val in the character array arr. E.g., we have already defined
int i and char c[20], then
itoa(i,c);
lcd_puts(c);
Similarly we
have
ftoa(float val, char decimal_places, char arr[])
It stores the
value of floating variable f in the character array arr with the number of
decimal places as specified by second parameter. E.g., we have already defined
float f and char c[20], then
ftoa(f,4,c);
// till 4 decimal places
lcd_puts(c);
Now we are
ready to display anything we want on our LCD. Just try out something which you
would like to see glowing on it!
header file required : #include<lcd.h> //but it is not required as it is already applied by cvavr by selecting lcd
HOW TO SELECT LCD:
get started with lcd on cvavr
No comments:
Post a Comment