Spread the love

custom char____________________________________________________________________________________________________

Introduction

In LCD, Custom character generation mean printing (displaying ) anything other than standard english character or symbol. In which you can program, any thing you want by doing each and every single pixel programming  including any laguage character and special character those not included in ASCII table also. Before going to discuss custom characters design on LCD, we will see how the standard characters (which are already stored in LCD memory during manufacture) are displayed on the 16×2 LCD.

 

Displaying standard characters on LCD

In 16×2 LCD controller HD44780, there are three memory are available to store characters, numbers and special symbols.

1. CGROM – character generating ROM which is responsible for stored standard character pattern.

2. CGRAM – character generating RAM which holds custom character pattern space ( total 8 in 2×16 module).

3. DDRAM – data display RAM which stores ASCII codes.

  • Steps to understand how character display:

1. Control unit of LCD receives signal(basically it is ASCII code) from user (usually microcontroller) and ask to DDRAM for its match.

2. If ASCII code match, control unit maps corresponding character pattern from CGROM.

3. According to that character pattern,  LCD screen energies and we can see character on it .

 

For example, in 16×2 LCD there are 16 segments available per single line. Each segment contains pixels in 5×8 or 5×10 matrix forms.

Untitled

 

For example, a character in both uppercase ‘A’ and lowercase ‘a’ is designed by energizing corresponding pixels as shown below pic.

Untitled - Copy

                         In each row, the ON and OFF pixels of 5×8 matrix is represented by binary values 1 and 0 respectively, from these binary values the hexadecimal code is designed by gathering all 1’s and 0’s as shown in the figure . All these eight hexadecimal codes (referred as character pattern) of each character are stored in memory. LCD Manufacturers store these hexadecimal representation codes of all ASCII characters in character generator ROM (CGROM) area. We refer the hexadecimal codes in CGROM as standard or basic fonts of characters in LCD.

                         The Display Data RAM (DDRAM) stores the ASCII code of a character which is sent by the microcontroller.

                        Now the LCD controller (HD44780) maps the corresponding ASCII code in DDRAM with CGROM address to bring the hexadecimal codes (character pattern) of that particular character. By using those hexadecimal codes the 5×8 matrix segment will energize according to that character pattern to display corresponding character on it as shown in below pic.

sdfsf

 

Generating Custom Characters on LCD display

To create custom characters on LCD, the display controller (HD44780) make use of CGRAM area to store hexadecimal codes (character pattern) which are designed by user. In addition to CGRAM area, DDRAM area is also used to store the CGRAM address of a particular character which is sent by microcontroller in hexadecimal format.

                      Don’t confuse with the above section of this module “Displaying standard characters on LCD”, in which DDRAM and CGROM memory areas are used to generate regular standard characters. But here, to create and display custom characters on LCD, we use DDRAM and CGRAM (both are RAM’s). There are only 8 memory locations are available to store user defined characters in CGRAM with address 0x00 to 0x07 .

 

Steps to create and display custom character on 16×2 LCD

1. To create custom characters, first draw a table with 7 rows and 5 columns (5×8 matrix-left one raw for cursor) on a paper. Fill the corresponding squares with some color according to your style of custom character pattern and form the hexadecimal code for each row as shown in above pic of Uppercase ‘A’ & Lowercase ‘a’.

2. Initialize LCD with required commands.

3. Send the Initial address (0x40) of CGRAM as a command to LCD to store the custom character on that particular locations. The next address to store another custom character should be ‘0x48’. That means we should add eight bytes to the present address to get the next address of CGRAM.

4. Send the all hexadecimal bytes of custom character to CGRAM.

5. Force the LCD cursor to where you want to display your custom character. If it is beginning of 1st line, then send ‘0x80’ as command.

6. Send the position of your custom character in CGRAM to LCD.

1. circuit diagram of ARM7 ( LPC2148 ) with lcd in 4 bit mode to generate custom character 

ckt of generating custom charactor  using ARM7 ( LPC2148 )on lcd  IN 4 BIT MODE

1. Program of creating custom character on 4 bit lcd connected with ARM7 ( LPC2148 )

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- GENERATING CUSTOM CHARACTER ON 4 BIT LCD CONNECTED WITH
ARM7 ( LPC2148 ) 
******************************************************/

#include<lpc21xx.h>

#include"delay.h"  // delay header file

#include"lcd4bit.h"  // lcd 4 bit header file

void send_str();  // fuction to save custom character to lcd

char dat[4][8]={0x00,0x0a,0x15,0x11,0x11,0x0a,0x04,0x00,  // custom character
                0x00,0x04,0x04,0x04,0x15,0x0e,0x04,0x00,
		0x15,0x0a,0x15,0x0a,0x15,0x0a,0x15,0x00,
                0x00,0x00,0x0a,0x00,0x04,0x11,0x0e,0x00};

