实验51 USB读卡器(Slave)实验 不能读写U盘,照搬例程过去,然后加了语句 if(KEY==0)如果有按键则进入U盘模式,如果没有按键则跑别的程序。加了这if语句后按下按键,进入U盘模式,电脑上有U盘图标出来,但看不到U盘(SD卡)的内容;如果不要iif(KEY==0)则U盘读写正常,原子哥,请问这是什么回事呢?代码如下: if(KEY==0)
{
LCD_ShowString(30,170,200,16,16,"USB Connecting...");//ìáê¾ÕyÔú½¨á¢ᬽó
USBD_Init(&USB_OTG_dev,USB_OTG_FS_CORE_ID,&USR_desc,&USBD_MSC_cb,&USR_cb);
delay_ms(1800);
while(1)
{
delay_ms(1);
if(USB_STA!=USB_STATUS_REG)//×′쬸ıäáË
{
LCD_Fill(30,190,240,190+16,WHITE);//Çå3yÏÔê¾
if(USB_STATUS_REG&0x01)//ÕyÔúD′
{
LED1=0;
LCD_ShowString(30,190,200,16,16,"USB Writing...");//ìáê¾USBÕyÔúD′èëêy¾Y
}
if(USB_STATUS_REG&0x02)//ÕyÔú¶á
{
LED1=0;
LCD_ShowString(30,190,200,16,16,"USB Reading...");//ìáê¾USBÕyÔú¶á3öêy¾Y
}
if(USB_STATUS_REG&0x04)LCD_ShowString(30,210,200,16,16,"USB Write Err ");//ìáê¾D′èë′íÎó
else LCD_Fill(30,210,240,210+16,WHITE);//Çå3yÏÔê¾
if(USB_STATUS_REG&0x08)LCD_ShowString(30,230,200,16,16,"USB Read Err ");//ìá꾶á3ö′íÎó
else LCD_Fill(30,230,240,230+16,WHITE);//Çå3yÏÔê¾
USB_STA=USB_STATUS_REG;//¼Ç¼×îoóμÄ×′ì¬
}
if(Divece_STA!=bDeviceState)
{
if(bDeviceState==1)LCD_ShowString(30,170,200,16,16,"USB Connected ");//ìáê¾USBᬽóòѾ-½¨á¢
else LCD_ShowString(30,170,200,16,16,"USB DisConnected ");//ìáê¾USB±»°Î3öáË
Divece_STA=bDeviceState;
}
tct++;
if(tct==200)
{
tct=0;
LED1=1;
LED0=!LED0;//ìáê¾Ïμí3ÔúÔËDD
if(USB_STATUS_REG&0x10)
{
offline_cnt=0;//USBᬽóáË,ÔòÇå3yoffline¼ÆêyÆ÷
bDeviceState=1;
}else//ûóDμÃμ½ÂÖÑˉ
{
offline_cnt++;
if(offline_cnt>10)bDeviceState=0;//2sÄúûêÕμ½ÔúÏß±ê¼Ç,′ú±íUSB±»°Î3öáË
}
USB_STATUS_REG=0;
}
};
}
Initial_d3321();
........///正常进入系统而非U盘模式的代码。
一周热门 更多>