Oscar
Joined: 23 Feb 2013 Posts: 1 Location: 英国
|
transmit MIDI message to a PC software via USB |
Posted: Sat Feb 23, 2013 5:51 pm |
|
|
I am a beginner and now doing a USB-MIDI project on 18F2550. I would like to transmit MIDI message to a PC software via USB. According to nakarman's work:
http://www.ccsinfo.com/forum/viewtopic.php?p=93141
I am able to install the driver for pic on host and the MIDI software(like MIDI-OX) can recognize the device, but no MIDI message was monitored. here is nakarman's code:
Code: |
#include <18F2550.h>
//#define USB_CON_SENSE_PIN PIN_B2 //CCS 18F4550 development kit has optional connection sense pin
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN //~~~ 20MHZ OSCILLATOR CONFIGS ~~~//
#use delay(clock=48000000/*, RESTART_WDT*/)
#DEFINE USB_HID_DEVICE FALSE
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP2_RX_ENABLE USB_ENABLE_BULK //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 64 //size to allocate for the tx endpoint 1 buffer
#define USB_EP2_RX_SIZE 64 //size to allocate for the rx endpoint 1 buffer
#include <pic18_usb.h>
#include <descriptors.h> //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
int8 rxdata[8];
void main(void) {
//int1 run=0;
//int16 ms_counter;
unsigned char buf[4];
printf("\r\n\nCCS USB Bulk Example\r\nPCH: v");
printf(__PCH__);
usb_init_cs();
printf("\r\n\n");
while (TRUE) {
usb_task();
if(usb_enumerated()) {
//if (run)
// usb_scope_task();
if (usb_kbhit(2)) {
usb_get_packet(1,rxdata,8);
//printf("\r\n--> Received 2 bytes: Thresh=%U Delay=%U",threshold,sample_rate);
}
//HERE i differently try to send midi data to pc
//buf[0] = (3 << 4) | 0x09;
buf[1] = 0x93;
buf[2] = 12;
buf[3] = 64;
buf[0] = (3 << 4) | 0x09;
usb_put_packet(1, buf, 4, USB_DTS_TOGGLE);
delay_ms(250);
buf[0] = (4 << 4) | 0x09;
usb_put_packet(1, buf, 4, USB_DTS_TOGGLE);
delay_ms(250);
usb_puts(1, 0x3BB01919, 4, 250);
delay_ms(250);
//falsh led
output_bit(PIN_B7,1);
delay_ms(200);
output_bit(PIN_B7,0);
}
}
} |
anyone can help? |
|