Serial port control program packaging method of LCD 1602 liquid crystal screen

CN115878114BActive Publication Date: 2026-10-09YUNNAN NORMAL UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211627662.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-16
Publication Date
2026-10-09
Estimated Expiration
2042-12-16

AI Technical Summary

Technical Problem

[0004]针对现有技术的不足,本发明提供了一种LCD1602液晶屏的串口控制程序封装方法,解决了使用起来不方便,后期修改起来也不方便,无形中带来了开发和维护成本的增加的问题

Benefits of technology

本发明通过降低LCD1602设备的开发要求和开发成本,对于开发者而言,只需要按需求使用封装好的10条数据帧,就可以实现原来复杂繁琐的开发工作,达到相同的效果,且后续程序的修改维护工作也比较简单,提高了开发者体验,对于设备而言,使用串口有效降低了连线成本,让设备的使用更加便捷。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115878114B_ABST
    Figure CN115878114B_ABST
Patent Text Reader

Abstract

The application provides a serial port control program packaging method of an LCD 1602 liquid crystal screen, and relates to the technical field of control program packaging. The serial port control program packaging method of the LCD 1602 liquid crystal screen comprises the following steps: step one, first, define a communication frame, the frame format of which is as follows: the first byte represents a device address (i.e. the number of devices), the second byte represents the length of the frame data, the third byte is an operation code, the fourth byte and the following bytes are data, the number of which varies with the operation code, and the last two bytes are 16-bit check codes of the communication frame. By reducing the development requirements and development costs of the LCD 1602 device, the developer only needs to use the packaged 10 data frames according to the requirements to realize the original complex and complicated development work, achieve the same effect, and the subsequent program modification and maintenance work is relatively simple, the developer experience is improved, the connection cost is effectively reduced by using the serial port, and the use of the device is more convenient.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of control program packaging technology, specifically a method for packaging a serial port control program for an LCD1602 liquid crystal screen. Background Technology

[0002] Currently, LCD1602 LCD screens are widely used in embedded systems, but they generally transmit data in parallel, which is very wasteful of pin resources and has a short transmission distance. Although the LCD1602 also has a 4-bit data mode, it is still a parallel mode and requires the participation of three additional control lines, so it is not a true serial mode and cannot adjust costs. In terms of software control, the LCD1602 is based on Hitachi's HD44780 control chip, which has 11 operation commands, divided into two categories: one is command data (such as clearing the screen, cursor positioning, etc.), and the other is display data (the content to be displayed). Each type of command also needs to be programmed in conjunction with control pins, which is not only unclear but also prone to program confusion, leading to development difficulties.

[0003] Traditional programming for controlling the LCD1602 display requires considering many factors, making it inconvenient to use and modify later, thus increasing development and maintenance costs. Summary of the Invention

[0004] To address the shortcomings of existing technologies, this invention provides a serial port control program encapsulation method for LCD1602 liquid crystal screens, which solves the problems of inconvenience in use and modification, and the resulting increase in development and maintenance costs.

[0005] To achieve the above objectives, the present invention provides the following technical solution: a serial port control program encapsulation method for an LCD1602 liquid crystal screen, comprising the following steps; Step 1: First, define the communication frame. Its frame format is as follows: the first byte represents the device address, the second byte represents the length of the data in this frame, the third byte is the opcode, the fourth byte and subsequent bytes are the data, the specific number of bytes varies depending on the opcode, and the last two bytes are the 16-bit checksum of this communication frame. Step 2: Set up 10 commands and their corresponding frame formats; Step 3: Set the response frame format for the 10 commands.

