📄 main_分别实验usb_capsens用.c
字号:
//----------------------------------------------------------------------------
// C main ( unisen Cyber Station K.B. )
//----------------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include <string.h>
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
BYTE abKeyboardData[8] = {0,0,0,0,0,0,0,0};
// ^ ^
// | |
// ctrl Alpha
/*
BYTE abKeyboardDataSave[8] = {0,0,0,0,0,0,0,0};
BYTE i = 0,k = 0;
*/
//M8C_Reset;
/*
void main()
{
M8C_EnableGInt; //Enable Global Interrupts
USBFS_1_Start(0, USB_5V_OPERATION); //Start USBFS Operation using device 0
//and with 5V operation
while(!USBFS_1_bGetConfiguration()); //Wait for Device to enumerate
//Enumeration is completed load endpoint 1. Do not toggle the first time
USBFS_1_LoadInEP(1, abKeyboardData, 8, USB_NO_TOGGLE);
M8C_EnableWatchDog; //(CPU_SCR0 &= ~CPU_SCR0_PORS_MASK)
while(1)
{
M8C_ClearWDT; //(RES_WDT = 0x00)
while(!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
if( memcmp(abKeyboardDataSave,abKeyboardData,8)!=0 )
{ USBFS_1_LoadInEP(1, abKeyboardData, 8, USB_TOGGLE);
memmove(abKeyboardDataSave,abKeyboardData,8);
}
if(i==128 && k<26)
{ //When our count hits 128
abKeyboardData[2] = 4+k++; //abcdef..xyz
}
else if(i==255 && k<27)
{
memset(abKeyboardData,0,8);
}
i++;
}
}
*/
void main()
{
M8C_EnableGInt; //Enable Global Interrupts
CSD_1_Start();//CSD 电容式键盘初始化
CSD_1_InitializeBaselines() ; //scan all sensors first time, init baseline
CSD_1_SetDefaultFingerThresholds() ;//设置 电容式键盘 Finger Thresholds
//USBFS_1_Start(0, USB_5V_OPERATION); //Start USBFS Operation using device 0
//and with 5V operation
//while(!USBFS_1_bGetConfiguration()); //Wait for Device to enumerate 等待USB HOST取得USB描述符
//Enumeration is completed load endpoint 1. Do not toggle the first time
//USBFS_1_LoadInEP(1, abKeyboardData, 8, USB_NO_TOGGLE);
while( 1 )
{
//memset(ScanArrayImage,0,5);//将键盘位图清零
//while(!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data 等待 USB HOST ACK 协议发生
//ACK has occurred, load the endpoint and toggle the data bit
//扫描键盘
CSD_1_ScanAllSensors(); //scan all sensors in array (buttons and sliders)
CSD_1_UpdateAllBaselines(); //Update all baseline levels;
//detect if any sensor is pressed
if(CSD_1_bIsAnySensorActive())//有键按下
{
memmove( abKeyboardData,CSD_1_baSnsOnMask,3 );
}
/*
if( KeyPressMain() == 1 ) //产生了键盘码
{
//向 USB 送键盘扫描码
USBFS_1_LoadInEP(1, abKeyboardData, 8, USB_TOGGLE);
}
*/
}
}
// now we are ready to send all status variables to chart program
// communication here
//
// OUTPUT CSD_waSnsResult[x] <- Raw Counts
// OUTPUT CSD_waSnsDiff[x] <- Difference
// OUTPUT CSD_waSnsBaseline[x] <- Baseline
// OUTPUT CSD_baSnsOnMask[x] <- Sensor On/Off
/*
#pragma ioport LED:0x04;
char LED;....
LED = 1;
// ioport is at IO space 0x04
LED must be declared in global scope
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -