替换c中的switch语句
我想知道是否可以向您寻求帮助,我正在玩一个pic USB接口教程,该教程中将未签名的字符从c ++应用程序写入固件.
I was wondering if I could ask you for some help, i''m playing with a pic USB interface tutorial, where an unsigned char is written to the firmware from a c++ application.
ProcessIO(void)
{
if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;
if(!HIDRxHandleBusy(USBOutHandle))
{
switch(RecievedDataBuffer[0])
{
case 0x01: //do something
break;
case 0x02: //do something
break;
}
USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
}
}
问题在于通过switch语句测试了RecievedDataBuffer [0].我大约有60种不同的命令要通过cs应用程序通过USB发送到固件(我正在谈论的代码是PIC 18F的固件),唯一的区别是存储在DataRecievedBuffer [0]中的hexi代码.因此,我只用不同的十六进制值编写了60条switch语句,而不是将上面的switch语句替换为以下代码:
The problem is the RecievedDataBuffer[0] is tested through switch statements. I have about 60 different commands to be sent VIA usb to the firmware from a c++ application (the code I am talking about is the firmware for a PIC 18F), the only difference being the hexi code stored in the DataRecievedBuffer[0]. So instead of writing 60 switch statements, only with different hex values, I would just like to replace the switch statement above to the code below:
j = ReceivedDataBuffer[0]; //unsigned char j = recieved data
upper_nibble = j & 0x0f0; //bit mask lower bits
PORTB = upper_nibble;
DelayMs(100);
RB1 = 1; //pulse enable line
DelayMs(100);
RB1 = 0;
DelayMs(100);
PORTB = 0x00;
k = (j << 4) | (j >> 4); //swap nibbles
lower_nibble = k & 0x0f0; //again bit mask to leave the lower nibble PORTB = lower_nibble;
DelayMs(100);
RB1 = 1; //pulse enable and reset
DelayMs(100);
RB1 = 0;
DelayMs(100);
PORTB = 0x00; //clear port
因此,我希望将缓冲区中收到的每个命令发送到PIC的管脚,但是程序崩溃了……您对如何解决此问题有任何建议吗?
好的...我认为这还不清楚...目前,在以下之间有一个switch语句:
So i''m looking to send each command recieved in the buffer to the pins of my PIC, but the program crashes...Do you have any suggestion of how I could fix this?
OK...I think this is pretty unclear...At the moment, there is a switch statement between:
if(!HIDRxHandleBusy(USBOutHandle))
...和
...and
USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
我要做的只是从页面顶部向下的第二个代码块替换此switch语句,但是似乎当我尝试放置除上述switch语句之外的其他语句时,系统完全没有响应.我没有在线防盗器,所以我盲目地这样做.我只是想知道有人在替换时是否会发现根本上的错误:
All i would like to do is replace this switch statement with the second block of code down from the top of this page, but it seems like when ever I try to put a statement other than the switch statement above, the system is completly unresponsive. I don''t have an in-circuit degugger so I''m doing this blindly. I was just wondering if somebody could see something fundamentally wrong in replacing:
switch(RecievedDataBuffer[0])
像这样:
with something like:
If( (RecievedDataBuffer[0]) = 0x02)
谢谢
Martyn
Thanks
Martyn
如此简单
If((RecievedDataBuffer [0])= 0x02)
{
}
else If((RecievedDataBuffer [0])= 0x01)
{
}
其他
{
cout<< 下地狱";
}
its so easy
If( (RecievedDataBuffer[0]) = 0x02)
{
}
else If( (RecievedDataBuffer[0]) = 0x01)
{
}
else
{
cout << "gone to hell";
}