转载:http://blog.youkuaiyun.com/ZJQLOVELYY/article/details/34466091
四线式电阻触摸屏
四线触摸屏包含两个阻性层。其中一层在屏幕的左右边缘各有一条垂直总线,另一层在屏幕的底部和顶部各有一条水平总线。为了在X轴方向进行测量,将左侧总线偏置为0V,右侧总线偏置为VREF。将顶部或底部总线连接到ADC,当顶层和底层相接触时即可作一次测量。为了在Y轴方向进行测量,将顶部总线偏置为VREF,底部总线偏置为0V。将ADC输入端接左侧总线或右侧总线,当顶层与底层相接触时即可对电压进行测量。
等待中断: XP上拉,XM高阻
YP模拟输入,YM接地
在数据手册上有那么一句话:
Touch Screen Controller generates interrupt (INT_TC) signal when the Stylus is down. Waiting for Interrupt Mode
setting value is rADCTSC=0xd3; // XP_PU, XP_Dis, XM_Dis, YP_Dis, YM_En.
After Touch Screen Controller generates interrupt signal (INT_TC), Waiting for interrupt Mode must be cleared.
(XY_PST sets to the No operation Mode)
也就是说需要设置为等待中断模式只需要设置ADCTSC = 0xd3即可
等待中断: XP上拉,XM高阻
YP模拟输入,YM接地
在数据手册上有那么一句话:
Touch Screen Controller generates interrupt (INT_TC) signal when the Stylus is down. Waiting for Interrupt Mode
setting value is rADCTSC=0xd3; // XP_PU, XP_Dis, XM_Dis, YP_Dis, YM_En.
After Touch Screen Controller generates interrupt signal (INT_TC), Waiting for interrupt Mode must be cleared.
(XY_PST sets to the No operation Mode)
也就是说需要设置为等待中断模式只需要设置ADCTSC = 0xd3即可
获取X坐标:XP接Vref,XM接地
YP接模拟输入,YM高阻
Vmeas = Vref * Rx2 / ( Rx1 + Rx2 )
获取Y坐标:XP模拟输入,XM高阻
YP接Vref,YM接地
Vmeas = Vref * Ry2 / ( Ry1 + Ry2 )
YP接Vref,YM接地
Vmeas = Vref * Ry2 / ( Ry1 + Ry2 )
程序的状态转换图:
所需用到的寄存器:
ADCCON
ADCTSC
ADCDLY
ADCDAT0
ADCDAT1
头文件:
所需用到的寄存器:
ADCCON
ADCTSC
ADCDLY
ADCDAT0
ADCDAT1
头文件:
- #ifndef TOUCH_H
- #define TOUCH_H
- #include "2440addr.h"
- #define PRSCEN 1 //使能分频
- #define PRSCVL 49 //分频系数
- /* 设置为等待中断 */
- #define waitDownInit() do{ \
- rADCTSC = 0xd3;\
- }while(0)
- extern __irq void touchISR();
- extern void touchInit(void);
- #endif
源文件:
- #include "TOUCH.h"
- #include "uart.h"
- #include "2440addr.h"
- __irq void touchISR()
- {
- int x,y;
- /* 松开产生的中断 */
- if (rADCTSC & (0x100))
- {
- rADCTSC &= 0xff;
- }
- else /* 按下产生的中断 */
- {
- /* 在检测XY坐标时要禁止上拉,这里设置为自动转换 */
- rADCTSC = (1<<3) | (1<<2);
- /* 开启AD转换 */
- rADCCON |= 1;
- /* 等待AD转换开启 */
- while(rADCCON & 1)
- ;
- /* 等待AD转换结束 */
- while(!(rADCCON & (1<<15)))
- ;
- /* 设置为检测松开中断 */
- rADCTSC = (1<<8) | 0xd3;
- /* 读取XY坐标值 */
- x = rADCDAT0 & 0x3ff;
- y = rADCDAT1 & 0x3ff;
- put(x);
- putc(',');
- put(y);
- putc('\n');
- }
- rSUBSRCPND = (1<<9);
- rSRCPND = 1<<31;
- rINTPND = 1<<31;
- }
- void touchInit(void)
- {
- pISR_ADC = (unsigned int)touchISR;
- /* 设置延时,之前没加的时候一按下就出了好多个数据,转换太快了 */
- rADCDLY = 50000;
- rADCCON = (PRSCEN<<14) | (PRSCVL<<6);
- /* 刚开始的时候设置为等待中断 */
- waitDownInit();
- rINTMSK &= ~(1<<31);
- rINTSUBMSK &= ~(1<<9);
- putc('H');
- }