[0006] Preferably, step two further includes the following steps: First, device reset, operation code: 0x01, parameter: none, frame length: 5 bytes. This command is used to reset the LCD1602. Second, cursor reset, operation code: 0x02, parameter: none, frame length: 5 bytes. This command is used to reset the cursor address without changing the displayed content. Third, clear screen, operation code: 0x03, parameter: none, frame length: 5 bytes. This command is used to clear the displayed content and reset the cursor address. Fourth, initialization, operation code: 0x04, parameter: 1 byte, frame length: 6 bytes. This command is used for the initialization operation of the LCD1602. The "1-byte parameter" represents the specific function to be initialized bit by bit, using only the lower 6 bits, as follows: The 5th digit: a value of 0 indicates single-line display, and a value of 1 indicates double-line display.

[0007] The 4th bit: a value of 0 indicates that the address pointer AC is decremented, and a value of 1 indicates that it is incremented.

[0008] The third position: a value of 0 indicates cursor movement, and a value of 1 indicates image movement.

[0009] The second digit: a value of 0 indicates that the display is off, and a value of 1 indicates that the display is on.

[0010] The first digit: a value of 0 indicates that the cursor is not displayed, and a value of 1 indicates that the cursor is displayed.

[0011] 0th bit: A value of 0 indicates that the cursor does not blink, and a value of 1 indicates that it blinks.

[0012] Preferably, step two further includes the following steps: Fifth, display a character at a specific position, operation code: 0x05, parameter: 3 bytes, frame length: 8 bytes. This command is used to display an ASCII character in a certain row and column. In the "3-byte parameter," the first byte indicates the row number, with a value from 1 to 2; the second byte indicates the column number, with a value from 1 to 16; and the third byte is the ASCII code of the character to be displayed. Sixth, display a string of characters at a specific position, operation code: 0x06, parameter: 2+n bytes, frame length: 7+n bytes. This command is used to display a string of characters starting at a certain row and column. In the "2+n byte parameter," the first byte indicates the row number, with a value from 1 to 2; the second byte indicates the column number, with a value from 1 to 16; and the third byte is the ASCII code of the character to be displayed. The value ranges from 1 to 16; the following n bytes are the ASCII codes of the string to be displayed. Seventh, cursor movement, opcode: 0x07, parameter: 1 byte, frame length: 6 bytes. This command moves the cursor, where the "1-byte parameter" indicates whether to move left or right. A value of 0x4c (ASCII code for L) moves left, and 0x52 (ASCII code for R) moves right. Eighth, image movement, opcode: 0x08, parameter: 1 byte, frame length: 6 bytes. This command moves the image, where the "1-byte parameter" indicates whether to move left or right. A value of 0x4c (ASCII code for L) moves left, and 0x52 (ASCII code for R) moves right. Ninth, retrieve data at a specific position. Opcode: 0x09, parameter: 2 bytes, frame length: 7 bytes. This command is used to retrieve the display data in a specific row and column. In the "2-byte parameter", the first byte indicates the row number, with a value from 1 to 2; the second byte indicates the column number, with a value from 1 to 16. Tenth, retrieve the address of the current cursor, opcode: 0x0a, parameter: none, frame length: 5 bytes. This command is used to retrieve the current cursor position, i.e., the AC value.

