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

📄 tsp_test.c

📁 tsp_test为ucos中tsp的测试代码。运行在2410的板子上
💻 C
字号:
/*********************************************************************************************
* File:	tsp_test.c
* Author:	embest
* Desc:	Touch Screen Test
* History:	
*			W.W.Zhang, Programming modify, May,25, 2005
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/*                                     include files	                                    */
/*------------------------------------------------------------------------------------------*/
#include <string.h>
#include "2410lib.h"
#include "tsp_test.h"
#include "def.h"
#include "lcd_init.h"
/*------------------------------------------------------------------------------------------*/
/*                                     constants define	                                    */
/*------------------------------------------------------------------------------------------*/
#define ADCPRS 39
int nSampleNo=5;
#define YMAX 145
#define YMIN 25
#define XMAX 905
#define XMIN 40
#define RED 0xe0
//表示检测到的电压值
int xcp = 0;
int ycp = 0;

//表示实际的坐标
int x_p = 0;
int y_p = 0;
extern void isrADC(void);				// touch screen interrupt entry point, call_int.s


/*********************************************************************************************
* name:		tsp_int
* func:		Touch screen interrupt handler (ADC)
* para:		none
* ret:		none
* modify:	R.X.Huang, March 12, 2005
* comment:		
*********************************************************************************************/
void tsp_int(void)
{
    int i;
	//UINT32T szPos[40];		
	rINTSUBMSK  |=  (BIT_SUB_ADC | BIT_SUB_TC);// Mask sub interrupt (ADC and TC)
	
	
	
    // TC(Touch screen Control) Interrupt	
	if( rADCTSC & 0x100)
	{
		uart_printf(" 触摸屏松开\n\n\n");
		rADCTSC&=0xff;							// Set stylus down interrupt
	}
	else
	{
		uart_printf(" 触摸屏被按下\n");
	//	szPos[30] = g_nPosX;
	//	szPos[34] = g_nPosY;
				
		// <X-Position Read>
		//Hi-Z,AIN5,GND,Ext vlt,Pullup Dis,Normal,X-position
		rADCTSC = (0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(0<<3)|(0<<2)|(1);
		//adc input ain5
		rADCCON = (1<<14)|(39<<6)|(5<<3)|(0<<2)|(1<<1)|(0);
		rADCDAT0;
		delay(10);
		for(i = 0; i<nSampleNo; i++)
		{
			while(!(0x8000 & rADCCON));			// Check ECFLG
			xcp += (0x3ff & rADCDAT0);
			//g_nPosX += szPos[i];
		}
		xcp = xcp/nSampleNo;
		//uart_printf(" X-Posion[AIN5] is %04d\n", g_nPosX);

		// <Y-Position Read>
		//GND,Ext vlt,Hi-Z,AIN7,Pullup Dis,Normal,Y-position
		rADCTSC = (0<<8)|(1<<7)|(0<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(2);
		//adc input ain7
		rADCCON = (1<<14)|(39<<6)|(7<<3)|(0<<2)|(1<<1)|(0);
		rADCDAT1;
		delay(10);		
		for(i = 0; i<nSampleNo; i++)
		{
			while(!(0x8000 & rADCCON));			// Check ECFLG
			ycp = (0x3ff & rADCDAT1);
			//g_nPosY += szPos[i];
			
		}
		ycp = ycp/nSampleNo;
		//uart_printf(" Y-Posion[AIN7] is %04d\n", g_nPosY);
		
		//GND,AIN,Hi-z,AIN,Pullup En,Normal,Waiting mode
    	rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
    	
    	//坐标转换
    	//横坐标
		x_p = (xcp - XMIN)*320/(XMAX - XMIN);
		//纵坐标
		y_p = (YMAX - ycp)*240/(YMAX - YMIN);
		uart_printf("当前的电压值是(xcp: %d, ycp: %d)\n", xcp, ycp);
		uart_printf("当前的坐标是(%d, %d)\n", x_p, y_p);	
		//uart_printf("将点(%d,%d)画成红色\n",x_p,y_p);
		PutPixel(x_p,y_p,RED);
	}
#ifdef BOARDTEST
	sprintf(&szPos, "(X1,Y1):(%d,%d)",szPos[30],szPos[34]);
	print_lcd(195,170,0x20,&szPos);
	sprintf(&szPos, "(X2,Y2):(%d,%d)",g_nPosX,g_nPosY);
	print_lcd(195,178,0x1c,&szPos);
#endif		
	rSUBSRCPND |= BIT_SUB_TC;		
	rINTSUBMSK = ~(BIT_SUB_TC);			// Unmask sub interrupt (TC)     
	ClearPending(BIT_ADC);

}
			
/*********************************************************************************************
* name:		tsp_test
* func:		
* para:		none
* ret:		none
* modify:	R.X.Huang, March 12, 2005
* comment:		
*********************************************************************************************/
void tsp_test(void)
{
  	uart_printf(" Touch Screen Test Example.\n");
    rADCDLY = 50000;						// ADC Start or Interval Delay
 	rGPGCON |= 0xFF000000;
	rGPGUP = 0xFFFF;

	rADCTSC = (0<<8) | (1<<7) | (1<<6) | (0<<5) | (1<<4) | (0<<3) | (1<<2) | (0);
	//auto sequential x/y position conversion,no operation,	XP pull-up
	
    rADCCON  =  (1<<14) | (ADCPRS<<6) | (5<<3) | (0<<2) | (0<<1) | (0);
	// Enable Prescaler,Prescaler,AIN7/5 fix,Normal,Disable read start,No operation	
	
	rADCTSC = (0<<8) | (1<<7) | (1<<6) | (0<<5) | (1<<4) | (0<<3) | (0<<2) | (3);
	//YM:GND,YP:AIN5,XM:Hi-z,XP:external voltage,XP pullup En,AUTO sequential,Waiting for interrupt mode
	delay(100);
	pISR_ADC = (unsigned)isrADC;			// pISR_ADC
	rINTMSK &= ~(BIT_ADC);
	rINTSUBMSK = ~(BIT_SUB_TC);
	g_nKeyPress = 1;
	while(g_nKeyPress==1)					// only for board test to exit
	{
		if(uart_getkey()) return;			// or press any key to exit
	}
	
	rINTSUBMSK |= BIT_SUB_TC;
	rINTMSK |= BIT_ADC;
	uart_printf(" end.\n");
}
/*
//横坐标
x_p = (xcp - XMIN)*320/(XMAX - XMIN);
//纵坐标
y_p = (YMAX - ycp)*240/(YMAX - YMIN);
*/

⌨️ 快捷键说明

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