⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 电容感应程序
💻 C
字号:
//------------------------------------------------------------------------------
// Name: CSA_7_Button_Slider Demo Lab
//------------------------------------------------------------------------------
// Revision History:
//             - 09/12/2006 - Version 1.0 (UTT) 
//                 1.  Initial Release
//------------------------------------------------------------------------------
// For Board:  CY3203 - CapSense RevA
//------------------------------------------------------------------------------
// For Device: CY20434-12LFXC 
//------------------------------------------------------------------------------
// Required Software:  PSoC Designer 4.3 w/CY8C20x34 Extension Pack
//------------------------------------------------------------------------------
// Description:  This code determines which sensor is depressed among 7 sensors
// and displays that sensor number on the LCD display. This code also determines 
// position of the finger on the slider.  The slider is composed of 8 sensors 
// diplexed to 16 segments.  The displayed value is the position of the finger 
// scaled according to the resolution set in the CapSense wizard.  Once the 
// slider board is pressed, the location and direction of the finger are 
// displayed on the LCD screen.  
//-------------------------------------------------------------------------------
// Project Settings: 
//      
//      Power Setting [Vcc/SysClk Freq]:  5.0V/12MHz
//      CPU Clock:                        Sysclk/1  
//      
//      Finger Threshold:          100
//      Noise Threshold:           10
//      BaselineUpdateThreshold:   100
//      Settling Time:             160
//      IDACSetting:               20
//      External Cap:              None
//      Hystersis:                 10 
//
//  	SW0 -> P1[2]
//      SW1 -> P1[4]
//      SW2 -> P1[6]
//      SW3 -> P3[2]
//      SW4 -> P3[3]
//  	SW5 -> P3[0]
//      SW6 -> P1[3]
//
//  	W0 -> P0[0]
//      W1 -> P0[1]
//      W2 -> P0[2]
//      W3 -> P2[7]
//      W4 -> P0[4]
//  	W5 -> P0[5]
//      W6 -> P0[6]
//      W6 -> P0[7]
//---------------------------------------------------------------------------------

#include <m8c.h>                                            //Part specific constants and macros
#include "PSoCAPI.h"                                        //PSoC API definitions for all User Modules

WORD i, x;                                                  //Define index variables 

int position = 0, previousPos = 0;                          //Define slider current and previous position

void main()
{

     LCD_1_Start();                                         //Initialize LCD
     LCD_1_Position(0,0);									
     LCD_1_PrCString("7-Button Slider ");                   //Display Title
     LCD_1_Position(1,0);
     LCD_1_PrCString("Demo v1.0       ");

     for (i=0; i< 60000; i++);                              //Delay long enough for title and version to be displayed
     for (i=0; i< 60000; i++);

     LCD_1_Position(0,0);
     LCD_1_PrCString("                ");
     LCD_1_Position(1,0);
     LCD_1_PrCString("                ");

     CSA_1_Start();
     M8C_EnableGInt;                                          
     CSA_1_SetDefaultFingerThresholds();                    //Load finger thresholds set in Device Editor
     CSA_1_InitializeBaselines();                           //Initialize all baselines to current count
	
     while(1) {
          CSA_1_ScanAllSensors();                          
          CSA_1_UpdateAllBaselines();                       

          if(CSA_1_bIsAnySensorActive()){    	            //Were any sensors pressed in the last scan?
               for(i=0; i<CSA_1_ButtonCount; i++){          //Loop through sensors and display which ones were active
                    if (CSA_1_bIsSensorActive(i)) {         //Was this sensor active? 
                         LCD_1_Position(0,0);               //Set LCD Position
                         LCD_1_PrHexInt(i);                 //Display sensor number that was active		    	     
                    } 
               }
               position = CSA_1_wGetCentroidPos(1);         //Get the finger position
               if(position != 0xFFFF){                      //Is the position valid?
                    LCD_1_Position(0,0);                    //Set LCD position 
                    LCD_1_PrHexInt(position);               //Display the finger position
                    LCD_1_Position(1,0);
                    if ((position - previousPos) < -1){     //Did the finger slide from left to right?
                         LCD_1_PrCString("Left            ");   
                         previousPos = position;
                    }
                    else if ((position - previousPos) > 1){ //Did the finger slide from right to left?        
                         LCD_1_PrCString("Right           ");
                         previousPos = position;
                    }	    	
               }
          }     
          else{                                             //No sensor active clear LCD
               LCD_1_Position(0,0);
               LCD_1_PrCString("                ");
               LCD_1_Position(1,0);
               LCD_1_PrCString("                ");
          }       
    }//End of normal operating loop
}//End of main

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -