In the human-computer interaction system, input devices such as keyboards and touch screens are an indispensable part. For consumer electronics such as mobile phones and tablets, touch screens have been widely used due to their very good user experience. Here, the author briefly introduces the application of s3c2416 IIC interface capacitive touch screen.
Android and iOS used in mobile phones and tablets, most operating systems (or graphics systems) do not support multi-point touch very well. This mode of pulling the interrupt signal line low when there is touch and pulling the interrupt signal line high when there is no touch will be very well applied to these software. The trigger mode is that when there is touch, the driver chip will generate an interrupt signal at a certain frequency to report the coordinate position of the touch point. Usually, this reporting frequency is about 100HZ (the driver chip is solidified). If the reporting frequency is too low, it may cause point loss. This can ensure the recognition of multiple touch points. At present, mainstream mobile phones and tablets all use this working method to obtain the coordinate position of multi-point touch.
The capacitive screen module of the author adopts the IIC interface. Therefore, the implementation of the s3c2416 capacitive screen driver needs to be based on the IIC driver in the previous chapter. In the capacitive screen test code, an example of 5-point touch canvas is given, and 5 fingers can be used to draw on the canvas at the same time. The touch screen module code test in this chapter requires the support of the startup code, IIC interface module, and RGB screen driver module in the previous chapter.
The tp_ft5206.c module is implemented as follows:
#include "s3c2416.h"
#include "IIC.h"
#include "tp_ft5206.h"
#include "Exception.h"
volatile unsigned char TP_Press;
static void TP_EINT8_15_IRQ()
{
if (rEINTPEND & (1<<12)) { //EINT12 interrupt processing
rEINTMASK |= (1 << 12); // EINT12 interrupt disable
rEINTPEND |= (1 << 12); // Clear interrupt flag
TP_Press = 1; // Indicates that the touch screen is pressed
}
rSRCPND1 |= (1 << INT_EINT8_15);//Clear pending bit
rINTPND1 |= (1 << INT_EINT8_15);
}
static void Delay_ms(unsigned int nCount)
{
//Delay 1ms, total delay nCount(R0) ms
__asm__ __volatile__ (
"0:\n\t"
"ldr r1, =100000\n\t" // Arm clock为400M
"1:\n\t"
"subs r1, r1, #1\n\t" // 一个Arm clock
"bne 1b\n\t" // Jump will clear the pipeline, 3 Arm clocks
"subs %0, %0, #1\n\t" // The caller ensures that nCount is not 0
"bne 0b\n\t"
: : "r"(nCount):"r1"
);
}
// Write Length bytes of data to the internal address WriteAddr of the capacitive touch screen. The data location is in pData.
intTP_WriteBytes(unsigned char WriteAddr, unsigned char *pData,
int Length)
{
//Call IIC write to continuously write to a certain address inside the capacitive screen
return IIC_WriteBytes(TP_SlaveAddr,WriteAddr, pData, Length);
}
//Continuously read Length bytes of data from the internal address ReadAddr of the capacitive touch screen, and save the data in pData
intTP_ReadBytes(unsigned char ReadAddr, unsigned char *pData,
int Length)
{
// Call the IIC interface to read continuously a certain address inside the capacitive screen
return IIC_ReadBytes(TP_SlaveAddr, ReadAddr,pData, Length);
}
void TP_Reset()
{
rGPFDAT &= ~(1 << 5); // Pull the reset line low
Delay_ms(20);
rGPFDAT |= (1 << 5);
Delay_ms(200);
}
void TP_Init()
{
rGPGUDP &= ~(0x3 << 8); //GPG4 (EINT12) as capacitive screen interrupt input
rGPGUDP |= (0x2 << 8); // TP_INT GPG4 pull-up
rGPGCON &= ~(0x3 << 8);
rGPGCON |= (0x2 << 8); // GPG4 is configured as EINT12
rGPFUDP &= ~(0x3 << 10); //GPF5 is used as reset control signal
rGPFUDP |= (0x2 << 10); // TP_RST GPF5 pull-up
rGPFCON &= ~(0x3 << 10);
rGPFCON |= (0x1 << 10); // GPF5 is configured as output
TP_Reset(); //TP reset
//TP external interrupt entry function is added to the vector table
IRQ_Register(INT_EINT8_15, TP_EINT8_15_IRQ);
rEXTINT1 &= ~(0x7 << 16);
rEXTINT1 |= (0x2 << 16); // EINT12 falling edge trigger
rINTMOD1 &= ~(1 << INT_EINT8_15);// EINT8_15 IRQ
rINTMSK1 &= ~(1 << INT_EINT8_15); // EINT8_15 enables interrupt
rEINTMASK &= ~(1 << 12); // EINT12 enable interrupt
}
The contents of the module header file are as follows:
#ifndef__TP_FT5206_H__
#define__TP_FT5206_H__
#ifdef__cplusplus
extern"C" {
#endif
// TP IIC 7-bit slave address
#define TP_SlaveAddr 0x38
#define TOUCH1_XH 0x03
#define TOUCH1_XL 0x04
#define TOUCH1_YH 0x05
#define TOUCH1_YL 0x06
#define ID_G_MODE 0xA4
extern void TP_Reset(void);
extern void TP_Init(void);
extern int TP_WriteBytes(unsigned char WriteAddr,
unsigned char *pData, int Length);
extern int TP_ReadBytes(unsigned char ReadAddr,
unsigned char *pData, int Length);
extern volatile unsigned char TP_Press;
#ifdef__cplusplus
}
#endif
#endif/*__TP_FT5206_H__*/
The effect of drawing a line with five fingers touching at the same time:
http://pan.baidu.com/s/1i37NU2x
Previous article:S3C2416 bare metal development series 14_Transplantation of UCGUI under GCC (1)
Next article:S3C2416 bare metal development series 12_IIC driver implementation
- 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
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications