Wednesday, August 13, 2014

Displaying custom character in lcd using MikroC

lcd custom7
Suppose you have to display a heart or love sign or any other logo to your lcd display. So lets make a trial.Its easy if you are simply go through this tutorial. MikroC has a powerful tool to display custom character in lcd.
You can draw custom character using this tool and it returns necessary codes for you.
In this tutorial we design + sign first ,and simulate it using proteus to view the result.




First open MikroC PRO for PIC and make a new project using pic16f73 with clock 20MHZ.
Go to Tools->LCD Custom Character
lcd custom1

In next window design + sign by clicking rectangular boxes.Then press enter to generate code. Copy the full code to the.
lcd custom2


Then paste the code under void main section shown below.Change the line
void CustomChar(char pos_row, char pos_char)
To this line
void CustomChar1(char pos_row, char pos_char)
lcd custom3


Then copy this line before void main shown below
lcd custom4

Now just initialize lcd and call custochar1() in row 1 col 1 by writing
Lcd_Init();                        // Initialize LCD
CustomChar1(1,1);           //print + in lcd position row 1, column 1
lcd custom5

Then Build the project and collect the hex file.
Open Proteus and draw the schema as shown below.
Load the hex file and in pic and oscillator will be 20 MHz.Then Run
lcd custom8

Okey That’s Done!!!

Adding more characters

To add more character repeat the process again and now we shall design x sign with name
CustomChar2();
But here is problem you have to face if you call
CustomChar2(1,3);
You may see both
+  +
sign rather than
+  x
To fix this problem you have change some code
lcd custom6


Make two changes shown in figure above.
write
Lcd_Cmd(72);       //every new character needs to add 8 e.g: 64+8=72
rather than
Lcd_Cmd(64);      
And
Lcd_Chr(pos_row, pos_char, 1); //1 for 2nd character
rather than
Lcd_Chr(pos_row, pos_char, 0);
Finally another divide sign I create named
CustomChar3();
Call all three character at a time
void main() {
Lcd_Init();                        // Initialize LCD

CustomChar1(1,1);           //print + in lcd position row 1, column 1
CustomChar2(1,3);           //print x in lcd position row 1, column 3
CustomChar3(1,5);           //print Devide sign in lcd position row 1, column 5

}
Build the project and run in proteus. Output window I have
lcd custom7

Now you can design any custom character you need.
You can download the full project file from here Lcd Custom Character.rar
The proteus DSN file is here Lcd Custom character.DSN

No comments:

Post a Comment