外设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 */

 

转载于:https://www.cnblogs.com/lihao602/p/3312484.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
void main() { // initialization WORD slidepos; // EzI2Cs initialization EzI2Cs_SetRamBuffer(sizeof(MyI2C_Regs), sizeof(MyI2C_Regs), (BYTE *) &MyI2C_Regs); EzI2Cs_Start(); // Turn on I2C EzI2Cs_SetAddr(5); // Change address to 5 M8C_EnableGInt; // capsense initialization CSD_Start(); CSD_InitializeBaselines() ; CSD_SetDefaultFingerThresholds() ; // LCD initialization LCD_Start(); LCD_Position(0,0); LCD_PrCString("Button:FF"); LCD_Position(1,0); LCD_PrCString("Slider:00"); while (1) { CSD_ScanAllSensors(); //scan all sensors in array (buttons and sliders) CSD_UpdateAllBaselines(); //Update all baseline levels; //detect if any sensor is pressed if(CSD_bIsAnySensorActive()){ // Add user code here to proceed the sensor touching if(CSD_baSnsOnMask[0]&0x01) { LCD_Position(0,0); LCD_PrCString("Button:0 "); } else if(CSD_baSnsOnMask[0]&0x02) { LCD_Position(0,0); LCD_PrCString("Button:1 "); } else if(CSD_baSnsOnMask[0]&0x04) { LCD_Position(0,0); LCD_PrCString("Button:2 "); } else if(CSD_baSnsOnMask[0]&0x08) { LCD_Position(0,0); LCD_PrCString("Button:3 "); } else if(CSD_baSnsOnMask[0]&0x10) { LCD_Position(0,0); LCD_PrCString("Button:4 "); } else if(CSD_baSnsOnMask[0]&0x20) { LCD_Position(0,0); LCD_PrCString("Button:5 "); } else if(CSD_baSnsOnMask[0]&0x40) { LCD_Position(0,0); LCD_PrCString("Button:6 "); } slidepos=CSD_wGetCentroidPos(1); if(slidepos!=0xffff) { // if((slidepos==0x21)&&(CSD_waSnsDiff[11]<32)&&(CSD_waSnsDiff[13]<32)) // slidepos=0x63; LCD_Position(1,7); LCD_PrHexByte(slidepos&0xff); } } else { LCD_Position(0,0); LCD_PrCString("Button:FF"); } // internal variable output for tuning MyI2C_Regs.rawcount=CSD_waSnsResult[9]; MyI2C_Regs.baseline=CSD_waSnsBaseline[9]; MyI2C_Regs.diff=CSD_waSnsDiff[9]; } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值