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

📄 tp.c

📁 一个触摸屏DRIVER
💻 C
字号:
/*********************************************************************************************
* File:	tp.c
* Author:	embest	
* Desc:	LCD touch screen control function
* History:	
*********************************************************************************************/

/*--- include files ---*/
#include <string.h>
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "tp.h"
#include "lcd.h"

/*--- global  variables ---*/
volatile unsigned int  UserTouch=0;

void TS_Test(void);
void TS_init(void);
void TSInt(void);
void TS_close(void);
void Lcd_TC(void);


/*--- function declare ---*/
void TSInt(void) __attribute__ ((interrupt ("IRQ")));

void TS_Test(void)
{
		Uart_Printf("\n\rEmbest 44B0X Evaluation Board(S3CEV40)");
		Uart_Printf("\n\rLCD TouchScreen Test Example(please touch LCD screen)\n");
		Uart_Printf("\n\rpress any key to exit...\n");
		Lcd_TC();
		TS_init();	
		Uart_Getch();
		TS_close();
}
/*--- function code ---*/
/*********************************************************************************************
* name:		TSInt
* func:		TouchScreen interrupt handler function
* para:		none
* ret:		none
* modify:
* comment:		
********************************************************************************************/
void TSInt(void)
{
    int   i;
    ULONG Pt[6];
    
    rI_ISPC = BIT_EINT2;			// clear pending_bit
	
	Uart_Printf("\n\rUser touch value is :\n");
	//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
    //  0		1	    0          1
	rPDATE = 0x58;
	// <X-Position Read>
	rADCCON = 0x1<<2;				// AIN1
	DelayTime(100);					// delay to set up the next channel
	// read x-position value
	for( i=0; i<5; i++ )
	{
		rADCCON |= 0x1;				// Start X-position A/D conversion
	    while( rADCCON & 0x1 );		// Check if Enable_start is low
    	while( !(rADCCON & 0x40) );	// Check ECFLG
	    Pt[i] = (0x3ff&rADCDAT);
	}
	// read X-position average value
	Pt[5] = (Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
	Uart_Printf("X-Posion is %04d", Pt[5]);

    // <Y-Position Read>
    //TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
    //  1		0	      1          0
	rPDATE = 0xa8;
	rADCCON = 0x0<<2;				// AIN0
	DelayTime(100);					// delay to set up the next channel
	for( i=0; i<5; i++ )
	{
    	rADCCON |= 0x1;				// Start X-position conversion
	    while( rADCCON & 0x1 );		// Check if Enable_start is low
    	while( !(rADCCON & 0x40) );	// Check ECFLG
	    Pt[i] = (0x3ff&rADCDAT);
	}
	// read Y-position average value
	Pt[5] = (Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
	Uart_Printf("Y-Posion is %04d\n", Pt[5]);
	
	DelayTime(100);					// delay to set up the next channel	
	rPDATE = 0xb8;					// should be enabled	

    rI_ISPC = BIT_EINT2;			// clear pending_bit
	DelayTime(100);					// delay to set up the next channel 
	UserTouch = 1;
}
			
/*********************************************************************************************
* name:		TS_init
* func:		initialize TouchScreen
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void TS_init(void)
{
    /* enable interrupt */
	rINTMOD=0x0;
	rINTCON=0x1;
	rI_ISPC |= BIT_ZDMA0;	    //clear pending
    rI_ISPC |= BIT_EINT2;		// clear pending_bit
	
    //TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
    //  0		1	 1          0
    rPUPE  = 0x0;	
    rPDATE = 0xb8;				// should be enabled	
    DelayTime(100);
    
    rEXTINT |= 0x200;			// falling edge trigger
    pISR_EINT2=(int)TSInt;		// set interrupt handler
    
    rCLKCON = 0x7ff8;			// enable clock
    rADCPSR = 0x4;				// A/D prescaler
    rINTMSK=~(BIT_GLOBAL|BIT_EINT2);
}

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

void Lcd_TC(void)
{
	/* initial LCD controller */
	Lcd_Init();
	/* clear screen */
	Lcd_Clr();
	Lcd_Active_Clr();
	/* draw rectangle pattern */ 
	Lcd_Draw_Box(0,0,80,60,15);
	Lcd_Draw_Box(80,0,160,60,15);
	Lcd_Draw_Box(160,0,240,60,15);
	Lcd_Draw_Box(240,0,320,60,15);
	Lcd_Draw_Box(0,60,80,120,15);
	Lcd_Draw_Box(80,60,160,120,15);
	Lcd_Draw_Box(160,60,240,120,15);
	Lcd_Draw_Box(240,60,320,120,15);
	Lcd_Draw_Box(0,120,80,180,15);
	Lcd_Draw_Box(80,120,160,180,15);
	Lcd_Draw_Box(160,120,240,180,15);
	Lcd_Draw_Box(240,120,320,180,15);
	Lcd_Draw_Box(0,180,80,240,15);
	Lcd_Draw_Box(80,180,160,240,15);
	Lcd_Draw_Box(160,180,240,240,15);
	Lcd_Draw_Box(240,180,320,240,15);
	/* output ASCII symbol */
	Lcd_DspAscII6x8(37,26,BLACK,"0");
	Lcd_DspAscII6x8(117,26,BLACK,"1");
	Lcd_DspAscII6x8(197,26,BLACK,"2");
	Lcd_DspAscII6x8(277,26,BLACK,"3");
	Lcd_DspAscII6x8(37,86,BLACK,"4");
	Lcd_DspAscII6x8(117,86,BLACK,"5");
	Lcd_DspAscII6x8(197,86,BLACK,"6");
	Lcd_DspAscII6x8(277,86,BLACK,"7");
	Lcd_DspAscII6x8(37,146,BLACK,"8");
	Lcd_DspAscII6x8(117,146,BLACK,"9");
	Lcd_DspAscII6x8(197,146,BLACK,"A");
	Lcd_DspAscII6x8(277,146,BLACK,"B");
	Lcd_DspAscII6x8(37,206,BLACK,"C");
	Lcd_DspAscII6x8(117,206,BLACK,"D");
	Lcd_DspAscII6x8(197,206,BLACK,"E");
	Lcd_DspAscII6x8(277,206,BLACK,"F");
	Lcd_Dma_Trans();
	Delay(8000);
}

⌨️ 快捷键说明

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