The mini2440 is connected to a resistive touch screen, which is based on AD conversion. That is, when a certain position is pressed, the voltage at that point will change. The voltage can be used to determine which point is pressed, and the arm can get the coordinates of this point. Because the touch screen and the LCD are two devices, the coordinates obtained by the touch screen generally cannot correspond to the coordinates on the LCD, so we need to manually calibrate them in the program (although they do not correspond, the relationship between them is linear, so by sampling three points, the coefficients can be determined.)
s3c2440 does not support interrupt nesting.
The arm is connected to the touch screen through four wires: tsxptsxm and tsyptsym. There is a sentence in the data sheet: When Touch Screen device is used; XM or PM is only connected ground for Touch Screen I/F. S3C2440 has a total of 4 touch screen interface modes, among which the automatic (continuous) XY coordinate conversion mode and wait for interrupt mode are what we use.
(1) Waiting for interrupt mode is to generate an interrupt when the stylus falls. In this mode, the value of the A/D touch screen control register ADCTSC should be 0xD3. After the system responds to the interrupt, the measurement mode of the XY coordinates must be no operation mode, that is, the lower two bits of the register ADCTSC must be cleared.
(2) Automatic (continuous) XY coordinate conversion mode is that the system converts the X-axis coordinate and Y-axis coordinate of the contact in sequence, where the X-axis coordinate value is written to the lower 10 bits of register ADCDAT0, and the Y-axis coordinate is written to the lower 10 bits of register ADCDAT1. In this mode, the system will also generate an interrupt signal.
In general, to realize the touch screen function, it is first set to wait for interrupt mode. After the int_tc interrupt is generated, it is set to automatic (continuous) XY coordinate conversion mode in the interrupt function to read the coordinate values of the touch points in sequence.
There are two interrupts related to the touch screen function: int_adc and int_tc. These two interrupt sources belong to subinterrupt source, both of which belong to int_adc. Therefore, when configuring interrupts, you need to configure them according to the configuration method of sub interrupt sources. Among them, int_tc is generated when the touch screen is pressed or released. Only one of the events can be detected at a time. To detect whether the touch screen is pressed or released, we need to set the 8th bit of the ADCTSC register. int_adc is generated after the ad conversion is completed.
The third bit of the ADCTSC register can select the enable of the pull-up resistor. In the waiting interrupt mode, the pull-up resistor must be valid. After the interrupt is triggered, the pull-up resistor must be invalid. The second bit of the ADCTSC register is used to select the automatic (continuous) XY coordinate conversion mode. The lower two bits of the stylus lift/drop interrupt status register ADCUPDN can determine the state of the stylus causing the interrupt. The A/D delay register ADCDLY can set the delay length from the start of the interrupt to the actual start of the A/D conversion. Its clock source frequency is 3.68MHz.
The process of implementing the touch screen function is as follows:
1. Set the touch screen to wait for interrupt mode and configure ADCTSC to generate an interrupt when the touch screen is pressed.
2. After the interrupt is generated, it proves that the touch screen is pressed. Modify ADCTSC and ADCCON in the interrupt function and configure the touch screen for continuous conversion. At the same time, the int_adc interrupt should be blocked. Because we are in the interrupt function, we use the while loop to detect the srcpnd and subsrcpnd registers to detect whether the interrupt of adc conversion completion has been generated. That is, the interrupt is blocked, but by detecting whether the interrupt is generated, we can determine whether the adc conversion is completed.
3. After the adc conversion is completed, extract the desired data. Then configure ADCSTC to generate an interrupt when the touch screen is released, and continue to mask the interrupt. By detecting srcpnd and subsrcpnd, it is determined whether an interrupt is generated when the touch screen is released. When the touch screen is detected to be released, the interrupt function ends.
Of course, I think it is also possible to use other methods to achieve this, for example, after detecting that the touch screen is pressed, the interrupt function ends. In other words, it is also feasible to implement the above three steps in three interrupt functions respectively.
In addition, regarding the calibration of the touch screen, Mr. Zhao's method is reproduced as follows:
The more common calibration method is the three-point calibration method, and its principle is:
Assume that the coordinates of each point PD on the LCD are [XD, YD], and the coordinates of each point PT on the touch screen are [XT, YT]. To convert the coordinates on the touch screen to the coordinates on the LCD, the following formula is required for conversion:
XD=A×XT+B×YT+C
YD=D×XT+E×YT+F
Because there are a total of six parameters (A, B, C, D, E, F), only three sampling points are needed to obtain these six parameters. Once these six parameters are determined, as long as the coordinate point PT on any touch screen is given and substituted into this formula, the coordinate PD of the corresponding pixel point on the LCD can be obtained. The specific solution process will not be explained in detail, only the final result is given. The three sampling points on the LCD are known to be: PD0, PD1, PD2, and the three points on the touch screen they correspond to are: PT0, PT1, PT2. The final results of the six parameters A, B, C, D, E, F are all fractions, and they all have a common denominator, which is:
K = (XT0-XT2) × (YT1-YT2) - (XT1-XT2) × (YT0-YT2)
The six parameters are:
A=[(XD0-XD2)×(YT1-YT2)-(XD1-XD2)×(YT0-YT2)] / K
B=[(XT0-XT2)×(XD1-XD2)-(XD0-XD2)×(XT1-XT2)] / K
C=[YT0×(XT2×XD1-XT1×XD2)+YT1×(XT0×XD2-XT2×XD0)+YT2×(XT1×XD0-XT0×XD1)] / K
D=[(YD0-YD2)×(YT1-YT2)-(YD1-YD2)×(YT0-YT2)] / K
E=[(XT0-XT2)×(YD1-YD2)-(YD0-YD2)×(XT1-XT2)] / K
F=[YT0×(XT2×YD1-XT1×YD2)+YT1×(XT0×YD2-XT2×YD0)+YT2×(XT1×YD0-XT0×YD1)] / K
The specific operation is to first display three points on the LCD, and then after the user clicks on these three points, collect the actual coordinates and theoretical coordinates of the three points, so that the above parameters can be calculated.
Attached below is my code.
static void __irq touchscreen_irq(void)
{
int xdata, ydata;
rADCTSC = (1<<3)|(1<<2); //Pull-up resistor is invalid, automatic continuous XY coordinate conversion mode is turned on
rADCDLY = 40000; //delay
rADCCON|=0x1; //Start A/D conversion
while(rADCCON & 0x1); //Check if A/D conversion has started
while(!(rADCCON & 0x8000)); //Wait for the end of A/D conversion
while(!(rSRCPND & (BIT_ADC))) ; //Judge the suspension bit of A/D interrupt
xdata=(rADCDAT0&0x3ff); //Read the X-axis coordinate
ydata=(rADCDAT1&0x3ff); //Read Y-axis coordinates
uart_printf("xdata = %x, ydata = %x adcdata0 = %x ", xdata, ydata, rADCDAT0);
rSUBSRCPND|=BIT_SUB_TC;
ClearPending(BIT_ADC);
rADCTSC = 0xd3; // Set the wait interrupt mode again, this time to determine whether the stylus is lifted
rADCTSC = rADCTSC|(1<<8); //Set the stylus lift interrupt
while(1) //Wait for the stylus to be lifted
{
if(rSUBSRCPND & (0x1<<9)) //Check A/D touch screen interrupt suspension
{
break; //If the stylus is lifted, then jump out of the loop
}
}
uart_printf("adcdata0 = %x ", rADCDAT0);
rSUBSRCPND = 1<<9;
ClearPending(BIT_ADC);
uart_printf("irq finishrn");
rADCTSC=0xd3; //important here
}
void touchscreen_init(void)
{
rADCDLY=50000; //Set delay
rADCCON=(1<<14)+(9<<6); //Set A/D prescaler
rADCTSC=0xd3; //Set the touch screen to wait for interrupt mode.
pISR_ADC = (U32)touchscreen_irq;
rINTSUBMSK &= ~(BIT_SUB_TC);
rSUBSRCPND = 1<<9;
ClearPending(BIT_ADC);
EnableIrq(BIT_ADC);
}
void touchscreen_test(void)
{
touchscreen_init();
}
Previous article:S3C2440 (4.3-inch) LCD driver level analysis (16)
Next article:ARM processor architecture------implementation of nested interrupts
- 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
- LLC design information collection (for learning only)
- Do the read and write registers of the ds2438 coulomb meter have a lifespan?
- Raspberry Pi based smartphone
- Share some learning videos about wireless at the University Hall. Netizens who want to learn can look here~~
- Share: Selection scheme for active balancing of multiple groups of lithium iron phosphate batteries
- [Ateli Development Board AT32F421 Evaluation] -TEST05 ADC+CFFT_1024 System Test Report
- Where can I rent an FPGA development board? Thanks in advance! ! ! ! ! !
- [SC8905 EVM Evaluation] + MCU I2C Communication Experiment
- Share WB-Serial Port Debugging Assistant
- Application of “C2000+TMS570” dual-chip solution in automotive electric drive functional safety