Boas.
Estou a desenvolver um controlador midi, utilizando um PIC 18f4550 e estou a usar um código exemplo da Microchip Solutions, modificando-o para a minha aplicação, só que me deparei com um problema. Não consigo utilizar 2 botões em simultâneo, sei que se trata de um problema de código mas não sei como resolve-lo.
void ProcessIO(void)
{
//static BYTE pitch = 0x3C;
static BOOL sentNoteOff = TRUE;
//Blink the LEDs according to the USB device status
BlinkUSBStatus();
// User Application USB tasks
if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;
if(!USBHandleBusy(USBRxHandle))
{
//We have received a MIDI packet from the host, process it and then
// prepare to receive the next packet
//INSERT MIDI PROCESSING CODE HERE
//Get ready for next packet (this will overwrite the old data)
USBRxHandle = USBRxOnePacket(MIDI_EP,(BYTE*)&ReceivedDataBuffer,64);
}
if(sw1==0)
{
if(sentNoteOff == TRUE)
{
if(msCounter == 0)
{
if(!USBHandleBusy(USBTxHandle))
{
//Debounce counter for 100ms
msCounter = 5;
midiData.Val = 0; //must set all unused values to 0 so go ahead
// and set them all to 0
midiData.CableNumber = 0;
midiData.CodeIndexNumber = MIDI_CIN_NOTE_ON;
midiData.DATA_0 = 0x90; //Note on
midiData.DATA_1 = 0x77; //pitch
midiData.DATA_2 = 0x2F; //velocity
USBTxHandle = USBTxOnePacket(MIDI_EP,(BYTE*)&midiData,4);
sentNoteOff == FALSE;
}
}
}
}
else if(sw2==0)
{
if(sentNoteOff == TRUE)
{
if(msCounter == 0)
{
if(!USBHandleBusy(USBTxHandle))
{
//Debounce counter for 100ms
msCounter = 5;
midiData.Val = 0; //must set all unused values to 0 so go ahead
// and set them all to 0
midiData.CableNumber = 0;
midiData.CodeIndexNumber = MIDI_CIN_NOTE_ON;
midiData.DATA_0 = 0x90; //Note on
midiData.DATA_1 = 0x76; //pitch
midiData.DATA_2 = 0x2F; //velocity
USBTxHandle = USBTxOnePacket(MIDI_EP,(BYTE*)&midiData,4);
sentNoteOff == FALSE;
}
}
}
}
else
{
if(msCounter == 0)
{
if(sentNoteOff == FALSE)
{
if(!USBHandleBusy(USBTxHandle))
{
//Debounce counter for 100ms
msCounter = 5;
midiData.Val = 0; //must set all unused values to 0 so go ahead
// and set them all to 0
midiData.CableNumber = 0;
midiData.CodeIndexNumber = MIDI_CIN_NOTE_ON;
midiData.DATA_0 = 0x90; //Note off
midiData.DATA_1 = 0x80; //pitch
midiData.DATA_2 = 0x00; //velocity
USBTxHandle = USBTxOnePacket(MIDI_EP,(BYTE*)&midiData,4);
sentNoteOff == TRUE;
}
}
}
}
}//end ProcessIO
Se for necessário posso postar mais do código.
O problema está no sentNoteOff que não permite que quando um botão está a ser pressionado outro não pode ser. E sem este sentNoteOff quando é pressionado o botão esta constantemente a enviar sinal midi, o que é indesejado.
Se alguém poder ajudar agradecia.