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

📄 tsp_test.c

📁 基于ARM9芯片的一个简单的GPRS测试程序
💻 C
字号:
/*********************************************************************************************
* File:	tsp_test.c
* Author:	embest
* Desc:	Touch Screen Test
* History:	
*			H.T.Zhang, Programming modify, September 14, 2005
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/*                                     include files	                                    */
/*------------------------------------------------------------------------------------------*/
#include <string.h>
#include "2410lib.h"
#include "tsp_test.h"
#include "demo.h"
/*------------------------------------------------------------------------------------------*/
/*                                     constants define	                                    */
/*------------------------------------------------------------------------------------------*/
#define ADCPRS 39
int nSampleNo=5;
int j=0;
unsigned int  f_unPosX, f_unPosY;
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;
	char buf[50];
	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(" Stylus Up!!\n");
		rADCTSC&=0xff;							// Set stylus down interrupt
	}
	else
	{
		uart_printf(" Stylus Down!!\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
			szPos[i] = (0x3ff & rADCDAT0);
			g_nPosX += szPos[i];
		}
		g_nPosX = g_nPosX/nSampleNo;
		f_unPosX = g_nPosX;
		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
			szPos[i] = (0x3ff & rADCDAT1);
			g_nPosY += szPos[i];
			
		}
		g_nPosY = g_nPosY/nSampleNo;
		f_unPosY = g_nPosY;
		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);
    	sprintf(buf, "(X%d,Y%d):(%04d,%04d)",j,j,f_unPosX,f_unPosY);
		lcd_clr_rect(85,90+16*j,237,90+16*(j+1),BLUE);
		lcd_disp_ascii8x16(85,90+16*j,WHITE,(UINT8T *)buf);
		if (++j > 6) j = 0;
	}
		
	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");
	lcd_disp_ascii8x16(f_nDescCol,f_nDescRow,BLUE,"Touch Screen Test Example.");
	lcd_disp_ascii8x16(f_nDescCol,f_nDescRow+f_nPadRow,BLUE,"Please touch the screen:");
    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);
	uart_printf(" Press any key to exit...\n");	
	
	f_nKeyPress = 0;
	while(1)
	{
		if(f_nKeyPress) 
		{
			f_nKeyPress = 0;
			j = 0;
			break;// any key to exit.
		}
	}
	rINTSUBMSK |= BIT_SUB_TC;
	rINTMSK |= BIT_ADC;
	uart_printf(" end.\n");
}

⌨️ 快捷键说明

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