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: break;
case 0x02: break;
}
USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
}
}
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];
upper_nibble = j & 0x0f0;
PORTB = upper_nibble;
DelayMs(100);
RB1 = 1;
DelayMs(100);
RB1 = 0;
DelayMs(100);
PORTB = 0x00;
k = (j << 4) | (j >> 4);
lower_nibble = k & 0x0f0;
DelayMs(100);
RB1 = 1;
DelayMs(100);
RB1 = 0;
DelayMs(100);
PORTB = 0x00;
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);
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)
Thanks
Martyn