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

📄 tchscr.c

📁 三星arm的资料与源码
💻 C
字号:
#include "..\inc\44b.h"#include "..\inc\LCD320.h"#include "..\inc\tchScr.h"#include "..\inc\flash.h"#include "..\inc\file.h"#define ADS7843_CMD_X	(ADS7843_CTRL_START|ADS7843_GET_X|ADS7843_CTRL_12MODE|ADS7843_CTRL_DFR|ADS7843_CTRL_ENPWD)#define ADS7843_CMD_Y	(ADS7843_CTRL_START|ADS7843_GET_Y|ADS7843_CTRL_12MODE|ADS7843_CTRL_DFR|ADS7843_CTRL_ENPWD)#define ABS(a)		((a)>=0?(a):(-(a)))int TchScr_Xmax=1840,TchScr_Xmin=176,	TchScr_Ymax=195,TchScr_Ymin=1910;U8 sysCONFIG[]={'C','O','N','F','I','G',' ', ' ','S','Y','S'};U32 tx_tmpbuf[16*1024/4];void LoadAxisMax(){	U32 root_location;	root_location=find_file(sysCONFIG);		//get the file first cluster//	current_block=root_buf[root_location][27]*256+root_buf[root_location][26];		if(root_location==FILE_NO_FOUND){		Uart_Printf("\nConFig.sys no found!");		LCD_printf("ConFig.sys no found!\n");		return;	}	else	{		Uart_Printf("\nLoading ConFig.sys...");		LCD_printf("Loading ConFig.sys...\n");		read_file((U8*)tx_tmpbuf);		TchScr_Xmax=tx_tmpbuf[0];		TchScr_Xmin=tx_tmpbuf[1];		TchScr_Ymax=tx_tmpbuf[2];		TchScr_Ymin=tx_tmpbuf[3];		if(TchScr_Xmax==TchScr_Xmin || TchScr_Ymax==TchScr_Ymin){			TchScr_Xmax=1840;			TchScr_Xmin=176;			TchScr_Ymax=195;			TchScr_Ymin=1910;			Uart_Printf("\nerror ConFig.sys data!");			LCD_printf("error ConFig.sys data!\n");			return;		}		Uart_Printf("\nLoad ConFig.sys OK!\n");		LCD_printf("Load ConFig.sys OK!\n");	}}void TchScr_init(){	/*7				6		5					4				3		2			1:0			*/	/*Internal clock,MSB mode,Transmit/Receive mode,falling edge clock,No action,Non hand-shaking mode,SIO interrupt mode*/	/*0				0			1				0				0			0		01*/	rSIOCON=0x21;//0x31;	rSBRDR=15;//15;//band rate = 60MHz/2/(15+1)=1.875MHz	rIVTCNT=7;//7;//Intervals=60MHz/4/(7+1)=1.875MHz	LoadAxisMax();}void TchScr_GetScrXY(int *x, int *y, U8 bCal){	unsigned int temp;	rPDATC&=~ADS7843_PIN_CS;	SendSIOData(ADS7843_CMD_X);	SendSIOData(0);	temp=ReadSIOData();	SendSIOData(ADS7843_CMD_X);	temp<<=8;	temp|=ReadSIOData();	*x=(temp>>4);	SendSIOData(0);	temp=ReadSIOData();	SendSIOData(ADS7843_CMD_X);	temp<<=8;	temp|=ReadSIOData();	*x+=(temp>>4);	SendSIOData(0);	temp=ReadSIOData();	SendSIOData(ADS7843_CMD_X);	temp<<=8;	temp|=ReadSIOData();	*x+=(temp>>4);	SendSIOData(0);	temp=ReadSIOData();	SendSIOData(ADS7843_CMD_Y);	temp<<=8;	temp|=ReadSIOData();	*x+=(temp>>4);	*x>>=2;		//x=x/4;		SendSIOData(0);	temp=ReadSIOData();	SendSIOData(ADS7843_CMD_Y);	temp<<=8;	temp|=ReadSIOData();	*y=(temp>>4);	SendSIOData(0);	temp=ReadSIOData();	SendSIOData(ADS7843_CMD_Y);	temp<<=8;	temp|=ReadSIOData();	*y+=(temp>>4);		SendSIOData(0);	temp=ReadSIOData();	SendSIOData(ADS7843_CMD_Y);	temp<<=8;	temp|=ReadSIOData();	*y+=(temp>>4);	SendSIOData(0);	temp=ReadSIOData();	SendSIOData(0);	temp<<=8;	temp|=ReadSIOData();	*y+=(temp>>4);	*y>>=2;		//y=y/4;	rPDATC|=ADS7843_PIN_CS;	if(bCal){		*x=(*x-TchScr_Xmin)*LCDWIDTH/(TchScr_Xmax-TchScr_Xmin);		*y=(*y-TchScr_Ymin)*LCDHEIGHT/(TchScr_Ymax-TchScr_Ymin);	}}void WaitForScrDown(int *x, int *y){	for(;;){		if(!(rPDATC&ADS7843_PIN_PEN)){//按下			Delay(50);			if(!(rPDATC&ADS7843_PIN_PEN)){//按下				TchScr_GetScrXY(x, y,FALSE);				while(!(rPDATC&ADS7843_PIN_PEN))					Delay(100);				return;			}		}	}}void SetTouchScr(){	int x,y;	U32 root_location;		Uart_Printf("\n");	Uart_Printf("please touch the any point.\n");	WaitForScrDown(&x,&y);	Uart_Printf("x=%d,y=%d.\n",x,y);	Uart_Printf("please touch the topleft point.\n");	WaitForScrDown(&TchScr_Xmin,&TchScr_Ymin);	Uart_Printf("x=%d,y=%d.\n",TchScr_Xmin,TchScr_Ymin);	Uart_Printf("please touch the bottomright point.\n");	WaitForScrDown(&TchScr_Xmax,&TchScr_Ymax);	Uart_Printf("x=%d,y=%d.\n",TchScr_Xmax,TchScr_Ymax);	Uart_Printf("Is set Touch Screen OK? y/n.\n");	if(Uart_Getch()!='y'){		Uart_Printf("Cancel Set Touch Screen.\n");		return;	}	//设置触摸屏最值	root_location=find_file(sysCONFIG);		//get the file first cluster//	current_block=root_buf[root_location][27]*256+root_buf[root_location][26];		if(root_location==FILE_NO_FOUND){		Uart_Printf("\nConFig.sys no found!");		LCD_printf("ConFig.sys no found!\n");		return;	}	else	{		int i;		for(i=0;i<16*1024/4;i++)			tx_tmpbuf[i]=0xffffffff;				tx_tmpbuf[0]=TchScr_Xmax;		tx_tmpbuf[1]=TchScr_Xmin;		tx_tmpbuf[2]=TchScr_Ymax;		tx_tmpbuf[3]=TchScr_Ymin;		Erase_Cluster(current_block);		write_file(TRUE, (U8*)tx_tmpbuf);		Uart_Printf("\nConFig.sys save OK!\n");	}	}U32 TchScr_GetOSXY(int *x, int *y){	static U32 mode=0;	static int oldx,oldy;	int i;	for(;;){		if(mode!=TCHSCR_ACTION_DOWN && mode!=TCHSCR_ACTION_MOVE){			if(!(rPDATC&ADS7843_PIN_PEN)){				TchScr_GetScrXY(x, y,TRUE);				for(i=0;i<20;i++){					if(rPDATC&ADS7843_PIN_PEN)						break;					Delay(100);				}				if(i<20){	//在规定的双击时间之内抬起,检测是不是及时按下					for(i=0;i<20;i++){						if(!(rPDATC&ADS7843_PIN_PEN)){							mode=TCHSCR_ACTION_DBCLICK;							break;						}						Delay(100);					}					if(i==20)		//没有在规定的时间内按下						mode=TCHSCR_ACTION_CLICK;				}				else{	//没有在规定的时间内抬起					mode=TCHSCR_ACTION_DOWN;				}				break;			}		}		else{			if(rPDATC&ADS7843_PIN_PEN){	//抬起				mode=TCHSCR_ACTION_UP;				*x=oldx;				*y=oldy;				return mode;			}			else{				TchScr_GetScrXY(x, y,TRUE);				if(ABS(oldx-*x)>4 ||ABS( oldy-*y)>4){					mode=TCHSCR_ACTION_MOVE;					break;				}			}		}		Delay(50);	}	oldx=*x;	oldy=*y;	return mode;}

⌨️ 快捷键说明

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