introduction
Touch screen is the simplest, most convenient, natural and suitable input device for China's multimedia information query. It has many advantages such as durability, fast response, space saving, easy communication, etc. Touch screen technology is considered to be one of the mainstream directions of future human-computer interaction technology, and the application of related industries and products is also becoming a hot spot.
This design topic comes from the Guangxi Natural Science Foundation Project and is a research sub-module in the foundation project. During the graduation design period, the author of this article targeted the NL 6448AC33218 color LCD display and its touch screen, applied the C8051F020 microcontroller control chip, used the microcontroller C language to compile and debug the program, and the program adopted a modular design.
1. System composition
This design is based on the control system of color LCD and touch screen controlled by single chip C8051F020 microprocessor. The system structure block diagram is shown in Figure 1:
Figure 1 System structure diagram
2. System connection method and working process
1. Working process of C8051F020 controlling TFT6448b
In the process of using C8051F020 to control TFT 6448b, bus control is adopted. Because TFT 6448b liquid crystal controller has its own latch function, no external latch chip is needed when using bus control. It can be realized by using P0, P2, and P3 ports of single-chip microcomputer C8051F020. Before the system is powered on, since the typical working voltage of C8051F020 is 313V and the working voltage of TFT 6448b is 5V, the driving capacity of the corresponding connection pins of P0, P2, and P3 ports is expanded; according to the control requirements, the pins of the corresponding ports are configured as drain output mode through P0, P2, and P3 port registers. Configure P3 port as a data address output port. When outputting the address, it is the lower eight bits of the address bus, and P2 port provides the high address; when transmitting data, it is an 8-bit data bus port. After the system is powered on, the chip select signal CS of TFT 6448b is valid. By writing data into the corresponding row, column, control and data registers of TFT 6448b, the C8051F020 chip can be used to control TFT 6448b, thereby realizing the display control of color LCD.
(II) Touch screen hardware interface circuit and working principle
Figure 2 Touch screen hardware interface circuit
According to the working principle of the four-wire resistive touch screen, combined with the touch screen hardware interface circuit in Figure 2.
The specific working process of the touch screen hardware interface circuit is as follows: 1. As shown in Figure 2, connect the circuit and connect a 313V DC power supply to the power input terminal and the reference voltage terminal; 2. Initialize AD0 in combination with software programming. When the system is in sleep mode, the software opens an interrupt, cuts off PN P1, PN P2, and N PN 1, and saturates and conducts N PN 2; 3. Wait for the touch screen to be touched; 4. If the touch screen is touched, enter the interrupt service program, turn off the external interrupt, and perform a short delay to eliminate external jitter. By judging the level change of the interrupt input port P010, it is determined whether the jitter has ended. Through software, PN P2 and N PN 2 are cut off, PN P1 and N PN 1 are saturated, and the analog-to-digital conversion channel A IN 010 is selected to collect the X-direction coordinate value of the touch point, delay and wait for the conversion to end, and remove the conversion result; electrode voltage switching, through software setting, PN P1 and N PN 1 are cut off, PN P2 and N PN 2 are saturated, and the analog-to-digital conversion channel A IN 011 is selected to collect the Y-direction coordinate value of the touch point, delay and wait for the conversion to end, and remove the conversion result; 5. By comparing the collected X and Y coordinate values with the set key boundary value, if the comparison result is true, switch to the corresponding sub-page, otherwise, restart the interrupt and return to the main program; 6. The working process of the touch screen hardware interface circuit returns to step 3 and continues to wait for the next touch. [page]
3. Color LCD display and touch screen software design1. Display principle
If you want to display Chinese characters on a dot matrix LCD, first extract the dot matrix fonts of the Chinese characters to be displayed from the Chinese character dot matrix generation tool. Because each Chinese character is stored in the font library in the form of a dot matrix font, a font library is established in the program for easy calling. The program monitors, if it is "1", it will be displayed, and if it is "0", it will not be displayed. There are two methods to detect whether a certain bit is "1": one is the shift method. Each time it moves one bit to the left, and then judge the value of the carry. If it is "1", it means it is to be displayed, and then send the color code of the word to be displayed to the write data register DAT; if it is "0", it means it does not need to be displayed and is skipped; the other is the bit AND method. First, perform bitwise AND with 80H to determine whether the highest bit of the byte is "1". If so, it needs to be displayed; if not, skip it; then perform bitwise AND with 40H, 20H, 10H, 08H, 04H, 02H, 01H in sequence to determine whether the corresponding bit is "1". If you want to display characters, numbers, graphics, etc., the method and principle are the same as those for displaying Chinese characters.
2. Programming
1. Display program programming.
The program flow chart is shown in Figure 3:
Figure 3 shows the subroutine flow chart
2. Touch screen software design.
Combined with the touch screen hardware interface circuit shown in Figure 2, in order to realize the recognition of touch points on the touch screen, the page switching function is realized. The software design idea of the touch screen module in this design is: configure the P010 pin of the P0 port and the P114~P117 pins of the P1 port as push-pull output mode through the corresponding port output mode register; set the relevant registers of the analog-to-digital converter ADC0, configure the analog input channel as single-ended input mode, and select the analog-to-digital conversion channel of the collected data through the channel selection register. Enter the main program and wait for the external touch interrupt to occur. If the outside world touches, enter the interrupt service program and turn off the external interrupt to avoid conflicts between multiple touch points. Eliminate the jitter caused by unintentional touch by judging the change of the interrupt input port level; after eliminating the jitter. Through voltage switching, the X electrode pair and the Y electrode pair are turned on respectively, and the analog input in the X direction and the Y direction are collected and the conversion results are shifted out respectively. The collected values are compared with the pre-set key boundary values. If they are within the key range, the corresponding page is switched to, otherwise the interrupt is opened and the main program is returned to continue waiting for the external touch interrupt to occur. The corresponding software design flow chart is shown in Figure 4.
Figure 4 Software design flow chart
[page]
3. Contact judgment program design.In this design, the coordinate distribution of the color LCD screen is as follows: the upper left corner of the screen (0, 0), the lower left corner of the screen (0, 479), the upper right corner of the screen (639, 0), and the lower right corner of the screen (639, 479). By sending the corresponding values to the column, row, control, and data registers of the color LCD display control chip TFT 6448b, the display can be realized anywhere on the LCD screen. According to the design requirements of the display page, the buttons to be displayed are displayed on the LCD screen in advance with text, characters, or graphic labels. For example, there are two button labels in the page, namely "return" and "next page". The positions of these two labels on the LCD screen are as shown in Figure 5 above.
Figure 5 Two button labels on the LCD screen
According to the X and Y coordinate values collected by the ADC0 module, by measuring point by point from left to right and from top to bottom, it is concluded that the converted values of the voltage gradient of each contact point of the touch screen are distributed linearly. Because the 12-bit hexadecimal value is shifted right by 3 bits, the maximum value of the corresponding decimal number is 511, the minimum value is 0, and its accuracy is 1/512. The specific distribution of the coordinates on the touch screen is shown in Figure 6.
Figure 6 Coordinate distribution on the touch screen
According to FIG6, the coordinate values (columns, rows) of several special points of the coordinate distribution can be known, such as: the upper left corner of the touch screen (511, 511), the lower left corner of the screen (0, 511), the upper right corner of the screen (511, 0), and the lower right corner of the screen (0, 0); on this basis, by fixing the touch screen on the LCD screen, the key area boundary value of the fixed key mark on the touch screen corresponding to the display screen can be measured. The specific software flow chart is shown in FIG7: The following is explained by describing a key mark, such as the "return" key mark in FIG5.
Figure 7 Software Flowchart
1. Collect and calibrate the touch screen coordinates, and get the key boundary values, X coordinates are 51 4. Debugging In this design, the software program debugging is involved in the touch screen hardware interface circuit design and software programming. In the debugging process, the functional modularization method is adopted: For example, in the process of realizing the entire color LCD and touch screen control, the brief software and hardware debugging steps are as follows: Hardware--Realize the connection between C8051F020 and TFT 6448b2LCD control board -> Realize the connection between the single-chip C8051F020 and the touch screen -> Connect the two modules together to form an overall control system; Software--First realize the display of the monochrome screen -> On this basis, realize the display of characters of different colors and models -> Then insert a picture that occupies a small storage space (such as the C8051F020 chip outline) -> Consider the realization of any point touch -> Consider the acquisition of fixed-point touch and realize the touch of the key area -> Consider the realization of the function of switching sub-pages -> Realize a more humane color page display.
Previous article:Detailed explanation of MCS-51 single-chip microcomputer control word
Next article:About .c files and .h files in 51 single chip C
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- A strange MIC (microphone) signal amplifier circuit, I thought about it for a long time but still couldn't understand it
- My Journey of MCU Development (Part 7)
- [TI recommended course] #Common errors and solutions in DC/DC converter design#
- Pyboard timer terminal callback function problem
- Relay wiring
- Blood pressure monitor diastolic and systolic blood pressure
- How to analyze this kind of circuit? I need your advice. It can be paid.
- The 59GHz oscilloscope has arrived. Those who want to test it, please take a look.
- [Hua Diao Experience] 02 Simple use of Xingkong board
- TI live broadcast at 8pm tonight [Innovation of next-generation automotive gateway system]