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

📄 ts.c

📁 s3c24a0固件测试代码 ? ? ? ? ?啊 
💻 C
字号:
/*****************************************
  NAME: ts.c
  DESC: S3C24A0 Touch Screen Test Code
  HISTORY:  2002.04.29:draft ver 0.0
 *****************************************/

#include <string.h>
#include "24a0addr.h"
#include "24a0lib.h"
#include "Ts.h"
#include "def.h"

void __irq TsAutoTest(void)
{
    unsigned int WHATIRQ=0;

    rINTSUBMSK|=(BIT_SUB_ADC|BIT_SUB_PENUP|BIT_SUB_PENDN);	// Mask sub interrupt (ADC, PENUP and PENDN) 

    WHATIRQ = (rSUBSRCPND>>17) & 0x3;

    switch(WHATIRQ)
    {
    case 1:
    case 3:
       rSUBSRCPND=BIT_SUB_PENUP|BIT_SUB_PENDN;//Clear Sub-Source Pending, PENUP
       Uart_Printf("\nStylus up!!\n"); 
       rINTSUBMSK=~(BIT_SUB_PENUP|BIT_SUB_PENDN|BIT_SUB_ADC);//Unmask Sub-Interrupt, PENUP
	break;
    case 2:
       rSUBSRCPND=BIT_SUB_PENDN;//Clear Sub-Source Pending, PENDN

      	rADCTSC=(0<<8)|(1<<3)|(1<<2)|(0);
	rADCCON|=0x1;// Start Auto conversion
	
	while(rADCCON & 0x1);//Check if Enable_start is low
	while(!(0x8000&rADCCON));//Check ECFLG
		
	
	rADCTSC=(0<<8)|(13<<4)|(0<<3)|(0<<2)|1;//for returning to X-position....
	rADCTSC=0xd3; //for waiting interruupt
	while(((rSUBSRCPND>>17)&0x02) !=0x2);
	rSUBSRCPND=BIT_SUB_PENDN|BIT_SUB_ADC;//Clear Sub-Source Pending, PENDN

       Uart_Printf("\nStylus down!!\n"); 
	Uart_Printf("X-Posion[AIN5] is %04d\n", (0x3ff&rADCDAX));
	Uart_Printf("Y-Posion[AIN7] is %04d\n\n", (0x3ff&rADCDAY));


	rINTSUBMSK=~(BIT_SUB_PENDN|BIT_SUB_PENUP|BIT_SUB_ADC);//Unmask Sub-Interrupt, PENDN
	break;
    default:
	break;
    }
 
//    ClearPending(BIT_ADC_PENUP_DOWN);
    rSRCPND=(1<<31);
    rINTPND=(1<<31);
}


void __irq TsNoiseTest(void)
{
    unsigned int WHATIRQ=0;

    rINTSUBMSK|=(BIT_SUB_PENUP|BIT_SUB_PENDN);	// Mask sub interrupt (ADC, PENUP and PENDN) 

    WHATIRQ = (rSUBSRCPND>>17) & 0x3;

    switch(WHATIRQ)
    {
    case 1:
	rSUBSRCPND=BIT_SUB_PENUP;	

	Uart_Printf("Stylus up!\n");
	break;
    case 2:
	rSUBSRCPND=BIT_SUB_PENDN;	
	
       rADCTSC=(0<<8)|(1<<3)|(1<<2)|(0);
	rADCCON|=0x1;// Start Auto conversion
	
	while(rADCCON & 0x1);//Check if Enable_start is low
	while(!(0x8000&rADCCON));//Check ECFLG
		
	rADCTSC=(0<<8)|(13<<4)|(0<<3)|(0<<2)|1;//for returning to X-position....
	rADCTSC=0xd3; //for waiting interruupt

	//Because of stopping unintended pendown interrupt
	while(((rSUBSRCPND>>17)&0x02) !=0x2);
	rSUBSRCPND=BIT_SUB_PENDN|BIT_SUB_ADC;//Clear Sub-Source Pending, PENDN

       Uart_Printf("Stylus down!\n"); 
	Uart_Printf("X-Posion[AIN5] is %04d\n", (0x3ff&rADCDAX));
	Uart_Printf("Y-Posion[AIN7] is %04d\n\n", (0x3ff&rADCDAY));
	break;	
    case 3:
       rSUBSRCPND=BIT_SUB_PENUP|BIT_SUB_PENDN;//Clear Sub-Source Pending, PENUP
       Uart_Printf("Stylus up & down!!\n"); 
	break;
    default:
	break;
    }
    rINTSUBMSK=~(BIT_SUB_PENUP|BIT_SUB_PENDN);//Unmask Sub-Interrupt, PENUP

    //Uart_Printf("rSUBSRCPND=%x\n",rSUBSRCPND);
 
//    ClearPending(BIT_ADC_PENUP_DOWN);
    rSRCPND=(1<<31);
    rINTPND=(1<<31);
}

