菜鸟求助:使用CY8C24794的USB模块实现按键扫描功能,调试时发现当主机重启后,板卡与主机就不能通信了,将板卡重新启动后,又能恢复正常,下面是程序代码,有劳大家帮忙看看问题在哪,谢谢了~
#include <m8c.h>
#include "PSoCAPI.h"
BYTE report[8];
BYTE led;
void main()
{
M8C_EnableGInt;
PRT0DR=0xFF;
PRT2DR=0xFF;
USB_Start(0,USB_5V_OPERATION);
while(!USB_bGetConfiguration());
PRT0DR &= 0xFE;
USB_LoadInEP(1,report,8,USB_NO_TOGGLE);
USB_EnableOutEP(2);
report[2]=0x00;
while(1)
{
while(!USB_bGetEPAckState(1)) PRT0DR |= 0x02;
PRT0DR &= 0xFD;
if ((PRT2DR & 0x01) == 0x00)
{
report[2]=0x4F;
PRT0DR &= 0xFB;
}
else if ((PRT2DR & 0x02) == 0x00)
{
report[2]=0x50;
PRT0DR &= 0xFB;
}
else if ((PRT2DR & 0x04) == 0x00)
{
report[2]=0x52;
PRT0DR &= 0xFB;
}
else if ((PRT2DR & 0x08) == 0x00)
{
report[2]=0x51;
PRT0DR &= 0xFB;
}
else if ((PRT2DR & 0x10) == 0x00)
{
report[0]=0x10;
PRT0DR &= 0xFB;
}
else if ((PRT2DR & 0x20) == 0x00)
{
report[0]=0x40;
PRT0DR &= 0xFB;
}
else if ((PRT2DR & 0x80) == 0x00)
{
report[2]=0x45;
PRT0DR &= 0xFB;
}
else
{
report[0]=0x00;
report[2]=0x00;
PRT0DR |= 0x04;
}
USB_LoadInEP(1,report,8,USB_TOGGLE);
if (USB_bGetEPAckState(2))
{
USB_bReadOutEP(2,&led,1);
if ((led & 0x01)== 0x01 ) PRT0DR &= 0xF7;
else PRT0DR |= 0x08;
USB_EnableOutEP(2);
}
}
} |