打印
[示波器]

如何实现液晶显示屏电阻式触摸功能

[复制链接]
1239|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
随着智能手机引领触摸屏的趋势,越来越多的应用像医疗液晶显示屏,工业TFT显示器等都将触摸板嵌入到液晶屏中。市场上有多种LCD触摸屏的实现方式,我们以最简单的四线电阻式触摸为例,来解释LCD触摸屏实现的基本原理。
四线电阻式触摸
Analog Device 的 AD7843 是一款常见的4线电阻触摸板控制器,我们用它来支持电阻式触摸屏。
应用目标和平台考虑
  • 大多数工业和仪表应用的触摸屏都是用于菜单选择和触摸按钮功能。从触摸屏上做高分辨率的读取不是必要的。
  • 对于7" 左右的LCD 显示屏来说,4位的分辨率就足够了(可以定义16x16 的触摸区域)
  • AD7846 提供12位或8位A/D分辨率,对于我们的例子来说已经足够了。
了解 AD7843 的操作过程
下图是一个完整的 AD7843 操作流程(单次采集操作)。基于此,工程师可以设计他们程序的操作顺序。(关于继续采样,请参考AD7834 datasheet
通信包
  • 一个数据包含有 24 (3x8) 时钟脉冲 (DCLK)
  • /CS=0 和第一次 DIN=1(start bit, S)时,通信开始
  • 前 8个 DCLK 用于命令输入(Host to AD7843) via DIN, 上升沿触发
  • 后 16个 DCLK 用于 A/D 结果输出 (AD7843 to Host), 主机可在下降沿读取数据 DCLK (DCLK=0 provides a valid bit output at DOUT)
  • 如要终止通信,可在每 8 个时钟周期后设 /CS=1
  • 设置 MODE=1 AD7843进行8位采样, 在第 16 个时钟周期后设 /CS=1可停止通讯
  • 设置 MODE=0 AD7843进行12位采样, 在第 24 个时钟周期后设 /CS=1可停止通讯
关于 /PENIRQ 信号
  • /PENIRQ is an "open collector" output signal. It may be necessary to add a pull up resistor (e.g. 10k) for the host
  • On powering on, AD7843 provides /PENIRQ output, the output can be disabled by setting config bit PD0=1
  • /PENIRQ reflects "touched" status. 1: not touched; 0: being touched
  • After the "S" inputted, /PENIRQ will not function any more. At the 4th DCLK and after, changes to Hi. /PENIRQ resumes to normal function (command setting PD0=0)
  • /PENIRQ is not related to /CS signal
AD7843 I/O 例程
  • 例子使用的是 8 位命令,输出 8 位 A/D 结果
  • 数据在 DCLK 上升沿写入
  • DCLK=0时读取数据
  • 所有的读写在第16时钟周期 DCLK 结束,然后用 /CS=1 结束通讯
  • 加入8个空的时钟周期,确保 /PENIRQ 恢复正常工作
uchar TP_IO8(uchar Command)
// send a command and return 8bit conversion result
// Command bits(MSB to LSB): S,A2,A1,A0,MODE,SER/DFR,PD1,PD0
{
uchar i;
temp=Command; // copy the command to bit accessible variable
temp_b3=1; // set the MODE to 8bit only
TP_DOUT=1; // pull up for read
TP_DCLK=0; // prepare for data trans transfer
_TP_CS=0; // select the touch panel IO
for(i=0;i<8;i++) // write command with 1st to 8th DCLK
{
TP_DIN = temp_b7; TP_DCLK=1; TP_DCLK=0;
temp=temp<<1;
}
// delayms(1); // delay for 12bit conversion
for(i=0;i<8;i++) // read data
{
temp=temp<<1;
TP_DCLK=1; TP_DCLK=0; temp_b0=TP_DOUT;
}
_TP_CS=1;
for(i=0;i<8;i++) // PenIrq re-enable at 21st CLK
{ // thus 8 dummy clock provided
TP_DCLK=1; TP_DCLK=0;
}
return(temp);
}
应用流程示例
  • Use /PENIRQ to ensure touch panel is "being touched"
  • Get X and Y A/D result (keep upper 4 bits)
  • Delay for de-bouncing
  • Again, use /PENIRQ to set touch panel is "being touched"
  • Get X and Y A/D result (keep upper 4 bits)
  • Delay for de-bouncing
  • Once again, use /PENIRQ to ensure touch panel is "being touched" and compare the last two sets of results
  • It the results are the same, we can confirm the touch panel is functioning correctly, and reliable result is given out
  • Based on this result, we could display a box or do a response on screen.
void WzitTouchAndResponse(void)
{
uchar x, y;
uchar i, j ;
uchar Verified_AD; // flag for verified A/D
Verified_AD=0;
while (Verified_AD==0)
{
while(_TP_PENQ) // ensure it is touched then start AD
{
}
i = TP_IO8(0xd8)>>4; // X-Ch, 8bit, LoPw, with PenInt
j = TP_IO8(0x98)>>4; // Y-Ch, 8bit, LoPw, with PenInt
delayms(50); // de-bouncing
while(_TP_PENQ) // ensure it is touched then start AD
{
}
x = TP_IO8(0xd8)>>4; // X-Ch, 8bit, LoPw, with PenInt
y = TP_IO8(0x98)>>4; // Y-Ch, 8bit, LoPw, with PenInt
delayms(50); // de-bouncing
if ((i==x) && (j==y) && (!_TP_PENQ)) // ensure two results are the same
{ // and still touching
Verified_AD=1;
}
}
Box20x15(x, y, touch_Mark);
}
以上程序还可以进一步改进以适应实际应用。
总结
上面的例子是针对低分辨率的应用,其逻辑流程可以用于高分辨率的应用。同时,为了支持触摸操作,并不一定要进行 tones calculation ,一个合理的逻辑流程可以简化整个操作过程。

使用特权

评论回复

相关帖子

沙发
biubiu108|  楼主 | 2022-5-31 09:47 | 只看该作者
更多信息,请关注Topway官网 www.topwaydisplay.com

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

85

主题

116

帖子

0

粉丝