The LCD driver must be driven by AC voltage to maintain a stable display. If a stable DC voltage is applied to the LCD, not only will it fail to display normally, it will also damage the LCD over time. A segment of LCD is composed of a back electrode and a segment electrode. When a display is needed, an appropriate AC voltage (usually a square wave is used) is added between the back electrode and the segment electrode. In order to adjust the contrast, you can adjust the display time (ie the duty cycle) in each half cycle of the square wave.
Generally, in order to save the driving port, multiple back electrodes are connected together to form a common back electrode terminal: COM. In addition, segment electrodes belonging to different COMs are connected together to form a common segment electrode terminal: SEG. When enough AC voltage is added between a COM and a SEG, the corresponding segment will be lit (actually black).
For example, the LCD used on the PCBA module designed by Spreadtrum has 4 COMs and 16 SEGs. To display a certain SEG, it is necessary to add sufficient AC voltage between the corresponding SEG and COM. On Spreadtrum’s board, the COM driver uses two resistor dividers, and the output voltage is 1/2Vcc. When you don’t want a bit to be displayed, set its voltage to 1/2Vcc (by setting the IO port to high impedance State to complete), so that the voltage added between the corresponding SEG and COM is only 1/2Vcc, which is not enough to light up the corresponding SEG. If you need to display, set the COM voltage to 0 or 1, so that the segment where the SEG voltage is opposite to the COM voltage will be lit (blackened), because the voltage between them is Vcc. By scanning each COM regularly, the required graphics can be stably displayed on the LCD. When you need to display characters or numbers, first design the corresponding patterns yourself, and send them to the corresponding SEG and COM when displaying them. But if it is driven 100% of the time, the contrast will be too high, and even the places that should not be displayed are displayed. Therefore, after displaying for a period of time, set both COM and SEG to low to turn off its display and reduce the contrast. By adjusting the length of the off time (PWM), the contrast can be adjusted. In the following test procedure, in order to simplify the procedure, a fixed duty cycle of 50% is used.
For the convenience of description, we call the light when COM is low level as positive light, and when COM is high level, we call it negative light. Scanning each COM is divided into 4 stages: positive light, off, negative light, and off. Therefore, for the LCD driver on this board, there are a total of 16 states, and each COM has the 4 states mentioned above. We switch the state every 2ms, so the entire scan cycle is 2*16=32ms, basically no flicker is felt.
But it should be noted that each COM in this LCD does not exactly correspond to the position of a character in the display pattern. Each COM corresponds to the same 4 segments in each display character! In other words, to display the character at the first character position, every COM must be used. Therefore, to change the display of a certain character position, you need to change the 4 segments of the corresponding SEG each time the COM is output. To this end, a buffer is established, and when the displayed characters need to be modified, the content in the buffer is modified. This buffer has 4 rows, and each row has 16 SEGs, corresponding to a COM. When it is necessary to modify the display, set the corresponding 4 SEGs in each row to the required value, so that the modification of a certain display position pattern is realized.
In order to display the characters, the characters to be displayed need to be made into data according to the distribution of SEG and COM in advance and saved, and when they need to be displayed, they are copied to the corresponding position in the display buffer. In addition, since the input parameter is the ASCII code of the character, it is also necessary to convert the ASCII code into the index value of the corresponding character pattern. Use a special function to complete these conversions and fill the buffer, and call this function when you need to modify the display data.

