//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include "delay.h"
#define BEEP_ON PRT5DR |=0X02
#define BEEP_OFF PRT5DR &=0XFD;
BYTE Speed[]=
{
0,0,0,0,0,0
};
BYTE Resolution[]=
{
14,14,14,14,14,14
};
BYTE RefValue[]=
{
2,2,2,2,2,2
};
//98,98,105,84,90,78
BYTE FingerThreshold[]=
{
93,93,100,79,85,70
};
BYTE SensorMap[]=
{
0x01,0x02,0x04,0x08,0x10,0x20
};
BYTE SensorSta;
struct I2C_REG
{
WORD RawCount[6];
WORD BaseLine[6];
BYTE Sta;
}my_i2c;
void ScanAndLightLED(void );
void Led_Init(void );
void BEEP(void );
void main(void)
{
BYTE i;
M8C_EnableGInt;
EzI2Cs_SetRamBuffer(sizeof (my_i2c),0,(BYTE *)(&my_i2c));
EzI2Cs_Start();
Led_Init();
LED7_On();
CSD_Start();
for (i=0;i<6;i++)
{
CSD_SetRefValue(RefValue);
CSD_SetScanMode(Speed,Resolution);
CSD_baBtnFThreshold=FingerThreshold;
CSD_InitializeSensorBaseline(i);
}
while (1)
{
for (i=0;i<6;i++)
{
CSD_SetRefValue(RefValue);
CSD_SetScanMode(Speed,Resolution);
CSD_ScanSensor(i);
}
CSD_UpdateAllBaselines();
if (CSD_bIsAnySensorActive())
{
SensorSta=CSD_baSnsOnMask[0];
ScanAndLightLED();
}
//#ifdef DEBUG
my_i2c.Sta=CSD_baSnsOnMask[0];
for (i=0;i<6;i++)
{
my_i2c.BaseLine=CSD_waSnsBaseline;
my_i2c.RawCount=CSD_waSnsResult;
}
//#endif
//ScanAndLightLED();
}
}
void Led_Init(void )
{
LED1_Start();
LED2_Start();
LED3_Start();
LED4_Start();
LED5_Start();
LED6_Start();
LED7_Start();
}
void ScanAndLightLED(void)
{
static BYTE Step=0;
switch (Step)
{
case 0:if (SensorSta==SensorMap[Step]){ LED1_On(); Step++;}break;
case 1:if (SensorSta==SensorMap[Step]){ LED2_On(); Step++;}break;
case 2:if (SensorSta==SensorMap[Step]){ LED3_On(); Step++;}break;
case 3:if (SensorSta==SensorMap[Step]){ LED4_On(); Step++;}break;
case 4:if (SensorSta==SensorMap[Step]){ LED5_On(); Step++;}break;
case 5:if (SensorSta==SensorMap[Step]){ LED6_On();}break;
}
}
void BEEP(void )
{
BEEP_ON;
Delay50uTimes(6);
BEEP_OFF;
Delay50uTimes(6);
BEEP_ON;
Delay50uTimes(6);
BEEP_OFF;
Delay50uTimes(6);
BEEP_ON;
Delay50uTimes(6);
BEEP_OFF;
Delay50uTimes(6);
}
你可以按照这个改一下,经验有限,也是摸索着前进。刚接触不久。
|