STM32-Touch Screen Experiment

Publisher:mb5362443Latest update time:2016-01-11 Keywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
void Touch_Init(void);//initialization

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:

[cpp] view plaincopy
 
  1. while(1)  
  2.     {     
  3.         key=KEY_Scan();  
  4.         if(Pen_Point.Key_Sta==Key_Down)//The touch screen is pressed  
  5.         {  
  6.             Pen_Int_Set(0); //Disable interrupt  
  7.             do  
  8.             {  
  9.                 Convert_Pos();  
  10.                 Pen_Point.Key_Sta=Key_Up;  
  11.                 if(Pen_Point.X0>216&&Pen_Point.Y0<16)Load_Drow_Dialog();//'RST' area, click this area to clear the screen  
  12.                 else   
  13.                 {  
  14.                     Draw_Big_Point(Pen_Point.X0,Pen_Point.Y0);//画图        
  15.                     GPIOC->ODR|=1<<1; //PC1 pull-up       
  16.                 }  
  17.             }while(PEN==0); //If PEN is always valid, it will continue to execute  
  18.             Pen_Int_Set(1); //Enable interrupt  
  19.         }else delay_ms(10);  
  20.         if(key==1) //KEY0 is pressed, the calibration procedure is executed  
  21.         {  
  22.             LCD_Clear(WHITE);//清屏  
  23.             Touch_Adjust(); //Screen calibration   
  24.             Save_Adjdata();    
  25.             Load_Drow_Dialog();  
  26.         }  
  27.         i++;  
  28.         if(i==20)  
  29.         {  
  30.             i=0;  
  31.             LED0=!LED0;  
  32.         }  
  33.     }  

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:

 

[cpp] view plaincopy
 
  1. while(1)  
  2. {  
  3.     key=KEY_Scan(0);  
  4.     tp_dev.scan(0);            
  5.     if(tp_dev.sta&TP_PRES_DOWN) //The touch screen is pressed  
  6.     {     
  7.         if(tp_dev.x
  8.         {     
  9.             if(tp_dev.x>(lcddev.width-24)&&tp_dev.y<16)Load_Drow_Dialog();//清除  
  10.             else TP_Draw_Big_Point(tp_dev.x,tp_dev.y,RED);      //画图                     
  11.         }  
  12.     }else delay_ms(10); //When no button is pressed           
  13.     if(key==KEY_RIGHT) //When KEY_RIGHT is pressed, the calibration procedure is executed  
  14.     {  
  15.         LCD_Clear(WHITE);//清屏  
  16.         TP_Adjust(); //Screen calibration   
  17.         TP_Save_Adjdata();     
  18.         Load_Drow_Dialog();  
  19.     }  
  20.     i++;  
  21.     if(i==20)  
  22.     {  
  23.         i=0;  
  24.         LED0=!LED0;  
  25.     }  
  26. }  

Keywords:STM32 Reference address:STM32-Touch Screen Experiment

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

Some findings on downloading Flash using IAR+Jlink to develop STM32
1. Use Jlink to download the program, without performing Flash whole chip erasure. 2. Based on 1,     The following situation occurs,     When you download a larger program such as 30k for the first time, and a smaller program such as 10k for the second time, Then after the second download, there is 20K of Fla
[Microcontroller]
How to convert the STM32 F101 series program to STM F103 and a compilation error occurs!
The following is the solution (experimental environment KEIL5 version number: 5.25) first step:  Take F103C8T6 small capacity as an example (MD represents medium capacity 64K or 128K), HD represents (large capacity 256K or 512K)   After the changes are made, compile it! If there are still many errors in the co
[Microcontroller]
How to convert the STM32 F101 series program to STM F103 and a compilation error occurs!
[STM32 Motor Vector Control] Record 12——IWDG Watchdog
Watchdog concept:      In a microcomputer system composed of a single chip, the operation of the single chip is often disturbed by external magnetic fields, causing confusion in the data of various registers and memories, resulting in program pointer errors, not being in the program area, taking out wrong program ins
[Microcontroller]
[STM32 Motor Vector Control] Record 12——IWDG Watchdog
STM32 continuous interrupt problem +
STM32 sometimes keeps interrupting. The solution is as follows 1. When initializing the serial port configuration, you need to turn on the ORE overflow interrupt, as shown in the red code below void Usart_Init(void)   {             GPIO_InitTypeDef GPIO_InitStructure;       NVIC_InitTypeDef NVIC_InitStructure;    
[Microcontroller]
Analysis of the first byte loss problem of stm32 serial port
STM32 serial port transmission must first detect the status, otherwise the first byte cannot be sent. After the transmission is completed, it is necessary to detect whether the transmission status is completed, otherwise, the transmission is unsuccessful. When using stm32f10x to debug serial port communication, an err
[Microcontroller]
The difference between STM32 register operation and library function operation
/*********************** Structure operation lights up the LED ********************************/   #include stdint.h //Data type declaration standard header file #define __IO volatile //Define __IO   //GPIO register structure definition typedef struct { __IO uint32_t CRL; __IO uint32_t CRH; __IO uint32_t IDR; __IO uin
[Microcontroller]
Must read! STM32 ultra-low power series STM32L0
STM32L0 is the flagship product of the Butterfly family low-power series, DNA@ ARM Cortex- M0+, light price, rich peripherals. Green, intelligent, safe, miniaturized, more exploration, more choices! ST MCU low power consumption family overview STM32Lx(0,1,4) low power series positioning   STM32L
[Microcontroller]
Must read! STM32 ultra-low power series STM32L0
STM32 RTC (Real Time Clock) 32.768kHz Crystal Oscillator Start-up Guide
It is an industry consensus that the STM32 RTC crystal oscillator often fails to oscillate. Many people ask for help on various electronic forums with questions like "Ask an expert for advice! What should I do if the RTC crystal oscillator does not oscillate?", and the answer can basically be summarized as "The expert
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号