u8 Read_ADS(u16 *x,u16 *y); //Bidirectional read with discard
u8 Read_ADS2(u16 *x,u16 *y); //Bidirectional coordinate read with enhanced filtering
u16 ADS_Read_XY(u8 xy); //Coordinate read with filtering (single direction)
u16 ADS_Read_AD(u8 CMD); //Read AD conversion value
void ADS_Write_Byte(u8 num); //Write a data to the control chip void
Drow_Touch_Point(u8 x,u16 y); //Draw a coordinate called a point
void Draw_Big_Point(u8 x,u16 y); //Draw a big point
void Touch_Adjust(void); //Touch screen calibration
void Save_Adjdata(void); //Save calibration parameters
u8 Get_Adjdata(void); //Read calibration parameters
void Pen_Int_Set(u8 en); //PEN interrupt enable/disable
void Convert_Pos(void); //Result conversion function
The above are the main functions in touch.c:
1.void Touch_Init(void); //Initialization
Contains clock initialization, EXTI1 interrupt setting, enables interrupt on line1, and sets falling edge trigger
2.u8 Read_ADS(u16 *x,u16 *y); //Bidirectional reading with discard
Single read coordinate function
3.u8 Read_ADS2(u16 *x,u16 *y); //Bidirectional coordinate reading with enhanced filtering
Secondary reading of coordinates
4.u16 ADS_Read_XY(u8 xy); //Coordinate reading with filtering (single direction)
Read READ_TIMES times of data continuously, sort them in ascending order, remove the lowest and highest LOST_VAL numbers, and take the average value
5.u16 ADS_Read_AD(u8 CMD); //Read AD conversion value
6.void ADS_Write_Byte(u8 num); //Write a data to the control chip
7.void Drow_Touch_Point(u8 x,u16 y);//Draw a coordinate called a touch point
8.void Draw_Big_Point(u8 x,u16 y); //Draw a big point
Drawing and writing functions
9.void Touch_Adjust(void); //Touch screen calibration
10.void Save_Adjdata(void); //Save calibration parameters
The calibrated coordinate parameters are saved in 2401
11.void Pen_Int_Set(u8 en); //PEN interrupt enable/disable
The interrupt is triggered when the touch screen is pressed. You can use this function to temporarily turn off the interrupt and turn it on again after the drawing is completed.
12.void Convert_Pos(void); //Result conversion function
The coordinates read by the touch screen are physical coordinates, and the coordinates used in the program are LCD pixel coordinates. This function is used as a conversion
There is a problem in the main function. I saw many people asked this question in the forum:
- while(1)
- {
- key=KEY_Scan();
- if(Pen_Point.Key_Sta==Key_Down)//The touch screen is pressed
- {
- Pen_Int_Set(0); //Disable interrupt
- do
- {
- Convert_Pos();
- Pen_Point.Key_Sta=Key_Up;
- if(Pen_Point.X0>216&&Pen_Point.Y0<16)Load_Drow_Dialog();//'RST' area, click this area to clear the screen
- else
- {
- Draw_Big_Point(Pen_Point.X0,Pen_Point.Y0);//画图
- GPIOC->ODR|=1<<1; //PC1 pull-up
- }
- }while(PEN==0); //If PEN is always valid, it will continue to execute
- Pen_Int_Set(1); //Enable interrupt
- }else delay_ms(10);
- if(key==1) //KEY0 is pressed, the calibration procedure is executed
- {
- LCD_Clear(WHITE);//清屏
- Touch_Adjust(); //Screen calibration
- Save_Adjdata();
- Load_Drow_Dialog();
- }
- i++;
- if(i==20)
- {
- i=0;
- LED0=!LED0;
- }
- }
This is a question post in the forum, related posts and solutions: http://www.openedv.com/posts/list/1813.htm Please study it when you need it.
In the Battleship version of the Zhengdian Atom routine, PEN is not used as a judgment condition, which avoids this problem:
- while(1)
- {
- key=KEY_Scan(0);
- tp_dev.scan(0);
- if(tp_dev.sta&TP_PRES_DOWN) //The touch screen is pressed
- {
- if(tp_dev.x
- {
- if(tp_dev.x>(lcddev.width-24)&&tp_dev.y<16)Load_Drow_Dialog();//清除
- else TP_Draw_Big_Point(tp_dev.x,tp_dev.y,RED); //画图
- }
- }else delay_ms(10); //When no button is pressed
- if(key==KEY_RIGHT) //When KEY_RIGHT is pressed, the calibration procedure is executed
- {
- LCD_Clear(WHITE);//清屏
- TP_Adjust(); //Screen calibration
- TP_Save_Adjdata();
- Load_Drow_Dialog();
- }
- i++;
- if(i==20)
- {
- i=0;
- LED0=!LED0;
- }
- }
Previous article:STM32 memory management implements malloc, free, remalloc and other functions
Next article:STM32-DMA study notes
Recommended ReadingLatest update time:2024-11-23 10:53
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- ESP-S3-12K (IV) ---- Here comes the ESP-box effect
- Robots of various shapes and forms "sing and dance" at the International Robot Exhibition
- I would like to ask about the problem that I cannot get data when simulating the I/O port connection file.
- Pre-registration for the prize live broadcast: ADI's vital signs monitoring solutions in wearable products
- Win rewards by completing levels | Get Microchip SAML10 and SAM L11 magic weapons to dismantle the security crisis in the electronics industry!
- Fun Oscilloscope + Plot Heart
- Timer T0 controls the running light
- [Review of SGP40] Rapid deployment of AI ambient air quality tracking model #3 I2C and UART interface selection
- [Silicon Labs BG22-EK4108A Bluetooth Development Evaluation] Development Environment Construction Step by Step
- Signal Generator and DA Conversion FPGA Case Tutorial