Section 71: LCD screen character, 16-dot, 24-dot and 32-dot display procedures

Publisher:BlissfulDreamsLatest update time:2016-03-16 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Opening remarks:

This section will teach you two knowledge points:

The first one: How to use the arbitrary dot matrix font display function display_lattice to display 8x16 characters, 16 dot matrix Chinese characters, 24 dot matrix Chinese characters and 32 dot matrix Chinese characters.

Second: Correct a small mistake in the previous section. The C51 compiler is a little different from other microcontroller compilers. To save constant data in the ROM program storage area, you do not use the const keyword, but the code keyword.

For details, please see the source code.

(1) Hardware platform:

Based on Zhu Zhaoqi 51 single-chip microcomputer learning board.

(2) Function realization: After powering on, you can see that the LCD screen displays the two characters "Mantou" in 32-dot, 24-dot and 16-dot matrices, and the two characters "V5" in 8x16-dot matrices.

(3) The source code is explained as follows:

#include "REG52.H"

sbit LCDCS_dr = P1^6; //chip select line

sbit LCDSID_dr = P1^7; //Serial data line

sbit LCDCLK_dr = P3^2; //Serial clock line

sbit LCDRST_dr = P3^4; //reset line

void SendByteToLcd(unsigned char ucData); //Send a byte of data to the LCD module

void SPIWrite(unsigned char ucWData, unsigned char ucWRS); //Simulate SPI to send a byte of command or data to the underlying driver of the LCD module

void WriteCommand(unsigned char ucCommand); //Send a byte command to the LCD module

void LCDWriteData(unsigned char ucData); //Send one byte of data to the LCD module

void LCDInit(void); //Initialization function including LCD module reset

void display_lattice(unsigned int x,unsigned int y,const unsigned char *ucArray,unsigned char ucFbFlag,unsigned int x_amount,unsigned int y_amount); //Display any lattice function

void display_clear(void); // Clear the screen

void delay_short(unsigned int uiDelayshort); //Delay

/* Note 1:

* Correct a small mistake in the previous section. The C51 compiler is a little different from other compilers.

* Constant data stored in the ROM program storage area does not use the const keyword, but the code keyword.

*/

code unsigned char Hz3232_man[]= /* horizontal modulus 32x32 dot matrix*/