[0013] Preferably, step three further includes the following steps: 1. Device reset response. [Device Address][0x06][0x01][Response Value][Check Code 1][Check Code 2], where the "Response Value" is 0xaa indicating success and 0x55 indicating failure; 2. Cursor reset response. [Device Address][0x06][0x02][Response Value][Check Code 1][Check Code 2], where the "Response Value" is 0xaa indicating success and 0x55 indicating failure; 3. Screen clear response. [Device Address][0x06][0x03][Response Value][Check Code 1][Check Code 2], where the "Response Value" is 0xaa indicating success and 0x55 indicating failure; 4. Initialization response. [Device Address][0x06][0x04][Response Value][Checksum 1][Checksum 2], where "Response Value" is the initialization parameter indicating success, and 0x55 indicates failure. 5. Display a single character at a specific position as a response. [Device Address][0x06][0x05][Response Value][Checksum 1][Checksum 2], where "Response Value" is the ASCII code of the displayed character indicating success, and 0x55 indicates failure. 6. Display a string of characters at a specific position as a response. [Device Address][0x05+n][0x06][Response Value][Checksum 1][Checksum 2], where "Response Value" is n bytes of ASCII code, i.e., the displayed string indicates success, and 0x55 indicates failure. 7. Cursor movement response. [Device Address][0x06][0x07][ Response value][Check code 1][Check code 2], where "Response value" is the parameter for cursor movement (i.e., movement direction) indicating success, and 0x55 indicating failure. 8. Image movement response, [Device address][0x06][0x08][Response value][Check code 1][Check code 2], where "Response value" is the parameter for image movement (i.e., movement direction) indicating success, and 0x55 indicating failure. 9. Response to obtain data at a specific location, [Device address][0x06][0x09][Response value][Check code 1][Check code 2], where "Response value" is the obtained data. 10. Response to obtain the address of the current cursor, [Device address][0x06][0x0a][Response value][Check code 1][Check code 2], where "Response value" is the obtained address.

[0014] This invention provides a method for packaging a serial port control program for an LCD1602 liquid crystal screen. It has the following advantages: This invention reduces the development requirements and costs of LCD1602 devices. For developers, they only need to use 10 pre-packaged data frames as needed to achieve the same effect as the previously complex and cumbersome development work. Furthermore, subsequent program modification and maintenance are also relatively simple, improving the developer experience. For the device, the use of a serial port effectively reduces wiring costs and makes the device more convenient to use. Attached Figure Description

[0015] Figure 1 This is a hardware block diagram of the present invention; Figure 2 This is a schematic diagram of the overall data frame processing process of the present invention; Figure 3 This is a schematic diagram illustrating the processing steps of the hardware reset, cursor reset, and screen clearing modules of the present invention. Figure 4 This is a schematic diagram of the initialization module processing procedure of the present invention; Figure 5 This is a schematic diagram of the cursor or image movement processing procedure of the present invention; Figure 6 A schematic diagram illustrating the process of displaying a character module at a specific location and displaying a string of character modules at a specific location in this invention; Figure 7 This is a schematic diagram illustrating the processing steps of the module for obtaining specific location data and the module for obtaining the current cursor address according to the present invention. Figure 8 This is a schematic diagram of the initialization process of the LCD1602 liquid crystal screen of the present invention. Detailed Implementation

[0016] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0017] Example: like Figure 1 The diagram shows the hardware structure upon which the method of this invention is based. The MCU in the diagram is the main body for implementing this method. It performs serial-to-parallel conversion and implements program encapsulation and parsing.

[0018] like Figure 2The diagram shows the main program structure of this invention. All low-level operations on the LCD1602 are encapsulated into 10 module programs, each implementing operations on the LCD1602. First, data frames from the main control device are received via serial port. According to the data frame definition, the first byte is the address of the LCD1602, which is assigned to the variable `dev_num`. The second byte is the length of the data frame, providing a reference for how many bytes of data the serial port should receive. The third byte is the opcode, with values ​​from 0x01 to 0x0a, defined as device reset, cursor reset, screen clear, initialization, displaying a character at a specific position, displaying a string of characters at a specific position, cursor movement, image movement, obtaining data at a specific position, and obtaining the current cursor address. The received opcode is first assigned to the variable `cmd`, and then the corresponding module program is executed according to the specific command.

