Jallist Archive Jun 2003

MIDI In problem

From: "sorecsorec" <dougwills(at)cox.net>
Date: 03 Jun 2003 03:41:43 -0000

Hey guys. I am hoping someone can help. I am working on what I 
thought was going to be a simple program. I want to take a midi 
signal from a midi player that I have and based on certain notes 
being turned on and off, I want to light an LED. 

I have successfully used code found here in this group to take my PIC 
and play notes back. My oldest son is a drummer and it is my hope to 
provide him with a midi controlled drum unit for the types of 
percussion instruments that he doesn't yet own. I figured I could 
build a series of strike pads, hook them up to a PIC and have the PIC 
play the notes through the midi equipment they have. That's done. I 
also want to add some visual feedback so that when the note is 
played, an LED mounted on top of the strike pad will light (I may 
change this to a different light source in order to help WOW the 
audience.) 

I don't believe my problem is software related. The code I am tesing 
with is just too simple. I set up the UART on a 16F877 to the right 
baud rate and listen for a midi note on signal (0x9X) where the X is 
the channel number. Eventually, I will light a specific LED based on 
the note number, but for right now I would be satisfied with lighting 
one LED based on any note on command.

I wired things up based on some samples I found on the net, but I 
don't seem to be getting anywhere. The example(s) I found runs midi 
cable pins 4 and 5 through a darlington photocoupler and from there 
into the RX (RC7) on the PIC.

Since the software didn't seem to be receiving any midi in data, I 
tried to view the midi in from the cable on my O-scope and saw 
nothing. I got a very used 20Mhz scope for free, and I am concerned 
that it isn't operating correctly, or I don't know how to use it (a 
distinct possibility). I am hoping someone here has worked with midi 
enough to help me with the hardware side of things with a more 
detailed explaination then "here's how you hook it up." Obviously, 
making sure the schematic I have is right would be helpful (although 
I found the same basic schematic on three different web sites), but 
even more helpful then that would be to understand what is happening 
with the signal. The schematic can be found at 
http://www.troikaranch.org/schematic.html.

I am including the pertinent code ever so slightly modified from what 
I found in this group.

Thanks for any help you can provide. My son will also be exremely 
grateful.

Doug


--  

include 16f877_20
include jpic
include jdelay

port_b_direction = all_input
pin_d0_direction = output

procedure MIDI_setup is
begin
Bank_1
f877_spbrg = 39
-- f877_brgh = High
brgh = High
Bank_0
Bank_1
-- f877_txen = High
txen = High
Bank_0
cren = High
-- f877_spen = High
-- f877_cren = High
spen = High

end procedure


Procedure MIDI_in ( byte out data ) is begin -- (RX on pin RC7) (TTL 
Level)
Bank_0
while ! RCIF loop
end loop
file_get ( 0x1A , data )
end procedure

Procedure MIDI_out ( byte in data ) is begin -- (TX on pin RC6) (TTL 
Level)
Bank_0
while ! TXIF loop
end loop
file_put ( 0x19 , data )
end procedure


var byte MDin

MIDI_setup 
pin_d0 = on  -- just to test and make sure the LED is working
delay_500ms(2)
pin_d0 = off


forever loop

MIDI_in(MDin)
-- if MDin == 0x90 then <<< Originally looking for a channel 1 (0) 
note on command, then changed to the following to catch any data at 
all

if MDin > 0 then  -- If ANY signal is received, light the LED
	 pin_d0 = on
	 end if
	
-- if MDin == 0x80 then
--	 pin_d0 = off
--	 end if


end loop




Seiz System Engineering AbelCam AbelCam WebCam Software for Windows