LCD RGB Text

Now lets write some methods to drive the LCD controller, first of all the JHD1313 datasheet (Grove for some reason puts a link to the datasheet of JHD1214) is not too clear, but after some time you will realize that to init the device you can write to register 0x00 if you want to write to CGRAM AD you need to write to register 0x40 and to write information to DDRAM you need to write to register 0x80 (take a look to the JHD1214 data sheet).

So lets start adding some defines we will need:

// commands
#define LCD_CLEARDISPLAY    0x01
#define LCD_RETURNHOME      0x02
#define LCD_ENTRYMODESET    0x04
#define LCD_DISPLAYCONTROL    0x08
#define LCD_CURSORSHIFT    0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR    0x40
#define LCD_SETDDRAMADDR    0x80

// flags for display entry mode
#define LCD_ENTRYRIGHT    0x00
#define LCD_ENTRYLEFT    0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00

// flags for display on/off control
#define LCD_DISPLAYON    0x04
#define LCD_DISPLAYOFF    0x00
#define LCD_CURSORON    0x02
#define LCD_CURSOROFF    0x00
#define LCD_BLINKON    0x01
#define LCD_BLINKOFF    0x00

// flags for display/cursor shift
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE    0x00
#define LCD_MOVERIGHT    0x04
#define LCD_MOVELEFT    0x00

// flags for function set
#define LCD_8BITMODE    0x10
#define LCD_4BITMODE    0x00
#define LCD_2LINE    0x08
#define LCD_5x8DOTS    0x00
//////////////////////////////////////////////////////////
uint8_t _displayfunction = 0;
uint8_t _displaycontrol = 0;
uint8_t _displaymode = 0;
uint8_t lines = 2;

Now add an init method to setup our LCD:

Of course we need a function we can pass a c string to it , then iterate it and pass each letter to the LCD. for that lets add the following method:

Alright! now what we have left is to update our main method:

clean , compile and run ./lcdtest

Last updated