void Ts_Auto(void)
{
    Uart_Printf("[Touch Screen Test.]\n");
    Uart_Printf("Auto X/Y position conversion mode test\n");

    rADCDLY=(1000);	// ADC Start or Interval Delay

    // Enable Prescaler,Prescaler,AIN5/7 fix,Normal,Disable read start,No operation
    rADCCON = (1<<14)|(ADCPRS<<6)|(0<<3)|(0<<2)|(0<<1)|0;	
    
    //rADCTSC=(0<<8)|(13<<4)|(0<<3)|(0<<2)|3;//tark, XP pullup En,Normal,Waiting for interrupt mode
    rADCTSC=0xd3;

    pISR_ADC_PENUP_DOWN=(unsigned)TsAutoTest;
    rINTMSK=~(BIT_ADC_PENUP_DOWN);
    rINTSUBMSK=~(BIT_SUB_ADC|BIT_SUB_PENUP|BIT_SUB_PENDN);

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

    rINTSUBMSK|=(BIT_SUB_ADC|BIT_SUB_PENUP|BIT_SUB_PENDN);
    rINTMSK|=BIT_ADC_PENUP_DOWN;
    Uart_Printf("[Touch Screen Test.]\n");
}


void Ts_Noise(void)
{
    int i;
    Uart_Printf("[Touch Screen Test.]\n");
    Uart_Printf("Pen Up & Down test\n");


    rALIVECON=0x1;
    Delay1us(0);//calibrating Dealy1us();
    //rADCDLY=(20000);	// ADC Start or Interval Delay

    rADCCON = (1<<14)|(ADCPRS<<6)|(0<<3)|(0<<2)|(0<<1)|0;	

    //code to escape invalid up/down state at initial time.
    rADCTSC=(0<<8)|(13<<4)|(0<<3)|(0<<2); //XP Pullup Enable, Normal
    Delay1us(5); //Low to High Transition time after setting Pull up is minimum 5us.
    rADCTSC|=0x3;//Waiting for interrupt mode

    pISR_ADC_PENUP_DOWN=(unsigned)TsNoiseTest;
    rINTMSK=~(BIT_ADC_PENUP_DOWN);
    rINTSUBMSK=~(BIT_SUB_PENUP|BIT_SUB_PENDN);

    Uart_Printf("Type any key to exit!!!\n");
    Uart_Printf("Stylus Down, please...... \n");
    Uart_Getch();

    rINTSUBMSK|=(BIT_SUB_PENUP|BIT_SUB_PENDN);
    rINTMSK|=BIT_ADC_PENUP_DOWN;
    Uart_Printf("[Touch Screen Test.]\n");
}

void Ts_PullUp(void)
{
    int i;
    Uart_Printf("[Touch Screen Test.]\n");
    Uart_Printf("Pen Up & Down test\n");

    
    //rADCDLY=(480);	// ADC Start or Interval Delay


    // Enable Prescaler,Prescaler,AIN5/7 fix,Normal,Disable read start,No operation
    rADCCON = (1<<14)|(ADCPRS<<6)|(7<<3)|(0<<2)|(0<<1)|0;	

    //rADCTSC=(0<<8)|(13<<4)|(0<<3)|(0<<2)|0;//tark, XP pullup En,Normal,Waiting for interrupt mode
    Uart_Printf("Press any key to set pull up\n");
    Uart_Getch();
    rADCTSC=(1<<3)|(1<<4);

	
    //rADCCON|=0x1;
    //while(rADCCON & 0x1);//Check if Enable_start is low
    //while(!(0x8000&rADCCON));//Check ECFLG
    


    for(i=0; i<100; i++) {    
    rADCCON|=0x1;// Start Auto conversion
	
    while(rADCCON & 0x1);//Check if Enable_start is low
    while(!(0x8000&rADCCON));//Check ECFLG

    Uart_Printf("%d\n", rADCDAX&0x3ff);
    	}		

    Uart_Getch();


    rADCTSC=(0<<8)|(13<<4)|(0<<3)|(0<<2)|1;//for returning to X-position....

    //Delay(100);
    //Uart_Printf("rSUBSRCPND=%x\n",rSUBSRCPND);
    pISR_ADC_PENUP_DOWN=(unsigned)TsNoiseTest;
    rINTMSK=~(BIT_ADC_PENUP_DOWN);
    rINTSUBMSK=~(BIT_SUB_PENUP|BIT_SUB_PENDN);

    //Uart_Printf("Type any key to exit!!!\n");
    //Uart_Printf("Stylus Down, please...... \n");
    Uart_Getch();

    rINTSUBMSK|=(BIT_SUB_PENUP|BIT_SUB_PENDN);
    rINTMSK|=BIT_ADC_PENUP_DOWN;
    Uart_Printf("[Touch Screen Test.]\n");
}			
    


⌨️ 快捷键说明

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