⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 这是一个在ADS下编译通过的源码
💻 C
字号:

#include "../inc/lib.h"
#include <stdio.h>
#include "../inc/tchScr.h"
#include "../uhal/uhal.h"
#pragma import(__use_no_semihosting_swi)  // ensure no functions that use semihosting 

#define ADS7843_PIN_PEN	(1<<5)//取中断信号
#define GPFDAT (*(volatile unsigned *)0x56000054)
#define TCHSCR_IsPenNotDown		(GPFDAT&ADS7843_PIN_PEN)//触摸笔中断

//获得触摸点坐标并返回触摸动作
int TchScr_GetOSXY(int *x, int *y)
{
	static int mode=0;
	static int oldx,oldy;
	int i,j;
	for(;;){
		if((mode!=TCHSCR_ACTION_DOWN) && (mode!=TCHSCR_ACTION_MOVE)){
			if(!TCHSCR_IsPenNotDown){//有触摸动作
				TchScr_GetScrXY(x, y);//得到触摸点坐标
				for(i=0;i<40;i++){
					if(TCHSCR_IsPenNotDown)//抬起
						break;
					hudelay(20);
				}
				if(i<40)
				{	//在规定的双击时间之内抬起,检测是不是及时按下
					for(i=0;i<60;i++)
					{
						if(!TCHSCR_IsPenNotDown)
						{
                            				if (i<10) 
							{
								i=60;break;
							}//如果单击后很短时间内按下,不视为双击
							mode=TCHSCR_ACTION_DBCLICK;
							for(j=0;j<40;j++) 
								hudelay(50);//检测到双击后延时,防止拖尾
                           		 		break;
						}
						hudelay(20);	
					}
					if(i==60)		//没有在规定的时间内按下
						mode=TCHSCR_ACTION_CLICK;
				}
				else
				{	//没有在规定的时间内抬起
					mode=TCHSCR_ACTION_DOWN;
				}
              		break;
			}
		}
		else
		{
			if(TCHSCR_IsPenNotDown){	//抬起
				mode=TCHSCR_ACTION_UP;
				*x=oldx;
				*y=oldy;
				return mode;
			}
			else
			{
				TchScr_GetScrXY(x, y);
				if(ABS(oldx-*x)>25 ||ABS( oldy-*y)>25)
				{//有移动动作
					mode=TCHSCR_ACTION_MOVE;
					break;
				}
			}
		}
		hudelay(10);
	}
	
	oldx=*x;
	oldy=*y;
	return mode;
}

/*************************************************
*TchScr_Test()-应用程序,当有触摸动作时调用
*函数TchScr_GetScrXY(x, y)获得(x,y)坐标
*************************************************/
void TchScr_Test()
{
	int x, y;
	int mode;
	Uart_Printf(0,"\nplease touch the screen\n");

	for(;;){
		mode=TchScr_GetOSXY(&x, &y);
		switch(mode){
		case TCHSCR_ACTION_CLICK:			
			Uart_Printf(0,"Action=click:x=%d,\ty=%d\n",x,y);
			break;
		case TCHSCR_ACTION_DBCLICK:
			Uart_Printf(0,"Action=double click:x=%d,\ty=%d\n",x,y);
			break;
		case TCHSCR_ACTION_DOWN:
			Uart_Printf(0,"Action=down:x=%d,\ty=%d\n",x,y);
			break;
		case TCHSCR_ACTION_UP:
			Uart_Printf(0,"Action=up:x=%d,\ty=%d\n",x,y);
			break;
		case TCHSCR_ACTION_MOVE:
			Uart_Printf(0,"Action=move:x=%d,\ty=%d\n",x,y);
			break;
		}
		hudelay(1000);
	}
	
}

/////////////////////////////////////////////////////
//                  Main function.                //
////////////////////////////////////////////////////
int main(void)
{
	ARMTargetInit();   //目标板初始化
	TchScr_init();     //触摸屏初始化
	TchScr_Test();     //应用程序
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -