home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 8
/
AU_CD8.iso
/
CoverDiscs
/
November_1999
/
rtr
/
software
/
Drum
next >
Wrap
Text File
|
1999-08-30
|
9KB
|
240 lines
;MIDI Drum
;For an 10 MHz clock
;A0 - MIDI Serial out
;
; 0838 - A/D converter
;B0 - ~CS not Chip Select
;B1 - Clock
;B2 - Data output (multiplex select)
;B3 - Data input (converted value)
;Note for 16F84 invert the state of the PWRTE
LIST P=16C84
C EQU 0
PCL EQU 2
Z EQU 2
PORTB EQU 6
PORTA EQU 5
TRISB EQU 86H
TRISA EQU 85H
EECON1 EQU 88H
INTCON EQU 0BH
EEDATA EQU 8
EEADR EQU 9
STATUS EQU 3
RP0 EQU 5
INC EQU 1
cts EQU 2
rts EQU 3
sBuf EQU 0ch ;Serial send buffer
Scount EQU 0dh ;Tempory Counter
Cdown EQU 0eh ;Time delay countdown
rBuf EQU 0fh ;Recieve buffer
val EQU 10h ;Value from A/D
chan EQU 11h ;Channel to digitise
Tcount EQU 12h ;Tempory loop counter
Ccount EQU 13h ;Channel counter
;
ORG 0
GOTO Start
;Send a serial byte
Send movlw 9 ;Number of data bits to send
movwf Scount
bcf PORTA,0 ;Start bit
call cDelay ;Extra delay compensation
Sloop call Delay
btfsc sBuf,0 ;Set the next bit
bsf PORTA,0
btfss sBuf,0
bcf PORTA,0
rrf sBuf,f ;Shift for next time
decfsz Scount,f
goto Sloop ;Round until finished
bsf PORTA,0 ;Stop bit
call cDelay ;Extra delay compensation
call Delay
call Delay
call cDelay ;For good measure
return
cDelay movlw 2 ;Small delay at end of send
movwf Cdown
goto Dloop
hDelay movlw 10 ;half delay for serial recieve 10MHz clock
movwf Cdown ; 31,250 Baud rate
goto Dloop
rDelay movlw 21 ;Delay for serial recieve 10MHz clock
movwf Cdown ; 31,250 Baud rate
goto Dloop
Delay movlw 22 ;Delay for serial send 10MHz clock
movwf Cdown ; 31,250 Baud rate
Dloop decfsz Cdown,f
goto Dloop
return
Start
BSF STATUS,RP0 ;SELECT REGISTER BANK 1
MOVLW 0Ah ;Bits 3 & 2 inputs
MOVWF TRISA^80H
MOVLW 0F8h ;port B I/O
MOVWF TRISB^80H
MOVLW 00H ;Enable Pull ups on inputs
MOVWF 1 ;Option register
BCF STATUS,RP0 ;SELECT REGISTER BANK 0
BSF PORTA,cts ;CTS disabled
MOVLW 5 ;Inital state of outputs
MOVWF PORTB
movlw 20h ;Fill buffer with FFs
movwf 4
movlw 8
movwf Ccount
pml clrf 0
comf 0,f
incf 4,f
decfsz Ccount,f
goto pml
Main
movlw 20h ;Start of buffer
movwf 4 ;Indirect register
movlw 8 ;Number of channels to read
movwf Ccount ;Into counter
Ml call conv ;do conversion
call hyst ;Add in hystrisis
subwf 0,w ;test to see if more than last time
btfss STATUS,C
call play ;Call play if bigger than last time
movf val,w ;Get current reading
movwf 0 ;save in buffer
incf 4,f ;Move to next buffer position
decfsz Ccount,f
goto Ml ;Read all 8 channels
goto Main ;Loop
conv movlw 5 ;Bits to send
movwf Tcount
movf Ccount,w ;Get channel
iorlw 18h ;Add start bit and single conversion bit
movwf chan ;Channel to convert
bcf PORTB,0 ;Lower ~CS
clop btfss chan,4 ;Put data on output
bcf PORTB,2 ;Put a zero
btfsc chan,4
bsf PORTB,2 ;Or a one
bsf PORTB,1 ;Raise clock
call ckd ;Clock delay
bcf PORTB,1 ;Lower clock
rlf chan,f ;Move sending bit pattern
decfsz Tcount,f ;loop round five times
goto clop
call ckd
call ckd ;Multiplexer settiling time
movlw 9 ;bits to recieve + 1
movwf Tcount
clrf val
ilop rlf val,f ;Shift up pattern to recieve the next bit
bcf val,0 ;make it a zero
btfsc PORTB,3
bsf val,0 ;make it a one if need be
bsf PORTB,1 ;Clock up
call ckd ;Clock delay
bcf PORTB,1 ;Clock down
decfsz Tcount,f
goto ilop ;Round again
bsf PORTB,2 ;Data to the converter set to a one
bsf PORTB,0 ;Raise ~CS as we are finished
movf val,w ;Get value in w
return
ckd return ;1.25 uS delay
play btfsc STATUS,Z ;Return if they are the same
return
sag movf val,w ;get the value
movwf 0 ;put it in the buffer
call conv ;Get same channel again
subwf 0,w ;Test to see if more than last time
btfsc STATUS,Z ;It is the same so don't play it
goto sag
btfss STATUS,C ;Is it greater (still rising)
goto sag ;Go round if it is bigger
movlw 99h ;Note On Channel 10 (drums)
movwf sBuf
call Send
rrf PORTB,w ;Get mapping shift switches
andlw 18h ;Look at only 2 bits (4 mappings)
addwf Ccount,w ;add in the channel
call map ;Map channel number to note (instrument)
movwf sBuf ;Send it
call Send
clrf STATUS,C ;Adjust velocity to 7 bits
rrf 0,w
movwf sBuf ;Send velocity
call Send
clrf val ;Set val to FF to inhibit firing next time round
comf val,f
return ;back with it
hyst incf 0,f ;Add hystresis to stored value
btfsc STATUS,Z ;Make sure it does not wrap round to 0
comf 0,f
incf 0,f ;Add hystresis to stored value
btfsc STATUS,Z ;Make sure it does not wrap round to 0
comf 0,f
incf 0,f ;Add hystresis to stored value
btfsc STATUS,Z ;Make sure it does not wrap round to 0
comf 0,f
return
map ;Map a MIDI drum sound to a channel number
;Change this to suite yourself
addwf PCL,f
;Mapping 0
retlw 59 ;Ch0 Ride cymbal 2
retlw 57 ;Ch1 Crash cymbal 2
retlw 58 ;Ch2 Vibraslap
retlw 56 ;Ch3 Cow bell
retlw 54 ;Ch4 Tambourine
retlw 50 ;Ch5 Hi tom
retlw 48 ;Ch6 Hi hat open
retlw 39 ;Ch7 Hand clap
;Mapping 1
retlw 32 ;Ch0 Sticks
retlw 22 ;Ch1 Metronome bell
retlw 29 ;Ch2 Snare roll
retlw 37 ;Ch3 Side stick
retlw 38 ;Ch4 Snare M
retlw 42 ;Ch5 Hi hat closed
retlw 30 ;Ch6 Castanet
retlw 18 ;Ch7 Scratch pull
;Mapping 2
retlw 20 ;Ch0 Click noise
retlw 19 ;Ch1 Finger snap
retlw 16 ;Ch2 Whip slap
retlw 25 ;Ch3 Brush tap
retlw 26 ;Ch4 Brush swirl
retlw 34 ;Ch5 Open rim shot
retlw 35 ;Ch6 Bass drum M
retlw 36 ;Ch7 Bass drum H
;Mapping 3
retlw 35 ;Ch0 Bass drum
retlw 38 ;Ch1 Snare
retlw 46 ;Ch2 Hi hat open
retlw 49 ;Ch3 Crash cymbal
retlw 51 ;Ch4 Ride cymbal
retlw 55 ;Ch5 Splash Cymbal
retlw 41 ;Ch6 Floor Tom L
retlw 43 ;Ch7 Floor Tom H
end