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

📄 touchpanel.c

📁 基于S3C2440开发板mini2440的俄罗斯方块程序
💻 C
字号:
/*****************************************
  NAME: Touchpanel.c
  DESC: ADC & Touch screen test
  HISTORY:
  2003.09.23:Leon YH KIM: draft ver 1.0
 *****************************************/
#include "def.h"
#include "2440addr.h"
#include "2440lib.h"


#define REQCNT 30
#define ADCPRS 9	//YH 0627
#define LOOP 1
#define drag_in 899<=xdata&xdata<=930&ydata<=130&ydata>=0;

void __irq AdcTsAuto(void);

int count=0;
int count_1=0;
int chang=0;
int xdata=0, ydata=200;
int chang_1=0;
int x1=0;
int y1=0;
int x2=0;
int y2=0;
int pt=0;
int tt=20000;
int x,y;
signed int k=0;
int color[]={0x001f,0x07e0,0xf800,0xffe0,0xf81f,0x07ff};

void delay( )
{
   U32 i,tt=20000;
   for(;tt>0;tt--)
   {
     for(i=0;i<10000;i++){}
   }
}

void PanelClearing_Button(void)
   {
		Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x1f)  )  ;
    	Glib_FilledRectangle(55,140,85,170,0xf800);
    	Glib_FilledRectangle(15,250,45,280,0x001f);
    	Glib_FilledRectangle(75,230,77,300,color[k]);
    	Glib_FilledRectangle(0,0,10,10,0x001f);
    	
  //  	delay();
  		while(1)		//to check Pen-up state
			{
			 if(rSUBSRCPND & (BIT_SUB_TC))	//check if ADC is finished with interrupt bit
				 {
					//Uart_Printf("Stylus Up Interrupt~!\n");
					break;	//if Stylus is up(1) state
				}
			}	
    	Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x1f)  )  ;
   		Glib_FilledRectangle(50,145,80,175,0xf800);
   		Glib_FilledRectangle(15,250,45,280,0x001f);
   		Glib_FilledRectangle(75,230,77,300,color[k]);
   		Glib_FilledRectangle(0,0,10,10,0x001f);
   		
   		chang=1;
    }
    
void ColorSwitch_Button(void)
{
    	if(k>6)
    		k=-1;
    		k++;
    	Glib_FilledRectangle(15,250,45,280,(0x1f<<11) | (0x3f<<5) | (0x1f));
    	Glib_FilledRectangle(20,245,50,275,0x001f);
    	Glib_FilledRectangle(75,230,77,300,color[k]);
    	  		while(1)		//to check Pen-up state
			{
			 if(rSUBSRCPND & (BIT_SUB_TC))	//check if ADC is finished with interrupt bit
				 {
					//Uart_Printf("Stylus Up Interrupt~!\n");
					break;	//if Stylus is up(1) state
				}
			}
		Glib_FilledRectangle(20,245,50,275,(0x1f<<11) | (0x3f<<5) | (0x1f));
		Glib_FilledRectangle(15,250,45,280,0x001f);
		chang=1;
		Uart_Printf("First chang=%d\n",chang_1);
    }
    
void Fun_SwitchButton(void)
{
    	count_1++;
    	chang_1=1;
    	if(count_1!=1)
    		{
    			count_1=0;
    			chang_1=0;
    		}
    	Uart_Printf("Second chang=%d\n",chang_1);
    	Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x1f)  )  ;
    	while(1)		//to check Pen-up state
			{
			 if(rSUBSRCPND & (BIT_SUB_TC))	//check if ADC is finished with interrupt bit
			    {
					     //Uart_Printf("Stylus Up Interrupt~!\n");
				  break;	//if Stylus is up(1) state
			    }
			}
    }
void Block_Pant(void)
{
    	 
      		Glib_FilledRectangle(0,0,10,10,0x001f);
    		Glib_FilledRectangle(220,300,240,320,color[1]);
    		Glib_FilledRectangle(199,300,219,320,color[2]);
    		Glib_FilledRectangle(178,300,198,320,color[3]);
    		Glib_FilledRectangle(157,300,177,320,color[4]);
    		Glib_FilledRectangle(136,300,156,320,color[5]);
    		Glib_FilledRectangle(115,300,135,320,color[6]);
    		if(853<=ydata&ydata<=930&xdata<=155&xdata>=0)
    			k=1;
			if(778<=ydata&ydata<=854&xdata<=155&xdata>=0)
				k=2;
			if(710<=ydata&ydata<=777&xdata<=155&xdata>=0)
				k=3;
			if(640<=ydata&ydata<=709&xdata<=155&xdata>=0)
				k=4;
			if(570<=ydata&ydata<=639&xdata<=155&xdata>=0)	
				k=5;
			if(500<=ydata&ydata<=569&xdata<=155&xdata>=0)
				k=6;
			if(!pt)
			Glib_FilledRectangle(x1,y1,x2,y2,(0x1f<<11) | (0x3f<<5) | (0x1f));
			Glib_FilledRectangle(x+10,290-y,x-10,330-y,color[k]);
			x1=x+10;
			y1=290-y;
			x2=x-10;
			y2=330-y;
			chang=1;
			
    }
