This is tip #11 from my "Tip of the Day" posts on the older Delphi 6502 forum (which is still there so you can refer back to older 6502 discussions):
----------------------------
The MIDI (musical instrument digital interface) bit rate is 31,250bps, which is not a standard rate option for the 6551 ACIA with a 1.8432 MHz crystal. To get it, set the 6551 for one-sixteenth of the XTAL clock input rate, and then feed it with 500kHz instead of 1.8432MHz. Get the 500kHz off of a 6522's PB7 from its free-running T1. If you have a 6522 put out a steady square wave on PB7 from T1, the frequency is: f=Ph2/(2(n+2)), where Ph2 is the phase-2 system clock frequency, and n is the T1 latch value.
----------------------------
So if you have a 6551 ACIA and a 6522 VIA and use those:
Set VIA_DDRB<7> to make PB7 an output bit.
Set VIA_ACR<6,7> for free-running T1 output on PB7, no IRQ.
Store 3 in VIA_T1CL for 500kHz PB7 output if ph2 is 5MHz
(Store 0 if ph2 is 2MHz. Equation is above.)
Store 0 in VIA_T1CH (do this _after_ writing to T1CL above)
Feed the 500kHz from VIA PB7 into ACIA XTAL 1 input (DIP pin 6).
(Don't use a crystal with this ACIA.)
Don't connect ACIA RxC (DIP pin 5).
Store 0 in ACIA_STAT_REG for software reset.
Store 1011B in ACIA_COM_REG for no parity or echo, TX & RX enabled, no IRQ.
Store 10010000B in ACIA_CTRL_REG for 2 stop bits, 8 data, RX clock=TX clock,
and TX clock=1/16 of XTAL input freq.
Of course if you receive MIDI info too and not just transmit, you will definitely want interrupts; but when I fooled around with it, I only transmitted, which is one reason ACIA interrupts are shown disabled above. Since I only transmitted, I didn't have to put any optoisolators on the home-made computer side. I used only two wires, one from ACIA TxD through a 220-ohm resistor to pin 5 of a male 5-pin DIN connector, and another wire from +5V through a 220-ohm resistor to pin 4 of the same DIN. The DIN connector pins are numbered in a way you might not expect. As you look into the end of the male connector with the middle pin at the top, you have starting at 9 o'clock pin 3, going clockwise to 5, 2 (at 12 o'clock), 4, and finally pin 1 at 3 o'clock.
Garth
engr@drecomm.com