• 外设capsense的简单调用


    1.熟悉外设capsense的简单使用,使用到了两个button,一个5元素的slide,
    Cypress提供算法供调用检测外设capsense。

    2.jtag编程将micro-usb连接在板子的J1口上



    3.结果如图所示

     
    4.* Hardware connection on the Kit
    * Slider - P5[0] - P5[4]
    * Button1 - P5[5]
    * Button2 - P5[6]
    * LCD 2[0-6]

    5.示例代码

     1 #include <device.h>
     2 
     3 /* Define constants for capsense button and slider */
     4 #define ON           (1)
     5 #define OFF          (0)
     6 #define NO_FINGER    (0xFF)
     7 
     8 void main()
     9 {
    10     uint8 statusButton0 = OFF;
    11     uint8 statusButton1 = OFF;
    12     uint16 sliderPosition = NO_FINGER;
    13     uint16 lastPosition = NO_FINGER;
    14     
    15     CYGlobalIntEnable; 
    16 
    17     LCD_Start();
    18     LCD_Position(0,0);
    19     LCD_PrintString("Btn0 Btn1 Slider");
    20 
    21     /* Start capsense and initialize baselines and enable scan */
    22     CapSense_Start();
    23     CapSense_InitializeAllBaselines();
    24     CapSense_ScanEnabledWidgets();
    25 
    26     while(1)
    27     {
    28         /* If scanning is completed update the baseline count and check if sensor is active */  
    29         if(!CapSense_IsBusy())
    30         {
    31             /* Update baseline for all the sensors */
    32             CapSense_UpdateEnabledBaselines();
    33             CapSense_ScanEnabledWidgets();
    34         
    35             /* Test if button widget is active */
    36             statusButton0 = CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN);
    37             statusButton1 = CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN);
    38             sliderPosition =(uint8)CapSense_GetCentroidPos(CapSense_LINEARSLIDER0__LS);
    39 
    40             /* Display button 1 status on LCD */
    41             LCD_Position(1,0);
    42             if( statusButton0 == ON )
    43             {
    44                 LCD_PrintString("On ");
    45             }
    46             else
    47             {
    48                 LCD_PrintString("Off");
    49             }
    50 
    51             /* Display button 1 status on LCD */
    52             LCD_Position(1,5);
    53             if( statusButton1 == ON )
    54             {
    55                 LCD_PrintString("On ");
    56             }
    57             else
    58             {
    59                 LCD_PrintString("Off");
    60             }
    61 
    62 
    63             LCD_Position(1,10);
    64             
    65             if(sliderPosition == NO_FINGER)
    66             {
    67                 LCD_PrintString("----");
    68             }
    69             
    70             /* Finger detected on the slider */
    71             else
    72             {
    73                 /* If finger position on the slider is changed then update the LCD */
    74                 if(sliderPosition != lastPosition)
    75                 {
    76                     LCD_Position(1,10);
    77                     LCD_PrintString("    ");
    78                     LCD_Position(1,10);
    79                     LCD_PrintNumber(sliderPosition);
    80                     LCD_PutChar('%');
    81                     lastPosition = sliderPosition; 
    82                 }
    83             }
    84         }
    85     }    
    86 }
    87 
    88 /* [] END OF FILE */

     

  • 相关阅读:
    扩展的friend语法
    常量表达式
    字符串过滤,排序输出数字的问题
    decltype类型声明- 现代C++新特性总结
    auto类型-现代C++新特性
    指针相关总结2
    指针相关总结1
    发现XMind一个超级牛逼的功能
    空类指针为什么可以调用类的成员函数 以及 A(){}和A();
    SSAS父子层次结构的增强-UnaryOperatorColumn属性
  • 原文地址:https://www.cnblogs.com/lihao602/p/3312484.html
Copyright © 2020-2023  润新知