ARM板开发触摸屏程序,出现飘屏!急求解决办法!

mygod0218 2010-04-12 11:24:07
我用ARM板测试一个触摸屏程序,偶尔出现飘屏!
源码如下:


#include "def1.h"
#include "2440addr.h"
#include "2440lib.h"
#include "config.h"


#define REQCNT 30
#define ADCPRS 9 //YH 0627
#define LOOP 1

void AdcTsAuto(void);

int TouchPanelCnt=0; // 触摸屏次数的记录

struct TouchLocation
{
volatile int x;
volatile int y;
}TPxyLocation = {0,0};
volatile int test_x;
volatile int test_y;
INT8U ts_status;//触摸屏的状态(校准还是测试)
//static U16 ts_lefttop_x,ts_lefttop_y,ts_rightbot_x,ts_rightbot_y,ts_leftbot_x,
//ts_leftbot_y,ts_righttop_x,ts_righttop_y;
struct TouchLocation TestPoint[8] = {0};

extern void AdcTsAuto_Handler(void);
extern OS_EVENT *TP_m_box;
//extern OS_EVENT *Cal_m_box;
//extern OS_EVENT *Lag_m_box;

//unsigned int buf[3][2];
U16 Ptx[6],Pty[6],tmp[6] = {0,0,0,0,0,0};

//U8 index = 0;
void AdcTsAuto(void)
{
int i;
U32 saveAdcdly;

if(rADCDAT0&0x8000)
{
//Uart_Printf("\nStylus Up!!\n");
rADCTSC&=0xff; // Set stylus down interrupt bit
}
//else

// Uart_Printf("\nStylus Down!!\n");

rADCTSC=(1<<3)|(1<<2); //Pull-up disable, Seq. X,Y postion measure.
saveAdcdly=rADCDLY;
rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms

rADCCON|=0x1; //start ADC



for(i=0;i<5;i++)
{
// rADCTSC = (1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);

rADCTSC=(1<<3)|(1<<2); //Pull-up disable, Seq. X,Y postion measure.
saveAdcdly=rADCDLY;
rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms

rADCCON |= 0x1; //Start Auto conversion
while(rADCCON & 0x1); //Check if Enable_start is low
while(!(0x8000&rADCCON)); //Check ECFLG
while(!(rSRCPND & (BIT_ADC))); //check if ADC is finished with interrupt bit

Pty[i] = (0x3ff&rADCDAT1);
Ptx[i] = (0x3ff&rADCDAT0);


//OSPrintf("----- ========(%04d,%04d)=======\n",Ptx[i], Pty[i]);
}
// buf[3][0] =((buf[0][0] + buf[1][0] + buf[2][0])/3)*10;
//buf[3][1] =((buf[0][1] + buf[1][1] + buf[2][1])/3)*10;
Ptx[5]=(Ptx[0]+Ptx[1]+Ptx[2]+Ptx[3]+Ptx[4])/5;
Pty[5]=(Pty[0]+Pty[1]+Pty[2]+Pty[3]+Pty[4])/5;
OSPrintf(" ========(%04d,%04d)=======\n",Ptx[5], Pty[5]);




//OSPrintf("----- ========(%04d,%04d)=======\n",TPxyLocation.x,TPxyLocation.y);
TPxyLocation.x=Ptx[5]*10;
TPxyLocation.y=Pty[5]*10;
//TPxyLocation.x=TPxyLocation.x*10;
// TPxyLocation.y=TPxyLocation.y*10;

//OSMboxPost(TP_m_box,(void*)1);
//YH 0627, To check Stylus Up Interrupt.
rSUBSRCPND|=BIT_SUB_TC;
ClearPending(BIT_ADC);
rINTSUBMSK&=~(BIT_SUB_TC);
rINTMSK&=~(BIT_ADC);

rADCTSC =0xd3; //Waiting for interrupt
rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.

while(1) //to check Pen-up state
{
if(rSUBSRCPND & (BIT_SUB_TC)) //check if ADC is finished with interrupt bit
{
//Uart_Printf("Stylus Up Interrupt~!\n");

break; //if Stylus is up(1) state
}
}

//Uart_Printf("count=%03d XP=%04d, YP=%04d\n", TouchPanelCnt++, TPxyLocation.x, TPxyLocation.y); //X-position Conversion data
OSMboxPost(TP_m_box,(void*)1);
rADCDLY=saveAdcdly;
rADCTSC=rADCTSC&~(1<<8); // Detect stylus Down interrupt signal.
rSUBSRCPND|=BIT_SUB_TC;
rINTSUBMSK &=~(BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
void Test_Touchpanel(void)
{
//OSPrintf("ADC touch screen test\n");
//OSPrintf("[1] calibration touch screen \n");
// OSPrintf("Please touch the location of left top \n");
//ts_status = TS_JUSTIFY_LEFTTOP;

rADCDLY=50000; //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms
rADCCON=(1<<14) | (ADCPRS<<6);//| (0<<3) | (0<<2) | (0<<1) | (0);
//ADCPRS En, ADCPRS Value
rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En

// pISR_ADC = (uint32)AdcTsAuto_Handler;
pISR_ADC = (int)AdcTsAuto;
rINTMSK &= ~BIT_ADC; //ADC Touch Screen Mask bit clear
rINTSUBMSK &= ~(BIT_SUB_TC);
}


谁能帮我看看这段代码有问题麽!
...全文
149 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
mygod0218 2010-04-15
  • 打赏
  • 举报
回复
谢谢各位的关注,跟电压有点关系,呵呵!
COPPERLIJIAN 2010-04-13
  • 打赏
  • 举报
回复
楼主 ARM 开发板在哪里买的?
bobo364 2010-04-13
  • 打赏
  • 举报
回复
代码我觉得没问题,也不是很复杂,估计出了控制的问题,也就是说控制的数值,比如0x8000这里面是不是不对,其实嵌入式,难的反而是理解控制的参数,用的c语言反而是最简单的
不知名小ITer 2010-04-13
  • 打赏
  • 举报
回复
友情帮顶..了解不多..
十八道胡同 2010-04-13
  • 打赏
  • 举报
回复
帮顶。
lucasma.eth 2010-04-13
  • 打赏
  • 举报
回复
什么平台都没有说清楚. 这种东西跟硬件是有关的.

LZ还是去wince版问一下吧
kevinyujm 2010-04-13
  • 打赏
  • 举报
回复
嵌入式的问题往往需要结合硬件来调试。
你有用标准的程序测试过这个触摸屏吗。
soon 2010-04-12
  • 打赏
  • 举报
回复
楼主啊,还是自己看看吧,这样才能变为自己的东西。我也在学ARM,说不一定我们用的开发板是一样的。
把原来的注释去掉,自己看懂了再注释。然后再自己动手写一个,这样比你看几天的LCD控制还难,

69,381

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