我没用过CY7C的,但是CY8C的我用过没问题;要开启定时器TIMER1中断;
demo:
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#pragma interrupt_handler Timer16_ISR
void Timer16_ISR(void);
void Timer_start(void);
struct I2C_Regs
{
//BYTE KeyValue;
int RawCount;
int BaseLine;
} MyI2C_Regs;
char Key_status=0;
char Press_Enable=0;
char Pulse_status=0;
int TimeCounter = 0;
int RawBuff[8]={0};
void main(void)
{
char i;
long int RawTotal;
// M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
// Insert your main routine code here.
EzI2Cs_SetRamBuffer(sizeof(MyI2C_Regs), 1, (BYTE *) &MyI2C_Regs);
M8C_EnableGInt ;
EzI2Cs_Start();
CSD_Start();
CSD_SetDefaultFingerThresholds() ;
CSD_InitializeBaselines() ;
LED_1_Start();
CSD_ScanAllSensors();
CSD_UpdateAllBaselines();
for(i=0;i<8;i++)
{
RawBuff[i] = CSD_waSnsResult[0];
}
while(1)
{
// EzI2Cs_Stop();
CSD_ScanAllSensors(); //scan all sensors in array (buttons and sliders)
RawTotal = 0;
for(i=0;i<8;i++)
{
//CSD_waSnsBaseline[i]=CSD_waSnsResult[i];
if(i==7)
RawBuff[i] = CSD_waSnsResult[0];
else
RawBuff[i] = RawBuff[i+1];
RawTotal += RawBuff[i];
}
CSD_waSnsResult[0] = RawTotal/8 ;
CSD_UpdateAllBaselines();
if (CSD_bIsAnySensorActive())
{
if(Press_Enable==0)
{
Press_Enable=1;
LED_1_On();
Timer_start();
}
}
else
{
Press_Enable=0;
LED_1_Off();
}
MyI2C_Regs.RawCount=CSD_waSnsResult[0];
MyI2C_Regs.BaseLine=CSD_waSnsBaseline[0];
}
}
void Timer_start(void)
{
Timer16_Start();
Timer16_EnableInt();
TimeCounter = 0;
}
void Timer_stop(void)
{
Timer16_Stop();
Timer16_DisableInt();
}
void Timer16_ISR(void)
{
TimeCounter ++;
if(TimeCounter >287)
{
Timer16_Stop();
Timer16_DisableInt();
LED_1_Off();
}
} |