[0019] like Figure 3 The diagram shows the program flow for the hardware, cursor reset, and screen clearing modules. When the received operation code is 0x01, commands 0x02 and 0x01 are written to the LCD1602 to reset the LCD screen. Then, the returned data frame is encapsulated. A successful data frame consists of: byte 1 being the value of variable `dev_num`, byte 2 being 0x06, byte 3 being the value of variable `cmd`, byte 4 being 0xaa, and bytes 5-6 being a 16-bit checksum of the first four bytes. A failed data frame consists of: byte 1 being the value of variable `dev_num`, byte 2 being 0x06, byte 3 being the value of variable `cmd`, byte 4 being 0x55, and bytes 5-6 being a 16-bit checksum of the first four bytes. After encapsulation, the data frame is immediately sent back to the main control device via the serial port. When the received operation code is 0x02, command 0x02 is written to the LCD1602 to reset the cursor. Then, a data frame is encapsulated and sent back. The data frame structure is consistent with that of the hardware reset. After completion, the data frame is immediately sent back to the master device via the serial port. When the received operation code is 0x03, command 0x01 is written to the LCD1602 to clear the screen. Then, a data frame is encapsulated and sent back. The data frame content structure is consistent with that of the hardware reset. After completion, the data frame is immediately sent back to the master device via the serial port.

[0020] like Figure 4The diagram shows the program flow for the initialization module. When the received opcode is 0x04, the 4th byte represents the initialization parameters. This parameter is first assigned to the variable `parm`, and then an initialization command is written to the LCD1602 according to the specific content of the parameters to initialize the LCD screen. Next, the returned data frame is encapsulated. A successful data frame consists of: the first byte being the value of the variable `dev_num`, the second byte being 0x06, the third byte being the value of the variable `cmd`, the fourth byte being the value of the variable `parm`, and bytes 5-6 being a 16-bit checksum of the first four bytes. A failed data frame consists of: the first byte being the value of the variable `dev_num`, the second byte being 0x06, the third byte being the value of the variable `cmd`, the fourth byte being 0x55, and bytes 5-6 being a 16-bit checksum of the first four bytes. After encapsulation, the data frame is immediately sent back to the main control device via the serial port.

[0021] like Figure 5 The diagram shows the program flow for the cursor movement or image movement module. When the received opcode is 0x07, the 4th byte represents the initialization parameter, which is first assigned to the variable parm. When the parameter value is 0x4c, command 0x10 is written to LCD1602 to move the cursor one position to the left. When the parameter value is not 0x4c, command 0x14 is written to LCD1602 to move the cursor one position to the right. Then, the returned data frame is encapsulated. A successful data frame consists of: the first byte being the value of variable dev_num, the second byte being 0x06, the third byte being the value of variable cmd, the fourth byte being the value of variable parm, and bytes 5-6 being the 16-bit checksum of the first four bytes. A failed data frame consists of: the first byte being the value of variable dev_num, the second byte being 0x06, the third byte being the value of variable cmd, the fourth byte being 0x55, and bytes 5-6 being the 16-bit checksum of the first four bytes. After encapsulation, the data frame is immediately sent back to the master device via serial port. When the received operation code is 0x08, the 4th byte represents the initialization parameter, which is first assigned to the variable parm. When the parameter value is 0x4c, the command 0x1c is written to the LCD1602 to shift the image one position to the left. When the parameter value is not 0x4c, the command 0x18 is written to the LCD1602 to shift the image one position to the right. Then, the sent-back data frame is encapsulated. A successful data frame consists of: the first byte being the value of the variable dev_num, the second byte being 0x06, the third byte being the value of the variable cmd, the fourth byte being the value of the variable parm, and bytes 5 and 6 being the 16-bit checksum of the first four bytes. A failed data frame consists of: the first byte being the value of the variable dev_num, the second byte being 0x06, the third byte being the value of the variable cmd, the fourth byte being 0x55, and bytes 5 and 6 being the 16-bit checksum of the first four bytes. Once encapsulated, the data frame is immediately sent back to the main control device via the serial port.