void Test_Touchpanel(void)
{
   
    
    Lcd_Tft_NEC35_Init1( );
    Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x1f)  )  ;
    Glib_FilledRectangle(50,145,80,175,0xf800);
    Glib_FilledRectangle(15,250,45,280,0x001f);
    Glib_FilledRectangle(75,230,77,300,color[k]);
    Glib_FilledRectangle(0,0,10,10,0x001f);
   
    rADCDLY=50000;                  //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms
    rADCCON=(1<<14)+(ADCPRS<<6);   //ADCPRS En, ADCPRS Value

    Uart_Printf("ADC touch screen test\n");

    rADCTSC=0xd3;  //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En

    pISR_ADC = (int)AdcTsAuto;
	rINTMSK=~BIT_ADC;       //ADC Touch Screen Mask bit clear
	rINTSUBMSK=~(BIT_SUB_TC);

	Uart_Printf("\nType any key to exit!!!\n");
	Uart_Printf("\nStylus Down, please...... \n");

	while(1)
	{
		delay();
		if((xdata>557)|(ydata<500))
		pt=1;
	}
	Uart_Getch();

	rINTSUBMSK|=BIT_SUB_TC;
	rINTMSK|=BIT_ADC;
	Uart_Printf("Touch Screen Test is Finished!!!\n");

}


void __irq AdcTsAuto(void)
{
	int i;
	U32 saveAdcdly;
	
    if(rADCDAT0&0x8000)
    {
		//Uart_Printf("\nStylus Up!!\n");
		rADCTSC&=0xff;	// Set stylus down interrupt bit
    }
    //else 
		//Uart_Printf("\nStylus Down!!\n");

	rADCTSC=(1<<3)|(1<<2);         //Pull-up disable, Seq. X,Y postion measure.
	saveAdcdly=rADCDLY;
	rADCTSC |=0xd3;
	rADCDLY=40000;                 //Normal conversion mode delay about (1/50M)*40000=0.8ms

	rADCCON|=0x1;                   //start ADC

		while(rADCCON & 0x1);		//check if Enable_start is low
		while(!(rADCCON & 0x8000));        //check if EC(End of Conversion) flag is high, This line is necessary~!!
		
            while(!(rSRCPND & (BIT_ADC)));  //check if ADC is finished with interrupt bit

            xdata=(rADCDAT0&0x3ff);
            ydata=(rADCDAT1&0x3ff);

	 //YH 0627, To check Stylus Up Interrupt.
	 rSUBSRCPND|=BIT_SUB_TC;
	 ClearPending(BIT_ADC);
	 rINTSUBMSK=~(BIT_SUB_TC);
	 rINTMSK=~(BIT_ADC);
			 
	 rADCTSC =0xd3;    //Waiting for interrupt
	 

	

    Uart_Printf(" XP=%04d, YP=%04d\n" , xdata, ydata);    //X-position Conversion data            

	y=(xdata-95)*320/830;
	x=(ydata-95)*240/825;
	
	if((470<=xdata&xdata<=554&ydata<=370&ydata>=270)&!chang_1)   //Panel clearing button
		PanelClearing_Button();
		
    if((204<=xdata&xdata<=280&ydata<=250&ydata>=150)&!chang_1)
    	ColorSwitch_Button();
    	
    if(899<=xdata&xdata<=930&ydata<=130&ydata>=0)
    	Fun_SwitchButton();
    if(chang_1)
    	Block_Pant();
    	
    if(!chang)
	PutPixel(x,320-y,color[k]);
//	{ 	if(!pt)
//		Glib_FilledRectangle(x1,y1,x2,y2,(0x1f<<11) | (0x3f<<5) | (0x1f));
//		PutPixel(x,320-y,color[k]);
//		x1=x+20;
//		y1=300-y;
//		x2=x-20;
//		y2=340-y;
//	}
	else chang=0;
	rADCDLY=saveAdcdly; 
	rADCTSC=rADCTSC&~(1<<8); // Detect stylus Down interrupt signal.
    rSUBSRCPND|=BIT_SUB_TC;
    rINTSUBMSK=~(BIT_SUB_TC);	// Unmask sub interrupt (TC)     
    ClearPending(BIT_ADC);
    rINTMSK=~(BIT_ADC);
    pt=0;
    tt=2000;
}

⌨️ 快捷键说明

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