TI-H: MIDI code


[Prev][Next][Index][Thread]

TI-H: MIDI code




Here is a driver code for MIDI this is just minmal code I  got it at
http://www.rt66.com/dthomas/pic/midi.txt

DEVICE	PIC16C54,HS_OSC,WDT_OFF,PROTECT_OFF

midi_out	equ	RA.0

temp		equ	09h
count		equ	0ah
t0		equ	0bh

		RESET	Start

Start
		mov	!RA,#0000b		; all pins are outputs
		mov	!RB,#00000000b
		mov	OPTION,#00000110b	; for 16mc xtal, 31250 RTCC/sec

		clrb	midi_out		; idle state

		; send program change on midi channel 11 to program 5

		mov	t0,#0cah
		call	Midi_send
		mov	t0,#05h
		call	Midi_send

Spin		jmp	Spin

;
;Midi_send -- transmit the byte in t0 over midi
;	ENTRY
;		t0	byte to send
;		midi_out should already be in idle (clrb) state
;	AFFECTED
;		t0,temp,count
;		midi_out left in idle state
;
Midi_send
		mov	temp,RTCC	; wait for RTCC tick
:l1		mov	W,RTCC
		xor	W,temp
		jz	:l1

		setb	midi_out	; send start bit

		mov	count,#8	; loop 8 times to send 8 data bits
:byteloop
		mov	temp,RTCC	; wait for RTCC tick
:l2		mov	W,RTCC
		xor	W,temp
		jz	:l2

		snb	t0.0		; send data bit
		clrb	midi_out	; clrb sends a 1
		sb	t0.0
		setb	midi_out	; setb sends a 0

		rr	t0
		djnz	count,:byteloop

		mov	temp,RTCC	; wait for RTCC tick
:l3		mov	W,RTCC
		xor	W,temp
		jz	:l3

		clrb	midi_out	; send stop bit
		ret