void main()  // main function
  {
		  PINSEL0=0x00000000;  // select as gpio
		  PINSEL1=0x00000000;  // select as gpio
		  IODIR0=0X00ffffff;   // make direction as output
	          lcd_ini();   // lcd initilization function
		  send_str();  // save custom character to lcd
		  cmd(0X80);   // set cursor at first position of first line
		  lcd_str("  CUSTOM FONTS ");  // write string on lcd
		  cmd(0xc4);  // set cursor at 4th position of second line
		  lcd_display(0x00);  // display first custom character
	          lcd_str("  ");  
		  lcd_display(0x01);  // display second custom character
		  lcd_str("  ");
		  lcd_display(0x02); // display third custom character
		  lcd_str("  "); 
		  lcd_display(0x03); // display fourth custom character
                  while(1);   // infinite loop
  }
  	
void send_str()   // function to save custom character on lcd
  {
     unsigned int i,j;  // declaring variables
		
     for(j=0;j<4;j++)   // for loop
      {
        i=0; 
        cmd(0x40+j*8); // select the position from where data of custom character is saved
        while(i<8)  
          {
             lcd_display(dat[j][i]); // save 8 data of each custom character
	           delay_fv(10,4);  // hault for some time
	           i++;       // increment i by 1
          }
     }
  }

LCD4BIT HEADER FILE

#define LCD (0xf<<19)
#define RS (1<<16)
#define RW (1<<17)
#define EN (1<<18)

void lcd_display(unsigned char x)  // lcd display funtion
  {
                        unsigned int temp;    //initilize variable
                        delay_ms(700);        // calling delay
                        IO0CLR|=(RS|RW|EN|LCD); // clearing rs, rw,en and lcd pins
                        temp=(x>>4)&0x0f;   // rotating value of x by 4 and anding with 0x0f
                        IO0SET|=(temp<<19);  //put value of temp at on lcd pins
                        IO0SET|=RS;    // set re pin
                        IO0CLR|=RW;    // clear rw pin 
                        IO0SET|=EN;    // set enable pin
                        delay_ms(10); // hault for some time
                        IO0CLR|=EN;   // clear enable pin
                        
                        delay_fv(1000,10); // calling delay function
                        IO0CLR|=(RS|RW|EN|LCD); // clearing rs, rw,en and lcd pins
                        temp=x&0x0f;    // anding value of x with 0x0f
                        IO0SET|=(temp<<19); // putting value of temp on lcd data pin
                        IO0SET|=RS;  // set re pin 
                        IO0CLR|=RW;  // clear rw pin
                        IO0SET|=EN;  // set enable pin
                        delay_ms(10); // hault for some time
                        IO0CLR|=EN;  // clear enable pin
                        delay_ms(100); // calling delay function
  }

void cmd(unsigned char x)   // lcd command funtion
  {
                        unsigned int temp;      //initilize variable
                        IO0CLR|=(RS|RW|EN|LCD); // clearing rs, rw,en and lcd pins
                        temp=(x>>4)&0x0f;   // rotating value of x by 4 and anding with 0x0f
                        IO0SET|=(temp<<19);  //put value of temp at on lcd pins
                        IO0CLR|=RS;  // clear re pin
                        IO0CLR|=RW;  // clear rw pin
                        IO0SET|=EN;  // set enable pin
                        delay_ms(1000); // hault for some time
                        IO0CLR|=EN;  // clear enable pin
                        
                        delay_fv(100,10);  // calling delay function
                        IO0CLR|=(RS|RW|EN|LCD);  // clearing rs, rw,en and lcd pins
                        temp=x&0x0f;     // anding value of x with 0x0f
                        IO0SET|=(temp<<19);  // putting value of temp on lcd data pin
                        IO0CLR|=RS;  // clear re pin 
                        IO0CLR|=RW;  // clear rw pin
                        IO0SET|=EN;  // set enable pin
                        delay_ms(1000); // hault for some time
                        IO0CLR|=EN; // clear enable pin
                        delay_fv(100,10);        // calling delay function
 }

void lcd_ini()   // lcd initilization function
 {
                        cmd(0X02);  // to initialize LCD in 4-bit mode.
                        cmd(0X28);  //to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
                        cmd(0x0e);  // cursor ON
                        cmd(0X06);
                        cmd(0X01);  // clear lcd
                        cmd(0X80);  // cursor indicating first line first position
  }

void lcd_str(unsigned char *str)  // funtion to write sting on lcd
  {
     while(*str!='\0')  // check str for NULL
       {
          lcd_display(*str);  // write one characture from string
          str++;     // increament string
       }
  }

DELAY.H  HEADER FILE 

void delay_ff()
{
    unsigned int b,v;
    for(b=0;b<600;b++)
    for(v=0;v<100;v++);
}

void delay_pf(unsigned int x)
{
 unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<153;j++);
}

void delay_fv(unsigned int x,int y)
{
 unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<y;j++);
}

void delay_ms(int count)
{
  int j=0,i=0;

  for(j=0;j<count;j++)
  {
    /* At 60Mhz, the below loop introduces
    delay of 10 us */
    for(i=0;i<35;i++);
  }
}

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

Content for the tab VIDEO