[0022] like Figure 6 The diagram shows the program flow for displaying a single character or a string of characters at a specific location. When the received opcode is 0x05, the 4th byte represents the row and is assigned to the variable `row`, the 5th byte represents the column and is assigned to the variable `col`, and the 6th byte represents the character to be displayed and is assigned to the variable `ch`. Then, based on the row, column, and display content information, the corresponding command is written to the LCD1602 to display the character at that row and column. Next, the returned data frame is encapsulated. A successful data frame consists of: the first byte being the value of the variable `dev_num`, the second byte being 0x06, the third byte being the value of the variable `cmd`, the fourth byte being the value of the variable `ch`, and bytes 5-6 being a 16-bit checksum of the first four bytes. A failed data frame consists of: the first byte being the value of the variable `dev_num`, the second byte being 0x06, the third byte being the value of the variable `cmd`, the fourth byte being 0x55, and bytes 5-6 being a 16-bit checksum of the first four bytes. After encapsulation, the data frame is immediately sent back to the master device via serial port. When the received operation code is 0x06, the 4th byte represents the row and is assigned to the variable `row`, the 5th byte represents the column and is assigned to the variable `col`, and the 6th byte represents a string of characters to be displayed and is assigned to the array variable `ch[]`. Then, according to the row, column, and display content information, the corresponding command is written to the LCD1602 to display the string at the beginning of the row and column. Next, the sent-back data frame is encapsulated. The data frame indicating success is as follows: the 1st byte is the value of the variable `dev_num`, the 2nd byte is the specific length value (5+n), the 3rd byte is the value of the variable `cmd`, the 4th byte is the value of the array variable `ch[]`, and the last 2 bytes are the 16-bit checksum of all the preceding bytes. The data frame indicating failure is as follows: the 1st byte is the value of the variable `dev_num`, the 2nd byte is 0x06, the 3rd byte is the value of the variable `cmd`, the 4th byte is 0x55, and the 5th and 6th bytes are the 16-bit checksum of the preceding 4 bytes. Once encapsulated, the data frame is immediately sent back to the main control device via the serial port.

[0023] like Figure 7The diagram shows the program flow for the module that retrieves data at a specific location or obtains the address of the current cursor. When the received opcode is 0x09, the 4th byte represents the row, which is assigned to the variable `row`, and the 5th byte represents the column, which is assigned to the variable `col`. Then, the corresponding command is written to the LCD1602 to retrieve the content at that row and column, and this content is assigned to the variable `ch`. Next, the data frame to be sent back is encapsulated: the 1st byte is the value of the variable `dev_num`, the 2nd byte is 0x06, the 3rd byte is the value of the variable `cmd`, the 4th byte is the value of the variable `ch`, and the 5th and 6th bytes are the 16-bit checksum of the first 4 bytes. After encapsulation, the data frame is immediately sent back to the master device via the serial port. When the received opcode is 0x0a, the corresponding command is written to the LCD1602 to obtain the address value of the current cursor, and this address is assigned to the variable `ac`. Next, the data frame to be sent back is encapsulated: the first byte is the value of the variable dev_num, the second byte is 0x06, the third byte is the value of the variable cmd, the fourth byte is the value of the variable ac, and the fifth and sixth bytes are the 16-bit checksum of the first four bytes. After encapsulation, the data frame is immediately sent back to the master device via the serial port.

[0024] The operations for writing commands and data to the LCD should be performed according to the HD44780 control chip datasheet. Some operations require busy checks, while others do not. The initialization process requires the following steps: Figure 8 As shown. After power-on, a delay of more than 15 milliseconds is performed first, then 0x30 (without checking for busy) is written to the LCD1602, followed by a delay of more than 4.1 milliseconds, then 0x30 (without checking for busy) is written again, followed by a delay of more than 100 microseconds, then 0x30 (without checking for busy) is written again, and finally the corresponding value is written according to the initialization parameter parm. After completing the above steps, the LCD1602 initialization is finished. Writing to the LCD1602 is divided into two modes: writing commands and writing data. When writing commands, busy status can be checked or not, but busy status must be checked when writing data. When performing read and write operations, the timing requirements of the HD44780 must be strictly followed. The low-level operations of the LCD1602 can be encapsulated into 12 functions in C language: busy wait function, write command function, write data function, initialization function, cursor positioning function, single character display function, string display function, cursor position reading function, data reading function, cursor movement function, image movement function, and delay function. Based on this method, most of the work of operating the LCD1602 is completed by the MCU. Current development only requires sending the corresponding command data frames via the serial port, eliminating the need to concern oneself with the operational details of the LCD1602, thus reducing development requirements and costs. For developers, understanding the specific functions of 10 serial port command data frames is sufficient for easy development, and subsequent modification and maintenance are also relatively simple.

