C8051F340 USB器件数据传输硅实验室IDE

时间:2015-03-02 06:06:04

标签: c microcontroller 8051

我正在尝试为C8051F340编写设备代码,以便通过USB从主机(PC)获取数据。我有一些来自硅实验室的例子,代码如下所示:

void  Receive_File(void)
{
   ReadStageLength = ((BytesToRead - BytesRead) > MAX_BLOCK_SIZE_READ)? MAX_BLOCK_SIZE_READ:(BytesToRead - BytesRead);

   BytesRead   += Block_Read((U8*)(&TempStorage[BlockIndex]), ReadStageLength);   // Read Block

   BlockIndex++;
  // If device has received as many bytes as fit on one FLASH page, disable interrupts,
  // write page to flash, reset packet index, enable interrupts
  // Send handshake packet 0xFF to host after FLASH write
   if ((BlockIndex   == (BLOCKS_PR_PAGE)) || (BytesRead  == BytesToRead))
 {
  Page_Erase((U8*)(PageIndices[PageIndex]));
  Page_Write((U8*)(PageIndices[PageIndex]));
  PageIndex++;
  Led1 = !Led1;
  BlockIndex  =  0;
  Buffer[0]   =  0xFF;
  Block_Write(Buffer,  1);         // Send handshake Acknowledge to host
 }

// Go to Idle state if last packet has been received
if (BytesRead  == BytesToRead)   {M_State =  ST_IDLE_DEV;   Led1  =  0;}
}

// Startup code for SDCC to disablt WDT before initializing variables so  that
// a reset does not occur
 #if defined SDCC
void _sdcc_external_startup (void)
{
 PCA0MD &= ~0x40;                    // Disable Watchdog timer
}
#endif

我有一些问题想问: 1.数据在哪里?缓冲区[0]? 2.如果我从主机获得Hex值传输,我可以只读取Buffer [0]来获取它吗? 对不起,我是新手。 谢谢。

1 个答案:

答案 0 :(得分:0)

您收到的数据存储在数组TempStorage中 您使用Buufer [0](值0xFF)将数据发送到主机