The use of LCD1602 custom symbols

The use of LCD1602 custom symbols

1. After having a basic understanding and use of LCD1602, we can then understand the use of custom characters of LCD1602.
To display custom symbols, it is necessary to use CGRAM memory, LCD1602 can only display up to 8 custom characters.

2. CGRAM can store 8 custom characters, their first addresses in the memory are: 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78.
To write the font data into CGRAM, you need to select from the first address. One, and send the font data, remember to send the custom characters in the CGRAM to the DDRAM, so that the custom characters can be displayed normally.

3. The index corresponding to the first address in the following CGRAM memory 0x00: the first (0x40) 0x01: the second (0x48) 0x02: the third (0x50) 0x03: the fourth (0x58) 0x04: the fifth ( 0x60) 0x05: the sixth (0x68) 0x06: the seventh (0x70) 0x07: the eighth (0x78), send the custom characters in the CGRAM to the DDRAM, just put the index corresponding to the first address in the CGRAM memory Just write to DDRAM. (For specific steps, see the code section)

font part

1. In the use of LCD1602, the pixel is generally set to 5*7, but a custom character occupies 8 bytes, so when writing a character; write the last bit as 0x00;
for example, in the program uchar code table[ ]={0x07,0x08,0x1c,0x08,0x1c,0x08,0x07,0x00};
uchar code table1[ ]={0x10,0x06,0x09,0x08,0x08,0x09,0x06,0x00};
in the above table Table 1 is the font data of the currency symbol of the euro (the currency symbol of the name coin and the dollar can be displayed directly), and the font data of the Celsius symbol in table1.

2. The picture below shows 00111 in the first row of € drawn by me in excel, which
euro currency symbol
corresponds to hexadecimal 0x07,
01000~0x08;
11100~0x1c;
01000~0x08;
11100~0x1c;
01000~0x08;
00111~0x07 ;
00000~ 0x00.
The font data of a custom character is obtained by sorting down in order. You can directly get the font data with the software that takes the font. You can also use the excel sheet to do it slowly like me...
The basic steps of custom symbol display:
①. Define characters written to CGRAM.
②. Send the custom characters in CGRAM to DDRAM.
The display of custom symbols is exactly the same as the basic operations of the built-in characters. The operations of writing instructions, writing data, and displaying the characters in the corresponding positions are exactly the same as the operations of the built-in characters.

code section

Through the write command, you can perform specific operations on the LCD and send the display address

void lcdwcom(uchar com) //1602写命令函数 
{
    
    
 lcdrs=0; //选择指令寄存器
 //rw=0; //选择写;我的开发板已接地
 P0=com; //把命令字送入
 delay(5); //延时一小会儿,让1602准备接收数据
 lcden=1; //使能线电平变化,命令送入1602的8位数据口
 lcden=0;
}

By writing data, send the characters we want to display into the LCD

void lcdwdat(uchar dat) //写数据 
{
    
    
  lcdrs=1; //选择写数据
  //rw=0; 
  P0=dat; //把要显示的数据送入
  delay(5); //延时一小会儿,让1602准备接收数据
  lcden=1; //使能变化;数据送入
  lcden=0;
}

Initialize the lcd and set its display mode

void lcdinit() //1602初始化
{
    
    
  dula=0;
  wela=0;//将数码管关闭
  lcdwcom(0x38); //8位数据,双列,5*7字形 
  lcdwcom(0x0c); //开启显示屏,关光标,光标不闪烁
  lcdwcom(0x06); //显示地址递增,写一个数据后,显示位置右移一位
  lcdwcom(0x01); //清屏
}

Four variables are defined, which can be called in the main function to display custom characters

void display1(uchar cgr,uchar table_num,uchar pos_,uchar count)//自定义符号显示
{
    
    
    lcdinit();//液晶初始化
 	lcdwcom(cgr);//设定CGRAM地址,把自定义字符存储进去
    for(m=table_num;m<table_num+8;m++)  //将table[]中的数据依次送入1602显示
    {
    
    
      lcd_wdat(table[m]);//写入数据
      delay(10);
    }
      lcdwcom(pos_);  //显示地址
      lcdwdat(count); //向DDRAM写入
}

Similar to the boot animation, but only a string of characters can be displayed...

void display()//开屏左移
{
    
    
  lcdinit();//液晶初始化
  lcdwcom(0x80);//选择显示地址起始位
  for(b=0;b<11;b++)
  {
    
    
    lcdwdat(table1[b]);//将hello world 送入1602
    delay(200); //可以通过延时控制hello word 的显示速度
  } 
  for(b=0;b<10;b++)
  {
    
    
    lcdwcom(0x18);//全屏左移
    delay(300);//可以通过延时控制hello word 左移的速度
  } 
}

main function part

void main() //主函数
{
    
      
   display();  
   delay(10);
   //display1(0x40,0,0x86,0x00);//显示摄氏度
   display1(0x48,8,0x86,0x01);//显示欧元
   lcdwcom(0x80);//选择显示地址
   for(num=0;num<6;num++)
   {
    
    
     lcdwdat(table2[num]);
     delay(20); 
   }    
 while(1);//动态停机
}

#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit lcden=P3^4;//使能位
sbit lcdrs=P3^5;//数据&命令选择端;
sbit dula=P2^6;	
sbit wela=P2^7;	//数码管的两个锁存器
uchar code table[]={
    
    0x10,0x06,0x09,0x08,0x08,0x09,0x06,0x00,
					0x07,0x08,0x1c,0x08,0x1c,0x08,0x07,0x00}; 
					//要显示的内容放入数组table
uchar code table1[]="Hello world";
uchar code table2[]="Types:";
uchar b,m,num;

Displayed result: After the Hello world is displayed, move left to disappear and then display type: €
I'm a novice ┗┃・ ■ ・┃┛ Sorry for the bad writing!

Guess you like

Origin blog.csdn.net/qq_52487856/article/details/116027432