The detection principle of resistive touch screen is that after touching, the upper and lower conductive layers come into contact, changing the voltage output, and after A/D conversion, it becomes the X, Y coordinates of the point.
Initialize AD and touch port:
void TouchSrceen_Test(void)
{
rADCDLY = 50000; //(1/3.68MHz)*50000 = 13.56ms
Note: Before ADC conversion, the external clock X-tal clock: 3.68MHz is used,
and then GLK: 50MHz is used
rADCCON = (1<<14)|(prescaler<<6);
Note: bit[14]: 0--disable ADC 1--enable ADC bit[13:6]: prescaler = 9 ADC fleq = 50MHz/(9+1) = 5MHz
Uart_Printf("\nTouch Screen test\n");
rADCTSC = 0xd3;//waiting for interrupt Mode
Note: bit[1:0]: 11--waiting for interrupt Mode
bit[2]: 0--Normal ADC 1--Auto Sequential measurement of X-position,Y-position
bit[3]: 0--XP pull-up enable 1--XP pull-up disable
bit[4]: 0--XP output driver enable 1--XP output driver disable
bit[5]: 0--XM output driver disable 1--XM output driver enable
bit[6]: 0--YP output driver enable 1--YP output driver disable
bit[7]: 0--YM output driver disable 1--YM output driver enable
bit[8 ]: 0--stylus down interrupt signal 1--stylus up interrupt signal
pISR_ADC = (int)ADC_TCTest;
rINTMSK = ~(1<<31); //clear ADC MASK bit
rINTSUBMSK = ~(1<<9); //clear TouchScreen MASK bit
}
void __irq ADC_TCTest(void)
{
U32 saveADCDLY;
if(rADCDAT0 & 0x8000) //bit[15]:0--stylus down 1--stylus up
{
rADCTSC &= 0xff; //clear bit[8]:0 stylus down 1--stylus up
}
rADCTSC = (1<<3)|(1<<2); //disable XP pull-up
//auto sequential measurement of XY position
saveADCDLY = rADCDLY;
rADCDLY = 40000; //(1/50MHz)*40000=0.8ms
Note: As shown in the figure below, switch to GCLK when X,Y conversion is required.
rADCCON |= 0x01; //start ADC
while(rADCCON & 0x1); //waiting for ADC startup
while(!(rADCCON & 0x8000)); //waiting for ADC end
while(!(rSRCPND & (0x1<<31)));//waiting for interrupt bit=1
xdata = rADCDAT0 & 0x3ff;
ydata = rADCDAT1 & 0x3ff;
Note: Read the X, Y coordinate data in the buffer
if(((xdata-xdata_save > 5)||(xdata-xdata_save < -5))\
||((ydata-ydata_save > 5)||(ydata-ydata_save < -5)))
{
Uart_Printf("X_value = %d,Y_value = %d,X_data = %d,Y_data = %d\n",\
xdata,ydata,xdata_save,ydata_save);
}
xdata_save = xdata;
ydata_save = ydata;
rSUBSRCPND |= (1<<9);
rINTSUBMSK =~(1<<9);
rSRCPND |= (0x1<<31);
rINTPND |= (0x1<<31);
rINTMSK = ~(0x1<<31);
Note: Clear all interrupt-related flags to prepare for the next interrupt
rADCTSC = 0xd3; //waiting for interrupt
rADCTSC |= 0x100; //stylus up
while(!(rSUBSRCPND & (1<<9))); //waiting for stylus up interrupt bit=1
Uart_Printf("The pen has stylus up.");
rSUBSRCPND |= (1<<9);
rINTSUBMSK =~(1<<9);
rSRCPND |= (0x1<<31);
rINTPND |= (0x1<<31);
rINTMSK = ~(0x1<<31);
Note: Clear all interrupt-related flags to prepare for the next interrupt
rADCDLY = saveADCDLY;
rADCTSC &= ~0x100; //stylus down
}
Previous article:Color display principle of TFT LCD
Next article:S3C2440 Test Program (IV) External Interrupt Experiment
Recommended ReadingLatest update time:2024-11-15 14:51
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Some cases of DSP program crash (flying away) - hardware reasons
- 39 yuan purchase or free: RCSN's wireless serial port tool is coming~
- The world's largest computer chip
- [National Technology N32 MCU Development Package] --N32G457 Series
- Methods for solving faults in FPGA design and development based on EDA simulation technology.pdf
- Tuya Sandwich Wi-Fi & BLE SoC NANO Main Control Board WBRU+ Simple Development (Zero Code Solution)
- Belling Products MEQ6310 Low Dropout Low Noise Voltage Regulator
- Super brain-burning question, about electric fishing? !
- Op amp applications - What are the main applications of op amp integration and differentiation circuits?
- Teach you how to play with various motors