Go Down

Topic: Useing more then 8 Custom Charicters on an LCD (Read 6138 times) previous topic - next topic

digimike

Mar 11, 2010, 05:25 am Last Edit: Mar 11, 2010, 11:31 pm by digimike Reason: 1
Once again i've been playing around with custom characters on an LCD using the LiquidCrystal library. I've been working with redefining the custom characters on the fly to open up many more possible characters the LCD can display.

This code offers 2 different sets of custom characters. Starting the cursor as (0,0) it fills the segment one line at a time from left to right. It then wipes the stored custom characters and then adds the new ones. The next segment then fills in one line at a time from top to bottom. It goes back and forth like this to fill the entire screen with fully filled in segments.

Code: [Select]
/*
 This sketch shows how to use multiple sets of custom characters
 at the same time. This is achieved by redefining the character
 sets on the fly. Initial code made for a 16x2 LCD using the
 LiquidCrystal library. Can be adapted for other sized LCDs.
 
 The Circuit:
  LCD RS pin to D7
  LCD Enable pin to D6
  LCD D4 pin to D5
  LCD D5 pin to D4
  LCD D6 pin to D3
  LCD D7 pin to D2
  LCD Vee tied to a pot to control brightness
  LCD Vss and R/W tied to ground
  LCD Vcc to +5V
  LCD pin 15 tied to pushbutton for control of back light

Made by Michael Pilcher
3/10/2010
*/

// include the library
#include <LiquidCrystal.h>

// initialize the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

// define integers for the cursor location
int x=0;
int y=0;

void setup()
{
 // sets the LCD's rows and columns:
 lcd.begin(16, 2);
}

void customclear()
{
 // ensures all custom character slots are clear before new custom
 // characters can be defined.
 byte blank[8] =
 {
   B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000
 };
 for(int i = 0; i < 8; i++)
 {
   lcd.createChar(i, blank);
 }
}

// filles a segment one line at a time fron left to right.
void customset1()
{
 customclear();
// arrays to form one set of custom characters
 byte line1[8] =
 {
   B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000
 };
 byte line2[8] =
 {
   B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000
 };
 byte line3[8] =
 {
   B11100, B11100, B11100, B11100, B11100, B11100, B11100, B11100
 };
 byte line4[8] =
 {
   B11110, B11110, B11110, B11110, B11110, B11110, B11110, B11110
 };
 
 // assignes each segment a write number
 lcd.createChar(0, line1);
 lcd.createChar(1, line2);
 lcd.createChar(2, line3);
 lcd.createChar(3, line4);  
}

// fills a segment one line at a time from top to bottom.
void customset2()
{
 customclear();
// arrays to form one set of custom characters
 byte line1[8] =
 {
   B11111, B00000, B00000, B00000, B00000, B00000, B00000, B00000
 };
 byte line2[8] =
 {
   B11111, B11111, B00000, B00000, B00000, B00000, B00000, B00000
 };
 byte line3[8] =
 {
   B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000
 };
 byte line4[8] =
 {
   B11111, B11111, B11111, B11111, B00000, B00000, B00000, B00000
 };
 byte line5[8] =
 {
   B11111, B11111, B11111, B11111, B11111, B00000, B00000, B00000
 };
 byte line6[8] =
 {
   B11111, B11111, B11111, B11111, B11111, B11111, B00000, B00000
 };
 byte line7[8] =
 {
   B11111, B11111, B11111, B11111, B11111, B11111, B11111, B00000
 };
 
 // assignes each segment a write number
 lcd.createChar(0, line1);
 lcd.createChar(1, line2);
 lcd.createChar(2, line3);
 lcd.createChar(3, line4);
 lcd.createChar(4, line5);
 lcd.createChar(5, line6);
 lcd.createChar(6, line7);
}

void loop()
{
 customset1();
 for(int i = 0; i < 4; i++)
 {
   lcd.setCursor(x, y);
   lcd.write(i);
   delay(100);
 }
 lcd.setCursor(x, y);
 lcd.write(255);
 delay(100);
 x++;
 if(x > 15)
 {
   x = 0;
   y++;
 }
 if(y > 1)
 {
   x = 0;
   y = 0;
   lcd.clear();
 }
 customset2();
 for(int i = 0; i < 7; i++)
 {
   lcd.setCursor(x, y);
   lcd.write(i);
   delay(100);
 }
 lcd.setCursor(x, y);
 lcd.write(255);
 delay(100);
 x++;
 if(x > 15)
 {
   x = 0;
   y++;
 }
 if(y > 1)
 {
   x = 0;
   y = 0;
   lcd.clear();
 }
}




I hope this can be used as a guide at expanding what can be done with these LCDs.

r0oland

Greetings,

I have problems using your code and using the lcd.createChar() and lcd.write() functions. It only works for me if I declare the chars in the setup function of my program. If I declare the char with lcd.creatChar() anywhere else in the code, my program successfully ignores it.

I hope you know what I mean...

With best regards,
r0oland

digimike

Well there is in fact more of a limitation to the whole setup. When it goes threw and changes the custom character set then any of the previous custom characters you had displayed on screen would change to the new set.

If you pay attention to the main loop of the code it is calling back to one of the custom character sets. If your not not calling to the specific set you want then the new character set will not be stored into the LCD's memory.

If you have the LCD connected to your Arduino correctly and you have the library in the right place. It should already be in the IDE if your running 0018.

If your using a modified version of my code then posting it would help. Then we can see if there are any obvious problems.

jdoll

Have you successfully executed your code example?

I tried something similar, but could not get it to work.  I was afraid newly created characters would replace custom characters previously written.  The actual result was even worse.

For me, createChar() had no effect unless followed by begin().  That is the way its usage is described in the documentation.  begin() clears the screen, so any previously written characters disappear.

It would be nice to get your scheme operational somehow.  It would make character LCDs much more versatile.

patrick8356

We are a LCD sales,and from one LCD manufacture in China, I would like to supply some standard character C version testing code  for you reference,  like 8x2 or 16x2 character LCD,if you need then please send me mail to patrick@lcdmaker.com,thanks.

Go Up