- »ý·Ö
- 3553
- ÏÂÔØ·Ö
- ·Ö
- ÍþÍû
- µã
- Ô´´±Ò
- µã
- ÏÂÔØ
- ´Î
- ÉÏ´«
- ´Î
- ×¢²áʱ¼ä
- 2014-11-13
- ¾«»ª
|
ÂíÉÏ×¢²á£¬»ñÈ¡ÔĶÁ¾«»ªÄÚÈݼ°ÏÂÔØÈ¨ÏÞ
ÄúÐèÒª µÇ¼ ²Å¿ÉÒÔÏÂÔØ»ò²é¿´£¬Ã»ÓÐÕʺţ¿×¢²á
x
Æß²½×ߣ¬
µÚÒ»²½£º¸øCS·Åµç£¬S3¿ª£¬
µÚ¶þ²½£ºËùÓпª¹Ø¹Ø±Õ£¬
µÚÈý²½£ºS2¿ªÆô£¬¸øCX³äµç¡£
µÚËIJ½£ºËùÓпª¹Ø¹Ø±Õ
µÚÎå²½£º¿ªÆôS1¸øCS³äµç
µÚÁù²½£ºËùÓпª¹Ø¹Ø±Õ
µÚÆß²½£ºS1ºÍS3¿ªÆô£¬¸øCXºÍCS·Åµç
ÖØ¸´ÉÏÃæµÄ7¸ö²½Ö裬ֱµ½CSµçѹµ½¸ßµçƽ£¨Óд¥ÃþÊ±ÖØ¸´´ÎÊý½«¼õÉÙ£©
ÔÚµÚÁù²½ºó²É¼¯µ½I/0¶Ë¿ÚµçƽÊÇ·ñ³¬¹ý·§Öµ¡£
void Configure_TSC(void)
{
RCC->AHBENR |= RCC_AHBENR_TSEN;
TSC->CR = TSC_CR_PGPSC_2 | TSC_CR_PGPSC_0 // fPGCLK = fHCLK/32
| TSC_CR_CTPH_0 | TSC_CR_CTPL_0 // pulse high = 2xtPGCLK,Master
| TSC_CR_MCV_2 | TSC_CR_MCV_1 // Max count value = 16383 pulses
| TSC_CR_TSCE; // Enable TSC
TSC->IOHCR &= (uint32_t)(~(TSC_IOHCR_G2_IO4 | TSC_IOHCR_G2_IO3)); // ĬÈÏʹÄÜ£¬È¥³ý²»ÒªµÄ¶Ë¿Ú
TSC->IER = TSC_IER_EOAIE; // ת»»ÏµÁнáÊøÖжÏ
TSC->IOSCR = TSC_IOSCR_G2_IO4; // ²ÉÑù¶Ë¿ÚµçÈݽÓÔÚ G2IO4ÉÏ
TSC->IOCCR = TSC_IOCCR_G2_IO3; // ´¥Ãþ°´¼üÉèÔÚG2IO3ÉÏ
TSC->IOGCSR |= TSC_IOGCSR_G2E; // ʹÄÜ×é2
NVIC_SetPriority(TSC_IRQn, 0);
NVIC_EnableIRQ(TSC_IRQn);
}
void TSC_IRQHandler(void)
{
if((TSC->ISR & TSC_ISR_EOAF) == TSC_ISR_EOAF) //ϵÁнáÊø·ñ
{
TSC->ICR = TSC_ICR_EOAIC; /* Clear flag */
AcquisitionValue = TSC->IOGXCR[1]; /* Get G2 counter value */
}
}
void Process(void)
{
static uint32 NumberOfCalibration=0;
uchar RefIndex=0;
static uchar RefIndexStatic=0;
static uint32 ReferenceTab[REFERENCE_TAB_SIZE];
if(AcquisitionValue) //ÓÐÊý¾Ýµ½À´
{
if(CalibrationDone) //ÊÇ·ñ½ÃÕýÍê³É
{
if((AcquisitionValue + THRESHOLD) < Reference) /* Touch detected */
{
Activities = 1;
}
else if(AcquisitionValue > (Reference + THRESHOLD))
{
Activities = 1;
CalibrationDone = 0; /* restart calibration */
Reference = 0; /* Reset reference */
}
else /* no touch detected */
{
if(ReferenceAdaptation)
{
ReferenceAdaptation=0;
RefIndexStatic%=REFERENCE_TAB_SIZE;
ReferenceTab[RefIndexStatic++] = AcquisitionValue;
for(RefIndex=0;RefIndex<REFERENCE_TAB_SIZE;RefIndex++)
{
Reference += ReferenceTab[RefIndex];
}
Reference /= (REFERENCE_TAB_SIZE + 1);
}
}
}
else /* Calibration */
{
if(NumberOfCalibration < NUMBER_OF_CALIBRATION)
{
Reference += AcquisitionValue;
NumberOfCalibration++;
}
else if(NumberOfCalibration == NUMBER_OF_CALIBRATION)
{
Reference += AcquisitionValue;
Reference /= (NUMBER_OF_CALIBRATION + 1); /* Compute reference */
NumberOfCalibration = 0; /* Reset number of calibration for nex time */
CalibrationDone = 1; /* Calibration Completed */
for(RefIndex=0;RefIndex<REFERENCE_TAB_SIZE;RefIndex++)
{
ReferenceTab[RefIndex] = Reference;
}
}
}
AcquisitionValue = 0; //¸´Î»countÖµ
TSC->CR |= (1<<1) ; // ¿ªÊ¼ÐµÄϵÁÐ
}
}
void main()
{
Configure_TSC£¨£©;
TSC->CR |= (1<<1); // ¿ªÊ¼×ª»»
while(1)
{
Process();
}
}
|
|