#define POWER 0x01
#define CLKREC 0x0f
#define E0CSR 0x11
#define E0CNT 0x16
#define FIFO0 0x20
/////////////////////////////////////
// Generated Initialization File //
/////////////////////////////////////
#include "compiler_defs.h"
#include "C8051F380_defs.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void PCA_Init()
{
PCA0MD &= ~0x40;
PCA0MD = 0x00;
}
void Oscillator_Init()
{
FLSCL = 0x90;
CLKSEL = 0x03;
OSCICN = 0xC3;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
PCA_Init();
Oscillator_Init();
}
char USB_Read(char Index)
{
while ((USB0ADR & 0x80) == 0x80);
USB0ADR=(0x80 | Index);
while ((USB0ADR & 0x80) == 0x80);
return USB0DAT;
}
void USB_Write(char Index,char Value)
{
while ((USB0ADR & 0x80) == 0x80);
USB0ADR=(Index);
USB0DAT=Value;
}
void USB_Init(void)
{
USB_Write(POWER,0x18);
USB_Write(CLKREC,0x8f);
USB0XCN=0xe0;
USB_Write(POWER,0);
}
void main (void)
{
char Tmp,Index,Len,Buf[16];
Init_Device();
USB_Init();
do
{
Tmp=USB_Read(E0CSR);
} while ((Tmp & 1)==0);
Len=USB_Read(E0CNT);
for (Index=0;Index<Len;Index++)
{
Buf[Index]=USB_Read(FIFO0);
}
while (1) ;
}