Imagino Title
Imagino Title
 

Sample LCD Display code

This code was developed to be substantially faster than previous suggested LCD support functions. This code has been tested as being 12x faster than a similar solution based on using the Arduino DigitalWrite function. The code is specific to the 84x48 Display used within the Imagino and the pin numbers specified in the Imagino standard.

void LCD_Write(byte dat, int mode) 
{  //
   // mode = 0 for commands, 1 for data
   //
   // code copyright © 2017 webinaweek limited
   // unlimited non-commercial use permitted 
   // with this notice intact
   //

  if (mode == 1)
    PORTD |= 0x80; // DC high
  else
    PORTD &= 0x7F; // DC low

  PORTB &= 0xFE; // CE low

  for (int ii = 0; ii < 8; ii++)
  {
    if (dat & 0x80)
      PORTD |= 0x40;  // DIN  high
    else
      PORTD &= ~0x40;  // DIN  low
    dat = dat << 1;
    PORTD |= 0x10;  // CLK high
    PORTD &= 0xEF;  // CLK low
  }
  PORTB |= 0x01;  // CE high
}
This routine transfers a single byte to the LCD Display by direct manipulation of the Arduino ports. Using this method is faster than other alternatives, at the cost of slightly larger, more complex code.

Each of the Hexadecimal numbers relates to an equivalent I/O pin, and the names of the inputs to the LCD display are indicated in code comments.

The Imagino adds a standard font to provide a variety of text display capabilities.

The screen is arranged as 6 horizontal rows of 84 bytes each. Each byte contains the data for 8 vertical pixels. There are therefore 84 x 6 (or 504) bytes in the whole screen, and a total of 84 x 48 (or 4032) pixels.


void LCD_ClearScreen()
{
  LCD_Write(0x80, 0);
  LCD_Write(0x40, 0);
  for (int zz = 0; zz < 504; zz++)
  {
     LCD_Write(0, 1);
  }
}
This is a simple add-on function that clears the LCD screen ready for further output.

These calls instruct the Display to begin outputting at co-ordinate 0,0 - the top left of the display.

The remainder of the code outputs 504 bytes, each blank to fill/clear the screen. Various patterns can be achieved by changing this byte value from 0 to another value.


These code examples are provided without warranty. Every care has been taken to ensure that they are fully functional, but no liability can be accepted for loss or damage incurred during their use.

© Copyright 2017 WebinaWeek ltd. trading as The Imagino Project, 14/ME10 2GE Callers by appointment only.
0800 612 8875