home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 8
/
AU_CD8.iso
/
CoverDiscs
/
November_1999
/
rtr
/
software
/
Drum.L
< prev
next >
Wrap
Text File
|
1999-08-30
|
11KB
|
331 lines
PIC 16C84 Assembler V1.4 by Mike Cook
File:- ADFS::Square.$.Develop.Drum.Drum
Assembled on :- Mon,30 Aug 1999 at 10:42:29
;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
0000 2821 goto Start
;Send a serial byte
Send:
0001 3009 movlw 9 ;Number of data bits to send
0002 008D movwf Scount
0003 1005 bcf PORTA,0 ;Start bit
0004 2013 call cDelay ;Extra delay compensation
Sloop:
0005 201C call Delay
0006 180C btfsc sBuf,0 ;Set the next bit
0007 1405 bsf PORTA,0
0008 1C0C btfss sBuf,0
0009 1005 bcf PORTA,0
000A 0C8C rrf sBuf,f ;Shift for next time
000B 0B8D decfsz Scount,f
000C 2805 goto Sloop ;Round until finished
000D 1405 bsf PORTA,0 ;Stop bit
000E 2013 call cDelay ;Extra delay compensation
000F 201C call Delay
0010 201C call Delay
0011 2013 call cDelay ;For good measure
0012 0008 return
cDelay:
0013 3002 movlw 2 ;Small delay at end of send
0014 008E movwf Cdown
0015 281E goto Dloop
hDelay:
0016 300A movlw 10 ;half delay for serial recieve 10MHz clock
0017 008E movwf Cdown ; 31,250 Baud rate
0018 281E goto Dloop
rDelay:
0019 3015 movlw 21 ;Delay for serial recieve 10MHz clock
001A 008E movwf Cdown ; 31,250 Baud rate
001B 281E goto Dloop
Delay:
001C 3016 movlw 22 ;Delay for serial send 10MHz clock
001D 008E movwf Cdown ; 31,250 Baud rate
Dloop:
001E 0B8E decfsz Cdown,f
001F 281E goto Dloop
0020 0008 return
Start:
0021 1683 bsf STATUS,RP0 ;SELECT REGISTER BANK 1
0022 300A movlw 0Ah ;Bits 3 & 2 inputs
0023 0085 movwf TRISA^80H
0024 30F8 movlw 0F8h ;port B I/O
0025 0086 movwf TRISB^80H
0026 3000 movlw 00H ;Enable Pull ups on inputs
0027 0081 movwf 1 ;Option register
0028 1283 bcf STATUS,RP0 ;SELECT REGISTER BANK 0
0029 1505 bsf PORTA,cts ;CTS disabled
002A 3005 movlw 5 ;Inital state of outputs
002B 0086 movwf PORTB
002C 3020 movlw 20h ;Fill buffer with FFs
002D 0084 movwf 4
002E 3008 movlw 8
002F 0093 movwf Ccount
pml:
0030 0180 clrf 0
0031 0980 comf 0,f
0032 0A84 incf 4,f
0033 0B93 decfsz Ccount,f
0034 2830 goto pml
Main:
0035 3020 movlw 20h ;Start of buffer
0036 0084 movwf 4 ;Indirect register
0037 3008 movlw 8 ;Number of channels to read
0038 0093 movwf Ccount ;Into counter
Ml:
0039 2044 call conv ;do conversion
003A 2081 call hyst ;Add in hystrisis
003B 0200 subwf 0,w ;test to see if more than last time
003C 1C03 btfss STATUS,C
003D 2067 call play ;Call play if bigger than last time
003E 0810 movf val,w ;Get current reading
003F 0080 movwf 0 ;save in buffer
0040 0A84 incf 4,f ;Move to next buffer position
0041 0B93 decfsz Ccount,f
0042 2839 goto Ml ;Read all 8 channels
0043 2835 goto Main ;Loop
conv:
0044 3005 movlw 5 ;Bits to send
0045 0092 movwf Tcount
0046 0813 movf Ccount,w ;Get channel
0047 3818 iorlw 18h ;Add start bit and single conversion bit
0048 0091 movwf chan ;Channel to convert
0049 1006 bcf PORTB,0 ;Lower ~CS
clop:
004A 1E11 btfss chan,4 ;Put data on output
004B 1106 bcf PORTB,2 ;Put a zero
004C 1A11 btfsc chan,4
004D 1506 bsf PORTB,2 ;Or a one
004E 1486 bsf PORTB,1 ;Raise clock
004F 2066 call ckd ;Clock delay
0050 1086 bcf PORTB,1 ;Lower clock
0051 0D91 rlf chan,f ;Move sending bit pattern
0052 0B92 decfsz Tcount,f ;loop round five times
0053 284A goto clop
0054 2066 call ckd
0055 2066 call ckd ;Multiplexer settiling time
0056 3009 movlw 9 ;bits to recieve + 1
0057 0092 movwf Tcount
0058 0190 clrf val
ilop:
0059 0D90 rlf val,f ;Shift up pattern to recieve the next bit
005A 1010 bcf val,0 ;make it a zero
005B 1986 btfsc PORTB,3
005C 1410 bsf val,0 ;make it a one if need be
005D 1486 bsf PORTB,1 ;Clock up
005E 2066 call ckd ;Clock delay
005F 1086 bcf PORTB,1 ;Clock down
0060 0B92 decfsz Tcount,f
0061 2859 goto ilop ;Round again
0062 1506 bsf PORTB,2 ;Data to the converter set to a one
0063 1406 bsf PORTB,0 ;Raise ~CS as we are finished
0064 0810 movf val,w ;Get value in w
0065 0008 return
ckd:
0066 0008 return ;1.25 uS delay
play:
0067 1903 btfsc STATUS,Z ;Return if they are the same
0068 0008 return
sag:
0069 0810 movf val,w ;get the value
006A 0080 movwf 0 ;put it in the buffer
006B 2044 call conv ;Get same channel again
006C 0200 subwf 0,w ;Test to see if more than last time
006D 1903 btfsc STATUS,Z ;It is the same so don't play it
006E 2869 goto sag
006F 1C03 btfss STATUS,C ;Is it greater (still rising)
0070 2869 goto sag ;Go round if it is bigger
0071 3099 movlw 99h ;Note On Channel 10 (drums)
0072 008C movwf sBuf
0073 2001 call Send
0074 0C06 rrf PORTB,w ;Get mapping shift switches
0075 3918 andlw 18h ;Look at only 2 bits (4 mappings)
0076 0713 addwf Ccount,w ;add in the channel
0077 208B call map ;Map channel number to note (instrument)
0078 008C movwf sBuf ;Send it
0079 2001 call Send
007A 0183 clrf STATUS C ;Adjust velocity to 7 bits
007B 0C00 rrf 0,w
007C 008C movwf sBuf ;Send velocity
007D 2001 call Send
007E 0190 clrf val ;Set val to FF to inhibit firing next time round
007F 0990 comf val,f
0080 0008 return ;back with it
hyst:
0081 0A80 incf 0,f ;Add hystresis to stored value
0082 1903 btfsc STATUS,Z ;Make sure it does not wrap round to 0
0083 0980 comf 0,f
0084 0A80 incf 0,f ;Add hystresis to stored value
0085 1903 btfsc STATUS,Z ;Make sure it does not wrap round to 0
0086 0980 comf 0,f
0087 0A80 incf 0,f ;Add hystresis to stored value
0088 1903 btfsc STATUS,Z ;Make sure it does not wrap round to 0
0089 0980 comf 0,f
008A 0008 return
map:
;Map a MIDI drum sound to a channel number
;Change this to suite yourself
008B 0782 addwf PCL,f
;Mapping 0
008C 343B retlw 59 ;Ch0 Ride cymbal 2
008D 3439 retlw 57 ;Ch1 Crash cymbal 2
008E 343A retlw 58 ;Ch2 Vibraslap
008F 3438 retlw 56 ;Ch3 Cow bell
0090 3436 retlw 54 ;Ch4 Tambourine
0091 3432 retlw 50 ;Ch5 Hi tom
0092 3430 retlw 48 ;Ch6 Hi hat open
0093 3427 retlw 39 ;Ch7 Hand clap
;Mapping 1
0094 3420 retlw 32 ;Ch0 Sticks
0095 3416 retlw 22 ;Ch1 Metronome bell
0096 341D retlw 29 ;Ch2 Snare roll
0097 3425 retlw 37 ;Ch3 Side stick
0098 3426 retlw 38 ;Ch4 Snare M
0099 342A retlw 42 ;Ch5 Hi hat closed
009A 341E retlw 30 ;Ch6 Castanet
009B 3412 retlw 18 ;Ch7 Scratch pull
;Mapping 2
009C 3414 retlw 20 ;Ch0 Click noise
009D 3413 retlw 19 ;Ch1 Finger snap
009E 3410 retlw 16 ;Ch2 Whip slap
009F 3419 retlw 25 ;Ch3 Brush tap
00A0 341A retlw 26 ;Ch4 Brush swirl
00A1 3422 retlw 34 ;Ch5 Open rim shot
00A2 3423 retlw 35 ;Ch6 Bass drum M
00A3 3424 retlw 36 ;Ch7 Bass drum H
;Mapping 3
00A4 3423 retlw 35 ;Ch0 Bass drum
00A5 3426 retlw 38 ;Ch1 Snare
00A6 342E retlw 46 ;Ch2 Hi hat open
00A7 3431 retlw 49 ;Ch3 Crash cymbal
00A8 3433 retlw 51 ;Ch4 Ride cymbal
00A9 3437 retlw 55 ;Ch5 Splash Cymbal
00AA 3429 retlw 41 ;Ch6 Floor Tom L
00AB 342B retlw 43 ;Ch7 Floor Tom H
end
Memory Usage Map ('X' = Used, '-' = Unused)
0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXX---- ----------------
43 Lables & Constants:-
Hex Name
0000 C
0002 PCL
0002 Z
0006 PORTB
0005 PORTA
0086 TRISB
0085 TRISA
0088 EECON1
000B INTCON
0008 EEDATA
0009 EEADR
0003 STATUS
0005 RP0
0001 INC
0002 cts
0003 rts
000C sBuf
000D Scount
000E Cdown
000F rBuf
0010 val
0011 chan
0012 Tcount
0013 Ccount
0001 Send
0005 Sloop
0013 cDelay
0016 hDelay
0019 rDelay
001C Delay
001E Dloop
0021 Start
0030 pml
0035 Main
0039 Ml
0044 conv
004A clop
0059 ilop
0066 ckd
0067 play
0069 sag
0081 hyst
008B map
0 Errors