Position: Index > Unclassified >

Creating custom LCD characters using WinAVR

2017-12-21 09:26  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

Standard LCD modules comes with built in Character MAP stored in LCD ROM memory. There is plenty of characters for your needs, but still you may need some special ones like backslashes, or some symbols that are in different languages. For this LCD has a reserved RAM area for storing eight 5×7 dot matrixcharacterpatterns.


In the table above this area is in first column with addresses starting from 0 to 7 (from 0b00000000 to 0b00000111). This means, that you can define any type of characters in these 8 fields as you like and use them by calling them by addresses from 0 to 7.

To define one character, you will need to write eight bytes in row to CGRAM memory

For 0 character address (DDRAM=0):


So for the first character creation procedure would be:

Cycle of 8 iterations:

Send command to LCD with CGRAM address from 40h to 47h;

Send bytes to to selected CGRAM address

Because characters are 5×7 dots. You only need to modify first five bits of each byte. Other area fill with zeros(Marked blue in picture).

For other 7 characters the procedure is the same. Continue on next 8 CGRAM addresses 48h-4Fh. the last CGRAM address for eighth character is l 78h.

So you can create an array of 64bytes and write them all at once to CGRAM. Then you can read separate characters using DDRAM addresses from 0 to 7.

Before load your custom character to CGRAM, you need to store these chunks of 8 bytes.

The best way to store is program memory (FLASH).

const uint8_t squareR[] PROGMEM=











Constructionconst uint8_t squareR[] PROGMEMmenas that data is stored in FLASH at address squareR. For this to work you must include #include a€?avr/pgmspace.ha€? library.

Then reading from program memory is easepgm_read_byte(squareR[0]):

Sending to custom character to LCD would look like:

void LCDdefinechar(const uint8_t *pc,uint8_t char_code){

uint8_t a, pcc;

uint16_t i;

a=(char_code<<3)|0x40;//calculate CGRAM address respectively to DDRAM address

for (i=0; i<8; i ){ //eight bytes for one character

pcc=pgm_read_byte(&pc[i]);//reads byte from program memory

LCDwritebyte(a ,pcc); //writes byte to CGRAM at address a


FunctionLCDwritebyte ()is simple. Send command with CGRAM address to LCD and after send a byte.

void LCDwritebyte(uint8_t a, uint8_t pc)





Displaying first custom character stored in DDRAM address 0 is simple:


Realization of functions



Depends on how you connect your LCD. I have developed simple routines for 3-wire LCD connection. You may download them from here:LCD Custom char with WinAVR . This is a part of project AVR controlled generator which is still in development stage.

Reprinted Url Of This Article: