//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include "cypdef.h" // Contains definitions for Endpoint registers
//----------------------------------------------------------------------------
//-----------------------
// Definitions and Types
//-----------------------
#define LED_ON (P1DATA &= 0xFB)
#define LED_OFF (P1DATA |= 0x04)
#define BUTTON_PU (P0DATA |= 0x08)
//-----------------------
// local function
//-----------------------
void delay(void);C:\Documents and Settings\Administrator\桌面
void main(void)
{
// M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
// Insert your main routine code here.
//BYTE i;
//BYTE epcnt;
//BYTE endpt_ram[8]={0,1,2,3,4,5,6,7};
//Button and LED init
LED_OFF; //LED OFF
BUTTON_PU; //PULL UP BUTTON PIN
//USB init
// USB_Start(0); // Enable USB
//M8C_EnableGInt; //and Global Interrupts
// Wait for USB enumeration
/*while (0 == USB_bGetConfiguration());
USB_EnableEP(1); //EP1 is ocnfigured as OUT endpoint and EP2 is the IN endpoint
while (1)
{
// Handle the LED from the Output Report on Endpoint 2
if (OUT_BUFFER_FULL == USB_bGetEPState(1))
{
epcnt = USB_bGetEPCount(1);
endpt_ram[0] = EP1DATA0;
endpt_ram[1] = EP1DATA1;
endpt_ram[2] = EP1DATA2;
endpt_ram[3] = EP1DATA3;
endpt_ram[4] = EP1DATA4;
endpt_ram[5] = EP1DATA5;
endpt_ram[6] = EP1DATA6;
endpt_ram[7] = EP1DATA7;
//Loads the IN enpoint with received data
USB_LoadEP(2, &endpt_ram[0], epcnt);
// This should be done with shadow registers on the GPIO ports
if (endpt_ram[1] == 49)
{
LED_ON;
delay();
}
else
{
LED_OFF;
}
// Unlocks the endpoint and sets it to ACK OUT
USB_EnableEP(1);
}
//when the button is pressed ,send data to PC
if(!(PRT0DR & 0x08))
{
LED_ON;
//Loads the IN enpoint with received data
USB_LoadEP(2, &endpt_ram[0], epcnt);
delay();
}
else
{
LED_OFF;
}
BUTTON_PU;
}*/
}
//==================================================================================
// FUNCTION NAME: delay
//
// DESCRIPTION: a delay time about 2senconds
//
//---------------------------------------------------------------------------------
// ARGUMENTS: NONE
//
// RETURNS: NONE
//
// THEORY of OPERATION or PROCEDURE:
//
//==================================================================================
void delay(void)
{
int i,j;
for(i=0;i<500;i++)
for(j=0;j<100;j++)
{;}
} |