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

📄 touchscreen.c

📁 Embest EudKit-II教学系统配Samsung S3C44B0处理器的部分测试程序。
💻 C
字号:
/*********************************************************************************************
* File:	touchscreen.c
* Author:	embest	
* Desc:	LCD touch screen control function
* History:	
*********************************************************************************************/
#include "44b.h"
#include "44blib.h"
#include "touchscreen.h"

/*------------------------------------------------------------------------------------------*/
/*	 								global variables					 				    */
/*------------------------------------------------------------------------------------------*/
unsigned int  f_unMaxX, f_unMaxY;
unsigned int  f_unMinX, f_unMinY;
unsigned int  f_unTouched;	
unsigned int  f_unPosX, f_unPosY;

/*********************************************************************************************
* name:		touchscreen_int
* func:		TouchScreen interrupt handler function
* para:		none
* ret:		none
* modify:
* comment:		
********************************************************************************************/
void touchscreen_test(void)
{
	unsigned int unX, unY;
	unsigned int unTmpX, unTmpY;

	touchscreen_init();
		
	uart_printf("Please touch LCD's left up corner:");
	f_unTouched = 0;
	while(f_unTouched == 0);
	uart_printf("left=%04d, up=%04d\n", f_unPosX, f_unPosY);
	unTmpX = f_unPosX;
	unTmpY = f_unPosY;
		
	uart_printf("Please touch LCD's right bottom corner:");
	f_unTouched = 0;
	while(f_unTouched == 0);
	uart_printf("right=%04d, bottom=%04d\n", f_unPosX, f_unPosY);
	f_unMaxX = f_unPosX>unTmpX? f_unPosX : unTmpX;
	f_unMaxY = f_unPosY>unTmpY? f_unPosY : unTmpY;
	f_unMinX = f_unPosX>unTmpX? unTmpX : f_unPosX;
	f_unMinY = f_unPosY>unTmpY? unTmpY : f_unPosY;

	for(;;)
	{
		f_unTouched = 0;
		while(f_unTouched == 0);
		//uart_printf("PosX=%04d, PosY=%04d\n", f_unPosX, f_unPosY);
		if(f_unPosX>f_unMaxX || f_unPosX<f_unMinX || f_unPosY>f_unMaxY || f_unPosY<f_unMinY)
			continue;
		unX = (320*(f_unPosX - f_unMinX))/(f_unMaxX - f_unMinX);
		unY = (240*(f_unPosY - f_unMinY))/(f_unMaxY - f_unMinY);
		uart_printf("X=%04d, Y=%04d\n", unX, unY);
	}

	while(1);		
}

/*********************************************************************************************
* name:		touchscreen_init
* func:		initialize TouchScreen
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void touchscreen_init(void)
{
#ifndef S3CEV40
	// TSPX(GPC1_Q4(-)) TSPY(GPC3_Q3(-)) TSMY(GPC0_Q2(-)) TSMX(GPC2_Q1(+)) 
	//          1               1                0                 1
	rPCONC = (rPCONC & 0xffffff00) | 0x55;
	rPUPC  = (rPUPE  & 0xfff0); 						// Pull up
	rPDATC = (rPDATC & 0xfff0 ) | 0xe;					// should be enabled
#else	
	// S3CEV40
	// TSPX(GPE4_Q4(+)) TSPY(GPE5_Q3(-)) TSMY(GPE6_Q2(+)) TSMX(GPE7_Q1(-))
    //       0               1                 1                0
	rPCONE = (rPCONE & 0x300ff) | 0x5500;
	rPUPE  = (rPUPE & 0xF);
	rPDATE = 0xb8;
#endif
	delay(100); 
    

    // set interrupt 
#ifndef S3CEV40
	rPUPG = (rPUPG & 0xFE) | 0x1;
    pISR_EINT0=(int)touchscreen_int;       				// set interrupt handler
    rEXTINT = (rEXTINT & 0x7FFFFFF0) | 0x2;           	// falling edge trigger
    rI_ISPC |= BIT_EINT0;            					// clear pending_bit
    rINTMSK =~(BIT_GLOBAL|BIT_EINT0);
#else
    pISR_EINT2=(int)touchscreen_int;       				// set interrupt handler
    rEXTINT = (rEXTINT & 0x7FFFF0FF) | 0x200;             // falling edge trigger
	rI_ISPC |= BIT_EINT2;            					// clear pending_bit
    rINTMSK =~(BIT_GLOBAL|BIT_EINT2);
#endif
    rCLKCON = (rCLKCON & 0x6FFF) | 0x1000;              // enable clock
    rADCPSR = 24;             							// A/D prescaler
}

/*********************************************************************************************
* name:		touchscreen_close
* func:		close TouchScreen
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void touchscreen_close(void)
{
	// Mask interrupt
	rINTMSK |=BIT_GLOBAL|BIT_EINT0;
	pISR_EINT0 = (int)NULL;
}

/*********************************************************************************************
* name:		touchscreen_int
* func:		TouchScreen interrupt handler function
* para:		none
* ret:		none
* modify:
* comment:		
********************************************************************************************/
void touchscreen_int(void)
{
    UINT32T 	unPointX[5], unPointY[6];
    UINT32T		unPosX, unPosY;
    int   		i;

#ifndef S3CEV40
	// <X-Position Read>
	// TSPX(GPC1_Q4(+)) TSPY(GPC3_Q3(-)) TSMY(GPC0_Q2(+)) TSMX(GPC2_Q1(-))
    //       0               1                 1                0
	rPDATC = (rPDATC & 0xfff0 ) | 0x9;
	rADCCON= 0x0014;										// AIN5
#else
	// TSPX(GPE4_Q4(+)) TSPY(GPE5_Q3(-)) TSMY(GPE6_Q2(+)) TSMX(GPE7_Q1(-))
    //       0               1                 1                0
	rPDATE =0x68;
	rADCCON=0x1<<2;											// AIN1
#endif	

	delay(100);	                							// delay to set up the next channel
	for(i=0; i<5; i++)
	{
		rADCCON |= 0x1;										// Start X-position A/D conversion
	    while(rADCCON & 0x1 == 1);							// Check if AD conversion starts
    	while((rADCCON & 0x40) == 0);						// Check end of AD conversion
	    unPointX[i] = (0x3ff&rADCDAT);
	}

	// read X-position average value
	unPosX = (unPointX[0]+unPointX[1]+unPointX[2]+unPointX[3]+unPointX[4])/5;
	f_unPosX = unPosX;

#ifndef S3CEV40
    // <Y-Position Read>
	// TSPX(GPC1_Q4(-)) TSPY(GPC3_Q3(+)) TSMY(GPC0_Q2(-)) TSMX(GPC2_Q1(+))
    //       1               0                 0                1
	rPDATC = (rPDATC & 0xfff0 ) | 0x6;
	rADCCON= 0x001C;		        						// AIN70
#else
	// TSPX(GPE4_Q4(-)) TSPY(GPE5_Q3(+)) TSMY(GPE6_Q2(-)) TSMX(GPE7_Q1(+))
    //       1               0                 0                1
	rPDATE =0x98;
	rADCCON=0x0<<2;		        							// AIN0
#endif	
	delay(100);	                							// delay to set up the next channel
	for(i=0; i<5; i++)
	{
    	rADCCON |= 0x1;             						// Start Y-position conversion
	    while(rADCCON & 0x1 == 1);     						// Check if AD conversion starts
    	while((rADCCON & 0x40) == 0); 						// Check end of AD conversion
	    unPointY[i] = (0x3ff&rADCDAT);
	}
	// read Y-position average value
	unPosY = (unPointY[0]+unPointY[1]+unPointY[2]+unPointY[3]+unPointY[4])/5;
	f_unPosY = unPosY;

//	uart_printf("X=%04d Y=%04d\n", unPosX, unPosY);

#ifndef S3CEV40
	rPDATC = (rPDATC & 0xfff0 ) | 0xe;						// should be enabled
#else
	rPDATE = 0xb8;                  						// should be enabled	
#endif	
	delay(1000);

	f_unTouched = 1;

#ifndef S3CEV40
    rI_ISPC |= BIT_EINT0;            						// clear pending_bit
#else
    rI_ISPC |= BIT_EINT2;            						// clear pending_bit
#endif    
}


⌨️ 快捷键说明

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