STM8 RC触摸库简单介绍

来源:互联网 发布:互联网营销数据分析 编辑:程序博客网 时间:2024/05/16 05:40

触摸检测到按键按下调用流程 :TSL_Action -> TSL_SCKEY_P1_Acquisition() -> TSL_IO_Acquisition() -> TSL_SCKey_Process() -> TSL_SCKey_DetectedTreatment() ,其中TSL_Action ()和TSL_SCKey_Process() 还有其他的状态变化和处理。

TSL_IO_Acquisition() 函数为充放电时间检测函数,其中最重要的变量应该是充放电时间和检测到超过预设范围的次数,函数外部会用到,分别为FinalMeasurementValue和RejectionCounter。

void TSL_IO_SW_Burst_Wait_Vil(void)//只看IAR编译器的内容
{


#if defined(_COSMIC_)
......
#elif defined(_IAR_)
  __asm("ld a, S:AcquisitionBitMask"); //将AcquisitionBitMask放到a中
  __asm("ldw x, S:sTouchIO");   // 将sTouchIO放到x中  装载字(16位)
  __asm("incw x");                    //增加一个字
  // Loop = 1 + 1 + 2 + 2 + 2 cycles = 8 cycles
  __asm("WaitForVil:");
// To be sure that the loop last 8 cycles the first instruction must be a 1-byte instruction
// This is to be sure it is fully fetched in 1 cycle. The second instruction must be shorter than 4 bytes.
// If this not the case, the code must be aligned.
  __asm("bcp a, (x)");  // 1 cycles 逻辑比较
  __asm("jreq ??EndWaitForVil");  //跳转到EndWaitForVil处
  __asm("ldw y, TIMACQ_CNTR"); // 2 cycles; hw counter also used for timeout ...
  __asm("cpw y, #0x0E00");    // 2 cycles; Timeout compare 字数值比较
  __asm("jrult ??WaitForVil");
  __asm("EndWaitForVil:");
#else //_RAISONANCE_
......
#endif
}

这个函数的大概意思是说检测对应管脚的电平,直到相同电平或者超时跳出,FinalMeasurementValue中装的应该就是TIMACQ_CNTR计数器的值(不知道是否正确,请大神指正)


注:

触摸方案的设计摘要:http://download.csdn.net/detail/wr1040982587/9697492

触摸方案的简单工程:http://download.csdn.net/detail/wr1040982587/9697482

有需要可以下载参考下!

0 0