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

📄 int_tp.c

📁 The combined demo is dedicated for S1C33L05, so DMT33L05 should be used to load and run the demo. F
💻 C
字号:
/************************************************************************
 *										                                *
 *  Copyright (C) SHANGHAI EPSON CORP. 2001					            *
 *                                  									*
 *  File name: int_tp.c                        							*
 *    This is interrupt file.               							*
 *                                  									*
 *  Revision history                        							*
 *      2001.04.30  Stella      Start.          						*
 *                                  									*
 ************************************************************************/

//-----Include---------
#include "drv_tp.h"
#include "ros33.h"
#include "sysGUI.h"	

//----Global var-------
static unsigned char ucSmpCnt = 0;
static unsigned short usGetXData[TP_SAMPLE_TIMES];
static unsigned short usGetYData[TP_SAMPLE_TIMES];

//----Extern var------
extern T_TPCtlDev	stTPCtlDev;

/*******************************************************************************
 * Int_TP_TM
 *   Type   : void
 *   Ret val    :  none
 *   Argument   : void
 *   Function   : 16bit timer interrupt routine
 *******************************************************************************/
void Int_TP_TM(void){
	
    /* reset 16-bit timer comparsion B intterupt factor */
    /* stop 16timer 									*/
    *(volatile unsigned char*)REG_TM16_3_IFLAG |= 0x40;

	ucSmpCnt = 0;

    fnTP_CtlP(TPCTL_SCANY);

     /*reset counter*/
    *(volatile unsigned char*)REG_TM16_3_CTL |= 0x2;

    /* start & end channel AD3*/
    *(volatile unsigned char*)0x40243 = 0x18|0x03;

    /* software trigger */
    *(volatile unsigned char *)0x40244 |=0x2;

    /* enable A/D */
    *(volatile unsigned char*)0x40244|=0x4;
    
    /* enable A/D interrupt */
    *(volatile unsigned char*)0x40277|=0x1;

    /* reset port input 4 interrupt flag*/
    *(volatile unsigned char*)0x40287=0x4;

}

/*******************************************************************************
 * Int_TP_K
 *   Type : void
 *   Ret val :  none
 *   Argument : void
 *   Function : input interrupt for ad
 *******************************************************************************/
void Int_TP_K(void){

    /* reset port input 4 interrupt flag*/
    *(volatile unsigned char*)0x40287=0x4;

    /* port input 4 interrupt disable*/
    *(volatile unsigned char*)0x40277&=0xfb;

   /* reset 16-bit timer comparsion B intterupt factor */
    *(volatile unsigned char*)REG_TM16_3_IFLAG |= 0x40;

    /* 16-bit timer comparison B interrupt enable */
    *(volatile unsigned char*)REG_TM16_3_IMASK |= 0x40;

    /* RUN_16TIMER4*/
    *(volatile unsigned char *)REG_TM16_3_CTL |= 0x01;
}


/*******************************************************************************
 * Int_TP_ADC
 *   Type : void
 *   Ret val :  none
 *   Argument : void
 *   Function : AD interruptfor AD conversion
 *      if x,y cnt both >sample times  A/D enable , A/D interrupt diable, A/D stop, PENGET
 *      else A/D enable, A/D interrupt enable, trigger A/D,PENKEEP
 *******************************************************************************/
void Int_TP_ADC(void){

	unsigned short	usSmpData;			
  	unsigned char	ucSmpErr, ucSmpDir;
  	int	iWaitCnt;
   	
   	ent_int();
   	asm("pushn %r15");	//ent_int only save limited reg
   
    /* reset interrupt flag*/
    *(volatile unsigned char*)0x40287=0x1;
    /*stop A/D convert*/
    *(volatile unsigned char*)0x40244&=0xfd;
    /* disable A/D interrupt  */
    *(volatile unsigned char*)0x40277&=0xfe;

    usSmpData = *(volatile unsigned short*)0x40240;
   	
   	if(ucSmpCnt < TP_SAMPLE_TIMES){		//sample one dot
   	
//		ucSmpErr = (*(volatile unsigned char*)0x40244)& 0x1;
// 		if(ucSmpErr)		// overwrite error
   			
   		ucSmpDir = (*(volatile unsigned char*) 0x300020) & 0x04;
   		if(ucSmpDir){		// Sample Y dir
   			usGetYData[ucSmpCnt++] = usSmpData;
   			if(ucSmpCnt >= TP_SAMPLE_TIMES){ //change sample dir
   				ucSmpCnt = 0;
   				fnTP_CtlP(TPCTL_SCANX);
   				// wait
   				for(iWaitCnt =0; iWaitCnt<0x400; iWaitCnt++)
   					asm("nop");
   				
   				/* start & end channel AD2*/
			 	*(volatile unsigned char*)0x40243=0x10|0x02;
   			}	
   		}
   		else{				// Sample X dir
   			usGetXData[ucSmpCnt++] = usSmpData;
   			if(ucSmpCnt >= TP_SAMPLE_TIMES){ //change sample dir
   				fnTP_CtlP(TPCTL_SCANY);
				//wait
				for(iWaitCnt=0; iWaitCnt<100; iWaitCnt++)
					asm("nop");
				
			 	/* start & end channel AD3*/
				*(volatile unsigned char*)0x40243=0x18|0x03;
   			}	
   		}
   	}
	else{	// finish sample one dot
		if(fnTP_CalAvg(usGetXData, &stTPCtlDev.usADC_X) \
				&& fnTP_CalAvg(usGetYData, &stTPCtlDev.usADC_Y)){
			stTPCtlDev.ucStatus = TP_STATUS_PENDOWN;
			if(stTPCtlDev.ucStage == TP_STAGE_SAMPL)
				iset_flg( GUI_EVENTID,0x01 );
		}	
		*(volatile unsigned char*)0x40244&=0xfb;	// disable ADC
		ucSmpCnt = 0;
		asm("popn %r15");
		ret_int();
	}

	*(volatile unsigned char*)0x40244&=0xfe;	//reset overwrite flag
	*(volatile unsigned char*)0x40277|=0x01;	//enabel adc
	*(volatile unsigned char*)0x40244|=0x02;	//triger
	
 	asm("popn %r15");
 	ret_int();
}

/*------------ End of this file -----------------------*/

⌨️ 快捷键说明

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