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 matrixdisplay_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 matrixdisplay_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
characterdisplay_lattice(11,0,Zf816_V,0,1,16); //Display 8x16 dot matrix
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.
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
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- PT6312 driver Samsung segment screen hardware design driver source code
- Why does the STM series MCU use SMD T card instead of traditional T card?
- The problem that the main function cannot be run after downloading the program with IAR compiler
- Added multiple ST sensor drivers in MakeCode
- Selection of power device heat sink
- LabView Note 4: Temperature Monitoring System Based on LabView Password Login
- The command configurations in the manual are all expressed in hexadecimal. How should they be used in the code?
- Gizwits Timer Switch
- Getting Started Manual for Oscilloscopes Written by Tektronix
- Learn “how to arrange” and “how to connect”, PCB design specifications are so easy!