[0025] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A method for packaging a serial port control program for an LCD1602 liquid crystal screen, characterized in that, All low-level operations on the LCD1602 LCD screen are encapsulated into 10 module programs. Each module program implements the operation of the LCD1602 LCD screen. First, data frames from the main control device are received via serial port. According to the definition of the data frame, the first byte is the address of the LCD1602 LCD screen, which is assigned to the variable dev_num; the second byte is the length of the data in this frame; the third byte is the opcode, whose value ranges from 0x01 to 0x0a, which are defined as device reset, cursor reset, screen clear, initialization, display a character at a specific position, display a string of characters at a specific position, cursor movement, image movement, get data at a specific position, and get the current cursor address, respectively. The received opcode is first assigned to the variable cmd, and then the corresponding module program is executed according to the specific command. Includes the following steps: Step 1: First, define the communication frame. Its frame format is as follows: the first byte represents the device address, the second byte represents the length of the data in this frame, the third byte is the opcode, the fourth byte and subsequent bytes are the data, and the last two bytes are the 16-bit checksum of this communication frame. Step 2: Set up 10 commands and their corresponding frame formats; Step 3: Set the response frame format for the 10 commands; Step two further includes the following steps: First, the frame format of the device reset command includes the device address, frame length 0x05, operation code 0x01, checksum 1, and checksum 2. This command is used to reset the LCD1602 screen. Second, the frame format of the cursor reset command includes the device address, frame length 0x05, operation code 0x02, checksum 1, and checksum 2. This command is used to reset the cursor address without changing the displayed content. Third, the frame format of the clear screen command includes the device address, frame length 0x05, operation code 0x03, checksum 1, and checksum 2. This command is used to clear the displayed content and reset the cursor address. Fourth, the frame format of the initialization command includes the device address, frame length 0x06, operation code 0x04, parameter 1, checksum 1, and checksum 2. Parameter 1 consists of 8 binary bits, numbered from right to left as bit 0, bit 1, bit 2, bit 3, bit 4, bit 5, bit 6, and bit 7. These bits represent the functions to be initialized, as follows: The 5th digit: a value of 0 indicates single-line display, and a value of 1 indicates double-line display; The 4th bit: a value of 0 indicates that the address pointer AC is decremented, and a value of 1 indicates that it is incremented; The third bit: a value of 0 indicates cursor movement, and a value of 1 indicates image movement; The second digit: a value of 0 indicates that the display is off, and a value of 1 indicates that the display is on; 1st bit: A value of 0 indicates that the cursor is not displayed, and a value of 1 indicates that the cursor is displayed; 0th bit: A value of 0 indicates that the cursor does not blink, and a value of 1 indicates that it blinks.

2. The serial port control program encapsulation method for an LCD1602 liquid crystal screen according to claim 1, characterized in that: Step two also includes the following steps: Fifth, the frame format of the command to display a character at a specific position includes device address, frame length 0x08, operation code 0x05, parameter 1, parameter 2, parameter 3, check code 1, and check code 2. This command is used to display an ASCII character in a specified row and column. Among the three parameters, the first parameter represents the row to be displayed, with a value of 1 to 2; the second parameter represents the column to be displayed, with a value of 1 to 16; and the third parameter is the ASCII code content of the character to be displayed. Sixth, the frame format of the command to display a string of characters at a specific position includes the device address, frame length 0x07+n, opcode 0x06, parameter 1, parameter 2, parameter n, checksum 1, checksum 2. This command is used to display a string of characters starting at a specified row and column. Parameter 1 indicates the row to be displayed, with a value of 1 to 2. Parameter 2 indicates the column to be displayed, with a value of 1 to 16. The following n parameters are the ASCII code content of the string to be displayed. Seventh, the frame format of the cursor movement command includes device address, frame length 0x06, opcode 0x07, parameter 1, check code 1, and check code 2. This command is used to move the cursor. Parameter 1 determines whether to move left or right. A value of 0x4c moves left and a value of 0x52 moves right. Eighth, the frame format of the image movement command includes device address, frame length 0x06, opcode 0x08, parameter 1, checksum 1, and checksum 2. This command is used to move the image. Parameter 1 determines whether to move left or right; a value of 0x4c moves left, and a value of 0x52 moves right. Ninth, the frame format of the command to retrieve data at a specific position includes device address, frame length 0x07, opcode 0x09, parameter 1, parameter 2, checksum 1, and checksum 2. This command is used to retrieve display data in a specified row and column. Parameter 1 represents the row of data to be retrieved, with a value from 1 to 2, and parameter 2 represents the column of data to be retrieved, with a value from 1 to 16. Tenth, the frame format of the command to retrieve the address of the current cursor includes device address, frame length 0x05, opcode 0x0a, checksum 1, and checksum 2. This command is used to retrieve the value of AC at the current cursor position.

3. The serial port control program encapsulation method for an LCD1602 liquid crystal screen according to claim 1, characterized in that: Step three further includes the following steps:

1. The response command frame format for device reset includes device address, frame length 0x06, operation code 0x01, response value, checksum 1, and checksum 2, where a response value of 0xaa indicates success and 0x55 indicates failure; 2. The response command frame format for cursor reset includes device address, frame length 0x06, operation code 0x02, response value, checksum 1, and checksum 2, where a response value of 0xaa indicates success and 0x55 indicates failure; 3. The response command frame format for clearing the screen includes device address, frame length 0x06, operation code 0x03, and checksum 2. The response command frame format includes:

1. Response value, checksum 1, and checksum 2. A response value of 0xxaa indicates success, and 0x55 indicates failure.

2. The initialization response command frame format includes: device address, frame length 0x06, opcode 0x04, response value, checksum 1, and checksum 2. A response value of 0xxaa indicates success, and 0x55 indicates failure.

3. The response command frame format for displaying a character at a specific position includes: device address, frame length 0x06, opcode 0x05, response value, checksum 1, and checksum 2. A response value of 0xxaa indicates success, and 0x55 indicates failure. 5 indicates failure; 6. The response command frame format for displaying a string of characters at a specific location includes the device address, frame length 0x05+n, opcode 0x06, response value, checksum 1, and checksum 2. The response value is an n-byte ASCII string indicating success, and 0x55 indicates failure; 7. The response command frame format for cursor movement includes the device address, frame length 0x06, opcode 0x07, response value, checksum 1, and checksum 2. The response value is the cursor movement parameter indicating success, and 0x55 indicates failure; 8. The response command frame format for image movement includes the device address, frame length 0x06, opcode 0x07, response value, checksum 1, and checksum 2. The format of the response command frame for obtaining data at a specific location includes the device address, frame length 0x06, operation code 0x08, response value, checksum 1, and checksum 2. The response value is the image movement parameter indicating success, and 0x55 indicates failure. The format of the response command frame for obtaining the current cursor address includes the device address, frame length 0x06, operation code 0x09, response value, checksum 1, and checksum 2. The response value is the obtained data.

Citation Information

Patent Citations

  • Master-slave serial communication protocol

    CN105975424A