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

📄 main.c

📁 基于Cypress CY3655开发工具的USB鼠标程序
💻 C
字号:
//----------------------------------------------------------------------------
// mian.c
//----------------------------------------------------------------------------
//
// Program Description:
//
// Draw USB Example Firmware
//
// This example application enumerates as a three button USB Mouse (HID Class)
// and moves the mouse cursor in the shape of the letters U, S, and B.
// It demostrates the use of the USB User Module API.
//
// Note: For proper demostration, turn off Mouse Accelerator using the Windows
// Control Panel.
//
// Hardware considerations:  This application was written for the CY3655
// Application Board that is provided in the CY3655 Development Kit.
//
// Switch S1 is connected to P0.2 (Down=Start Movement/Up=Stop Movement)
// Switch S2 is connected to P0.3 (Down=Left Button Down/Up=Left Button Up)
// Switch S3 is connected to P0.4 (Not used)
// 
// LED D1 is connected to P0.5 (Tracks S1: On=Down/Off=Up)
// LED D2 is connected to P0.6 (Tracks S2: On=Down/Off=Up)
// LED D3 is connected to P1.3 (Not used)
//
//
//
// Target:         CY7C63823-SXC
// Tool chain:     PSoC Designer / CY3655DK
// Author:         Jean hou
//
//---------------------------------------------------------------------------- 


//----------------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------------
#include <m8c.h>        // part specific constants and macros
#include "main.h" 

//----------------------------------------------------------------------------
// Global Constants
//----------------------------------------------------------------------------
BYTE left_button;
BYTE move;
BYTE a_ram[4];
const unsigned char *p_data;

//---------------------------------------------------------------------------
// Main Function
//---------------------------------------------------------------------------
void main()
{
    USB_Start(0);        // Enable USB
    M8C_EnableGInt;      //  and Global Interrupts
    
	while (USB_bGetConfiguration() == 0)    // Wait for USB enumeration
    {}
    
    p_data = &a_logo_vectors[0]; // Point to the first of the logo vectors

    move = STOP;
    left_button = UP;
    
    while (1)
    {
        move        = ((P0DATA & 0x04) ? STOP : GO);  // P0.2 Up or Down
        left_button = ((P0DATA & 0x08) ? UP : DOWN);  // P0.3 Up or Down
        if (move == STOP)
         {   P0DATA |= 0x20;        // P0.5 high (off)
         }else {
            P0DATA &= ~(0x20);      // P0.5 low (on)
         }
        if (left_button == UP)
         {   P0DATA |= 0x40;        // P0.6 high (off)
         }else{
            P0DATA &= ~(0x40);      // P0.6 low (on)
         }
       
        if (move == GO)
        {
            // Check to see if the endpoint is empty
            if (USB_bGetEPState(1) == IN_BUFFER_EMPTY)
            {
	            a_ram[0] = ((left_button == DOWN) ? *p_data : *p_data & ~(LB_DOWN));
	            p_data++;
	            a_ram[1] = *p_data; p_data++;
	            a_ram[2] = *p_data; p_data++;
	            a_ram[3] = *p_data; p_data++;
	        	if (p_data > &a_logo_vectors[sizeof(a_logo_vectors) - 1])
	        		p_data = &a_logo_vectors[0];
	            USB_LoadEP(1, &a_ram[0], 3);
            }        
        }
    }
}

//----------------------------------------------------------------------------
// End Of File
//----------------------------------------------------------------------------

⌨️ 快捷键说明

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