Lcd1602 can display Chinese characters? _lcd1602 display Chinese characters program

Lcd1602 can display Chinese characters
Lcd1602 can display Chinese characters? _lcd1602 display Chinese characters program

The 1602 liquid crystal is a character liquid crystal with a total of 2 lines of 16 characters per line. The valid displayable font for each character is a 5*8 dot matrix font. Therefore, Chinese cannot usually be displayed. The Chinese display must select a graphic dot matrix liquid crystal.

In particular: Does it mean simple Chinese characters such as "year, month, day"? Supports up to 8 CGRAM characters. You can do it yourself. Call the font code 0-7. For example, the "year" CGRAM unit data is: 0FH, 09H, 0FH, 09H, 0FH, 09H, 13H, 00H. These 8 bytes are written to the CGRAM cells 00H-07H. Call character code 0. You can see the Chinese "year".

Lcd1602 shows the concept of Chinese characters
Lcd1602 can display Chinese characters? _lcd1602 display Chinese characters program

First of all: we have to figure out a concept. In fact, we use 1602 to display Chinese characters, which is to use its internal custom byte space.

The content of the first line corresponds to the content of the second line of 80H to 8FH content in DDRAM corresponding to the content of C0H to CFH in DDRAM

By looking at the LCD1602 user manual, it is mentioned that when we need to write data to CGRAM, we need to write the address of CGRAM first. From the manual, the address of CGRAM is 0x40. So when we want to write data, we must Write an address command write_com(0x040) first;

Then write the data you want to write to write_date by writing the data command (you have to write the data);

Store the code you want to display Chinese characters in CGRAM, which is equivalent to other common characters fixed in the LCD. Store the code you want to display Chinese characters in CGRAM, which is equivalent to other common characters fixed in the LCD. It is equivalent to storing the code you want to display Chinese characters in CGRAM, which is equivalent to other common characters fixed in the LCD. We all know that there is a 64-byte custom CGRAM inside the LCD1602. So, we just want to use Customize the bytes to achieve the effect of displaying Chinese characters.

We know that one character occupies 8 bytes, so it can store 8 characters in CGRAM. In other words, this 64-byte CGRAM is to provide us with write data, so how do we write the Chinese characters we want to CGRAM?

The DDRAM display uses ram, which corresponds directly to the point on the screen. A point on the screen corresponds to a bit in the ddram, and the ddram of the character screen is slightly different from the ddram of the graphics screen.

CGROM stores some standard character font encoding. The LCD screen is solidified in the control chip when it leaves the factory. The user cannot change the stored content. It can only be read and called. It contains standard ASCII code, Japanese characters and Greek characters. character.

The CGRAM is the control chip left to the user to store the font code of the user's own design.

The font code must be read into the corresponding DDRAM first. After the transfer, the corresponding position of the screen will display the character. For the character screen, when a character is to be displayed, the index of the character written in ddram (usually ascii code) can be displayed.

Lcd1602 program for displaying Chinese characters
Lcd1602 can display Chinese characters? _lcd1602 display Chinese characters program

Chinese character font:

   It is the structure of the mandarin font displayed.

To define a font, you need to know the CG RAM address of 1602 and the address of the display character DD RAM:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F

The address of the first character of the first line is (0x80), and the following character address and so on.

The address of the first character of the second line is (0x80 + 0x40). You need to add an offset of 0x40 to the base address of the first line. The following address is added to the base address in turn.

Void delay(unsigned int TIme_i)

{

Int i;

For (;TIm"0;TIm--)

{

For (i=0;i"10;i++);

}

}

Void command_out (char out_data)

{

RW=0;

RS=0;

EN=1;

DB=out_data;

EN=0;

Delay(10);

}

Void OUTD(char out_data)

{

RS=1;

RW=0;

EN=1;

DB= out_data;

EN=0;

Delay(10);

}

OUTI() is a function that writes instructions, and OUTD() is a function that writes data. Such as:

The first 5*7 display data in the upper left corner is:

0x00, 0x01, 0x81, 0x12, 0x24, 0x41, 0x81, 0x10 The corresponding bit of the blue area is 1

This way you can write out all 4 5*7 dot matrix display data and wrap it in an array, such as an array.

Hanzi[]={0x00,0x01,0x81,0x12,0x24,0x41,0x81,0x10, ...... ...... ......

Then use the command:

OUTI(0X40);

For (i=0;i"64;i++)

{

OUTD(neu[i]);

}

The data in this array is assigned to the 1602 internal CGRAM. After completion, set the display address of the data on 1602, according to the structure of Figure 1, set the position, such as the first character and the second character and the second line in the first line.

Displayed at the first character and the second character:

Command_out (0x80+0x00);

For (i=0;i"4;i++)

{

Data_out (i);

}

Command_out(0x80+0x40);

For (i=4;i"8;i++)

{ data_out(i);

}

The function of command_out() is to set the starting address of the display. The function of data_out() is to send the hexadecimal data in the hanzi[] array. Each hexadecimal number corresponds to each line on the 5*7 dot matrix. content. The first character of the first line requires eight hexadecimal data, and the first character and the second character also require 816 hexadecimal data. There is also a two-character dot matrix on the second line, so that displaying a Chinese character requires 32 hexadecimal data.

Below is an example (proteus simulation passed)

//************************************************ *************************************** //

Hardware connection: 1602VDD to 5V, VO to ground, BL1 to 5V, BL2 to ground, 8 data lines to P0, RS RW E to P2.0, P2.1, P.4

//************************************************ ***************************************//

#include 《reg52.h》

#include 《string.h》

#define Busy 0x80 //Used to detect the Busy flag in the LCM status word

#define LCM_Data P0 ;

Sbit LCM_RS=P2^0; //Register selection

Sbit LCM_RW=P2^1; //Read/Write Control

Sbit LCM_E=P2^4; //Read/Write Enable

Int i,j;

/ / Custom character list //

=========================================================== ============================================

Unsigned char character0[8] = {0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02}, //year

Character1[8] = {0x0f,0x09,0x0f,0x09,0x0f,0x09,0x0b,0x11}, //month

Character2[8] = {0x0f,0x09,0x09,0x09,0x0f,0x09,0x09,0x0f}, //day

characterN[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //day

//======================================================== ==========

//======================================================== =========

/ / delay program

//======================================================== =======

Void Delay5Ms(void)

{

Unsigned long int TempCyc = 5552;

While(TempCyc--);

}

Void Delay400Ms(void)

{

Unsigned char TempCycA = 5;

Unsigned int TempCycB;

While(TempCycA--)

{

TempCycB=7269;

While(TempCycB--);

};

}

//======================================================== ====================

//Read and write subroutine

//======================================================== =================

/ / Read the data

Unsigned char ReadDataLCM(void)

{

LCM_RS = 1;

LCM_RW = 1;

LCM_E = 1;

LCM_E = 0;

For(i=0;i"100;i++);

LCM_E = 1;

Return(LCM_Data);

}

//Read status

Unsigned char ReadStatusLCM(void)

{

LCM_Data = 0xFF;

LCM_RS = 0;

LCM_RW = 1;

LCM_E = 1;

LCM_E = 0;

For(i=0;i"100;i++);

LCM_E = 1;

//while (LCM_Data & Busy); //Detect busy signal

Return(LCM_Data);

}

/ / Write data

Void WriteDataLCM(unsigned char WDLCM)

{

ReadStatusLCM(); //Detect busy

LCM_Data = WDLCM;

LCM_RS = 1;

LCM_RW = 0;

LCM_E = 1;

LCM_E = 0; //If the crystal oscillator speed is too high, you can add a small delay after this.

For(i=0;i"100;i++);//delay

LCM_E = 1;

}

/ / write instructions

Void WriteCommandLCM(unsigned char WCLCM,BuysC) //Buy busy detection when BuysC is 0

{

If (BuysC) ReadStatusLCM (); / / detect busy as needed

LCM_Data = WCLCM;

LCM_RS = 0;

LCM_RW = 0;

LCM_E = 1;

LCM_E = 0;

For(i=0;i"100;i++);

LCM_E = 1;

}

//======================================================== ===========

//Initial subroutine

//======================================================== ====================

Void LCMInit(void) //LCM initialization

{

LCM_Data = 0;

WriteCommandLCM(0x38,0); // Three display mode settings, no busy signal detected

Delay5Ms();

WriteCommandLCM(0x38,0);

Delay5Ms();

WriteCommandLCM(0x38,0);

Delay5Ms();

WriteCommandLCM(0x38,1); // Display mode setting, start to request busy signal every time

Delay5Ms();

WriteCommandLCM(0x08,1); // Close display

Delay5Ms();

WriteCommandLCM(0x01,1); // Clear Screen Delay5Ms();

WriteCommandLCM(0x06,1); // Display cursor movement settings

Delay5Ms();

WriteCommandLCM(0x0c,1); // Display on and cursor settings

Delay5Ms();

}

//======================================================== ================

/ / Display a character by the specified position

//======================================================== ====================

Void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)

{

Y &= 0x1;

X &= 0xF; //Restrict X cannot be greater than 15, Y cannot be greater than 1

If (Y) X |= 0x40; //When the second line is to be displayed, the address code is +0x40;

X |= 0x80; //calculate the instruction code

WriteCommandLCM (X, 0); / / here does not detect the busy signal, send the address code

WriteDataLCM(DData);

}

//======================================================== =================

/ / Display a string of characters by the specified position

//void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)

//Description: x(0-15): x parameter y(0-1): y parameter DData (string): content to be displayed (English, numbers, symbols)

//======================================================== =========================

Void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)

{

Unsigned char ListLength,j; ListLength = strlen(DData);

Y &= 0x1;

X &= 0xF; //Restrict X cannot be greater than 15, Y cannot be greater than 1

If (X <<= 0xF) //X coordinate should be less than 0xF

{

For(j=0;j"ListLength;j++)

{

DisplayOneChar(X, Y, DData[j]); //Display a single character X++;

}

}

}

//======================================================== ==========

/ / Display custom characters

//void mychar(char xx,char yy,unsigned char *character,unsigned char saveto)

//Description: xx(0-15): for x parameter.yy(0-1):y parameter.character: list address of the character to be displayed, defined in front of the program

//saveto(1-7) is the RAM for character storage. Up to 7 custom characters are displayed per screen // (0x00-0x0h is a custom character)

//======================================================== =============

Void mychar(char xx,char yy,unsigned char *character,unsigned char saveto)

{

Unsigned char add = (saveto "3) | 0x40;

Unsigned char t; // temporary variable, the value of each line / *

t=*(character+0);

WriteCommandLCM(add, 0); //Line 1 WriteDataLCM(t); t=*(character+1);

WriteCommandLCM(add+1, 0); //Line 2 WriteDataLCM(t); t=*(character+2);

WriteCommandLCM(add+2, 0); //Line 3 WriteDataLCM(t); t=*(character+3);

WriteCommandLCM(add+3, 0); //Line 4 WriteDataLCM(t); t=*(character+4);

WriteCommandLCM(add+4, 0); //Line 5 WriteDataLCM(t); t=*(character+5);

WriteCommandLCM(add+5, 0); //Line 6 WriteDataLCM(t); t=*(character+6);

WriteCommandLCM(add+6, 0); //Line 7 WriteDataLCM(t); t=*(character+7);

WriteCommandLCM(add+7, 0); //Line 8 WriteDataLCM(t); */

For(i = 0;i"8;i++)

{

WriteCommandLCM(add+i, 0);

WriteDataLCM(*(character+i));

}

DisplayOneChar(xx,yy,saveto); //display characters}

//======================================================== ===============

/ / Main function

//======================================================== =========

Main()

{

Delay400Ms();

LCMInit();

Delay400Ms(); //1602 initialization

While(1)

{

DisplayListChar(0,0, "This is ListChar"); DisplayListChar(0,1,"!");

For(j=0;j"30;j++)for(i=0;i"30000;i++); WriteCommandLCM(0x01,1); //clear screen

Delay5Ms();

DisplayListChar(0,0,"This is OneChar:");

DisplayOneChar(0,1,0x4f);

DisplayOneChar(1,1,0x6e);

DisplayOneChar(2,1,0x65);

DisplayOneChar(3,1,0x21);

For(j=0;j"30;j++)for(i=0;i"30000;i++);

WriteCommandLCM (0x01, 1); / / clear screen

Delay5Ms();

DisplayListChar(0,0,"This is MyChar:");

Mychar(0,1, character0,1);

Mychar(1,1, character1,2);

Mychar(2,1, character2,3);

For(j=0;j"30;j++)for(i=0;i"30000;i++);

WriteCommandLCM(0x01,1); //Clear screen Delay5Ms();

}

}

LED BAR

FEATURES:

High intensity and reliability

High quality, Low power requirement and low cost

IC compatible , Easy assembly

Meet RoHS EU Directive

ESD 2000V

10 segment led bar ,red led bar ,yellow green led bar

Wuxi Ark Technology Electronic Co.,Ltd. , https://www.arkledcn.com

This entry was posted in on