LCD CHARACTERS millis() PROBLEM !!!

Hello. I have a problem with my code.I have a lcd and I want to blink a character every 0.5 seconds BUT I don’t want to use delay.I want to use MILLIS function.Everything is ok ,but many times the character lag about 0.5-1 second MORE than 0.5 seconds.I don’t know if the problem is in the code or not ,but I want your help!!!
Then,I would like to know if exists another way…
CODE:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long previousMillis = 0;
bool real = true;

byte A[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};

void setup()
{
lcd.begin(20, 4);
}

void characters_for_AI()
{
lcd.createChar(0, A);
lcd.setCursor(5, 3);
lcd.write(byte(0));
lcd.setCursor(6, 2);
lcd.write(byte(0));
lcd.setCursor(7, 1);
lcd.write(byte(0));
lcd.setCursor(8, 0);
lcd.write(byte(0));

lcd.setCursor(9, 0);
lcd.write(byte(0));
lcd.setCursor(10, 1);
lcd.write(byte(0));
lcd.setCursor(11, 2);
lcd.write(byte(0));
lcd.setCursor(12, 3);
lcd.write(byte(0));

lcd.setCursor(7, 2);
lcd.write(byte(0));
lcd.setCursor(8, 2);
lcd.write(byte(0));
lcd.setCursor(9, 2);
lcd.write(byte(0));
lcd.setCursor(10, 2);
lcd.write(byte(0));

lcd.createChar(0, A);
lcd.setCursor(15, 0);
lcd.write(byte(0));
lcd.setCursor(15, 1);
lcd.write(byte(0));
lcd.setCursor(15, 2);
lcd.write(byte(0));
lcd.setCursor(15, 3);
lcd.write(byte(0));
}

void function()
{
unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= 500)
{
previousMillis = currentMillis;
if (real)
{
characters_for_AI();
}

else
{
lcd.clear();
}
}
real = !real;
}

void loop()
{
function();
}

SOLVED

What was the problem? Repetive calling of lcd.createChar()?

No .I should have put the command (real = !real;) a position over...

Of course....

Suggestion:

Create the custom character only once in "characters_for_AI()" as it doesn't change.

Call "characters_for_AI()" in "setup()" and use "display/noDisplay" for blinking the display (without loosing its contents).

Writing to the display may be relative slow, and this would save some time for other tasks.

(untested)

void function()
{
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= 500)
  {
    previousMillis = currentMillis;
    if (real)
    {
      lcd.display();
    }

    else
    {
      lcd.noDisplay();
    }
    real = !real;
  }
}

When you skip character zero, and start with 1, then you can use a zero-terminated string with the lcd.print().

lcd.setCursor(15, 0);
lcd.print("\1\1\1\1");

The \1 is the octal notation. You may use \x01 as well.