{

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x07,0x03,0x00,0x0F,0x87,0xFF,0x80,

0x0F,0x07,0x03,0x80,0x0E,0x07,0x03,0x80,0x0E,0x37,0xFF,0x80,0x1C,0x7F,0x03,0x80,

0x1F,0xFF,0x03,0x80,0x18,0x77,0xFF,0x00,0x38,0xE0,0x00,0xC0,0x36,0xDF,0xFF,0xF0,

0x77,0x9C,0xCE,0xE0,0x67,0x1C,0xCE,0xE0,0xC7,0x1C,0xCE,0xE0,0x07,0x1C,0xCE,0xE0,

0x07,0x1F,0xFF,0xE0,0x07,0x18,0x00,0x00,0x07,0x00,0x03,0x80,0x07,0x0F,0xFF,0xC0,

0x07,0x71,0x8F,0x00,0x07,0xE0,0xDE,0x00,0x07,0xC0,0xFC,0x00,0x07,0x80,0x78,0x00,

0x0F,0x01,0xFE,0x00,0x07,0x03,0x8F,0xE0,0x00,0x1E,0x03,0xF0,0x00,0xF8,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

code unsigned char Hz3232_tou[]= /*Head horizontal modulus 32x32 dot matrix*/

{

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xE0,0x00,

0x03,0xC3,0xC0,0x00,0x00,0xF3,0x80,0x00,0x00,0x7B,0x80,0x00,0x00,0x7B,0x80,0x00,

0x00,0x3B,0x80,0x00,0x0E,0x03,0x80,0x00,0x07,0x83,0x80,0x00,0x03,0xC3,0x80,0x00,

0x01,0xE3,0x80,0x00,0x01,0xE3,0x80,0x00,0x00,0xC3,0x80,0x00,0x00,0x03,0x81,0xE0,

0x7F,0xFF,0xFF,0xF0,0x00,0x07,0x80,0x30,0x00,0x07,0x00,0x00,0x00,0x07,0x80,0x00,

0x00,0x0E,0xE0,0x00,0x00,0x1E,0x7C,0x00,0x00,0x3C,0x1F,0x00,0x00,0x78,0x0F,0xC0,

0x00,0xF0,0x03,0xC0,0x03,0xC0,0x01,0xE0,0x0F,0x00,0x00,0xE0,0x78,0x00,0x00,0x00,

0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

code unsigned char Hz2424_man[]= /* horizontal modulus 24x24 dot matrix*/

{

0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x18,0x30,0x1E,0x1F,0xF8,0x1C,0x1C,0x38,0x1C,

0x1F,0xF8,0x19,0xFC,0x38,0x3F,0xFF,0xF8,0x31,0x98,0x30,0x7B,0xE0,0x0E,0x6F,0x7F,

0xFE,0x6E,0x76,0xEE,0xCC,0x76,0xEE,0x0C,0x7F,0xFE,0x0C,0x70,0x0C,0x0C,0x00,0x38,

0x0C,0x3F,0xF8,0x0D,0xCE,0x70,0x0F,0x87,0xE0,0x0F,0x03,0x80,0x1E,0x07,0xE0,0x0C,

0x1C,0x7E,0x01,0xF0,0x1F,0x00,0x00,0x00,

};

code unsigned char Hz2424_tou[]= /*Head horizontal modulus 24x24 dot matrix*/

{

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x06,0x0F,0x00,0x07,0x8E,0x00,0x01,

0xEE,0x00,0x00,0xEE,0x00,0x00,0xEC,0x00,0x1C,0x0C,0x00,0x0F,0x0C,0x00,0x07,0x9C,

0x00,0x03,0x9C,0x00,0x00,0x1C,0x0C,0x00,0x1C,0x1E,0x7F,0xFF,0xF6,0x00,0x1C,0x00,

0x00,0x3C,0x00,0x00,0x3F,0x80,0x00,0x71,0xE0,0x00,0xE0,0xF8,0x01,0xC0,0x3C,0x07,

0x00,0x1C,0x3C,0x00,0x0C,0x70,0x00,0x00,

};

code unsigned char Hz1616_man[]= /* horizontal modulus 16X16 dot matrix*/

{

0x21,0xF8,0x21,0x08,0x21,0xF8,0x3D,0x08,0x45,0xF8,0x48,0x00,0x83,0xFC,0x22,0x94,

0x23,0xFC,0x20,0x00,0x21,0xF8,0x20,0x90,0x28,0x60,0x30,0x90,0x23,0x0E,0x00,0x00,

};

code unsigned char Hz1616_tou[]= /*Head horizontal modulus 16X16 dot matrix*/

{

0x00,0x80,0x10,0x80,0x0C,0x80,0x04,0x80,0x10,0x80,0x0C,0x80,0x08,0x80,0x00,0x80,

0xFF,0xFE,0x00,0x80,0x01,0x40,0x02,0x20,0x04,0x30,0x08,0x18,0x10,0x0C,0x20,0x08,

};

code unsigned char Zf816_V[]= /*V horizontal modulus 8x16 dot matrix*/

{

0x00,0x00,0x00,0xE7,0x42,0x42,0x44,0x24,0x24,0x28,0x28,0x18,0x10,0x10,0x00,0x00,

};

code unsigned char Zf816_5[]= /*5 horizontal modulus 8x16 dot matrix*/

{

0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00,

};

void main()

{

LCDInit(); // Initialize 12864 including the reset of the LCD module

display_clear(); // Clear the screen

display_lattice(0,0,Hz3232_man,0,4,32); //Display the 32-dot matrix <漫> character

display_lattice(2,0,Hz3232_tou,0,4,32); //Display the character in 32-dot matrix

display_lattice(4,0,Hz2424_man,0,3,24); //Display the 24-dot matrix <漫> character

display_lattice(6,0,Hz2424_tou,0,3,24); //Display the character in 24 dot matrix

display_lattice(8,0,Hz1616_man,0,2,16); //Display the 16-dot matrix <漫> character

display_lattice(9,0,Hz1616_tou,0,2,16); //Display the 16-dot matrix character

display_lattice(11,0,Zf816_V,0,1,16); //Display 8x16 dot matrixcharacter

display_lattice(12,0,Zf816_5,0,1,16); //Display the <5> character of 8x16 dot matrix

while(1)

{

;

}

}

void display_clear(void) // Clear the screen

{

unsigned char x,y;

WriteCommand(0x34); //Display buffer command

WriteCommand(0x34); //Display buffer off command is intentionally written twice, for fear that it will not work once. This is because I refer to a driver from a certain manufacturer that is also written in this way.

y=0;

while(y<32) //y axis ranges from 0 to 31

{

WriteCommand(y+0x80); //vertical address

WriteCommand(0x80); //Horizontal address

for(x=0;x<32;x++) //256 horizontal points, 32 bytes

{

LCDWriteData(0x00);

}

y++;

}

WriteCommand(0x36); //Open display buffer command

}

/* Note 2: The core function of this section. Readers should especially understand the display relationship between x_amount and y_amount.

* The first and second parameters x and y are coordinate systems. The range of x is 0 to 15, and the range of y is 0 to 31.

* The third parameter *ucArray is the array of fonts.

* The fourth parameter ucFbFlag is the reverse display flag. 0 represents normal display, 1 represents reverse display.

* The 5th and 6th parameters x_amount and y_amount represent the number of bytes in the horizontal direction and the number of bytes in the vertical direction of the font array respectively.

*/

void display_lattice(unsigned int x,unsigned int y,const unsigned char *ucArray,unsigned char ucFbFlag,unsigned int x_amount,unsigned int y_amount)

{

unsigned int j=0;

unsigned int i=0;

unsigned char ucTemp;

WriteCommand(0x34); //Display buffer command

WriteCommand(0x34); //Display buffer off command is intentionally written twice, for fear that it will not work once. This is because I refer to a driver from a certain manufacturer that is also written in this way.

for(j=0;j

{

WriteCommand(y+j+0x80); //vertical address

WriteCommand(x+0x80); //Horizontal address

for(i=0;i

{

ucTemp=ucArray[j*x_amount+i];

if(ucFbFlag==1) //Highlight

{

ucTemp=~ucTemp;

}

LCDWriteData(ucTemp);

// delay_short(30000); //Remove the delay function in the previous section to speed up the screen refresh

}

}

WriteCommand(0x36); //Open display buffer command

}

void SendByteToLcd(unsigned char ucData) //Send a byte of data to the LCD module

{

unsigned char i;

for ( i = 0; i < 8; i++ )

{

if ( (ucData << i) & 0x80 )

{

LCDSID_dr = 1;

}

else

{

LCDSID_dr = 0;

}

LCDCLK_dr = 0;

LCDCLK_dr = 1;

}

}

void SPIWrite(unsigned char ucWData, unsigned char ucWRS) //Simulate SPI to send a byte of command or data to the underlying driver of the LCD module

{

SendByteToLcd( 0xf8 + (ucWRS << 1) );

SendByteToLcd(ucWData & 0xf0);

SendByteToLcd( (ucWData << 4) & 0xf0);

}

void WriteCommand(unsigned char ucCommand) //Send a byte command to the LCD module

{

LCDCS_dr = 0;

LCDCS_dr = 1;

SPIWrite(ucCommand, 0);

delay_short(90);

}

void LCDWriteData(unsigned char ucData) //Send one byte of data to the LCD module

{

LCDCS_dr = 0;

LCDCS_dr = 1;

SPIWrite(ucData, 1);

}

void LCDInit(void) //Initialization function including LCD module reset

{

LCDRST_dr = 1; // reset

LCDRST_dr = 0;

LCDRST_dr = 1;

}

void delay_short(unsigned int uiDelayShort) //delay function

{

unsigned int i;

for(i=0;i

{

;

}

}

Closing remarks:

The font display we are talking about now is horizontal. If a project requires the entire LCD screen to be rotated 90 degrees clockwise and a string of fonts to be displayed vertically like a couplet, what should be done? I encountered such a project two months ago. At that time, my approach was to rotate the font array 90 degrees through an algorithm to achieve the goal. How is this algorithm program written? For details, please listen to the next analysis - the algorithm program for rotating the font 90 degrees clockwise to display.

Reference address:Section 71: LCD screen character, 16-dot, 24-dot and 32-dot display procedures

Previous article:Section 70: In-depth explanation of the LCD screen word formation process
Next article:Section 72: Algorithm program for rotating the font 90 degrees clockwise on the LCD screen

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号