gpasm-0.11.8 alpha synth2.asm 6-8-2004 12:55:44 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ; ._. .__. .____. .________. ._. 00002 ; _! !_! !__! !____! !________! !_ 00003 ; 00004 ; 8 channel cheapo midi -> cv converter 00005 ; ._. .__. .____. .________. 00006 ; ________! !_! !__! !____! !_____ 00007 00008 processor 16F84 00009 include 00001 LIST 00002 ; P16F84.INC Standard Header File, Version 2.00 Microchip Technology, Inc. 00136 LIST 002007 3FFB 00010 __config _WDT_OFF 00011 00000010 00012 random EQU 0x10 ; random state 00000011 00013 plen EQU 0x11 ; cycle len 00000012 00014 voicestate EQU 0x12 ; on/off 00000013 00015 midibyte EQU 0x13 00000014 00016 midifirst EQU 0x14 00000015 00017 midinote EQU 0x15 00000016 00018 midivelocity EQU 0x16 00000017 00019 temp EQU 0x17 00000018 00020 bitcount EQU 0x18 00000019 00021 vnote EQU 0x19 ; array for note nums [+8] 00000021 00022 vtime EQU 0x21 ; array for times [+8] 00000029 00023 voiceid EQU 0x29 00024 00000000 00025 midipin EQU 00 ; input pin 00000001 00026 mididebugpin EQU 01 00027 00028 ;--------------------------------- 00029 ; .-----------. .---- 00030 ; ! ! ! 00031 ; !<- vtime ->! ! 00032 ; ----' '---' 00033 ; TMR0 = 0...............0.... 00034 ; <--- plen ----> 00035 ;--------------------------------- 00036 0000 00037 main: 0000 3001 00038 movlw B'00000001' Warning [224] : Use of this instruction is not recommended. 0001 0065 00039 tris PORTA ; port a is mostly output 0002 3000 00040 movlw B'00000000' Warning [224] : Use of this instruction is not recommended. 0003 0066 00041 tris PORTB ; port b is output 00042 0004 3083 00043 movlw B'10000011' ; timer prescale /16 Warning [224] : Use of this instruction is not recommended. 0005 0062 00044 option 00045 00046 ; init stuff 0006 3004 00047 movlw D'4' 0007 0090 00048 movwf random gpasm-0.11.8 alpha synth2.asm 6-8-2004 12:55:44 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0008 307F 00049 movlw D'127' 0009 0091 00050 movwf plen 000A 0181 00051 clrf TMR0 000B 0192 00052 clrf voicestate 00053 00054 ; test... 00055 00056 ; movlw 0x90 00057 ; movwf midifirst 00058 ; movlw 0x40 00059 ; movwf midinote 00060 ; movlw 0x01 00061 ; movwf midivelocity 00062 ; 00063 ; call noteon 00064 ; 00065 ; movlw 0x92 00066 ; movwf midifirst 00067 ; movlw 0x01 00068 ; movwf midinote 00069 ; 00070 ; call noteon 00071 00072 ;--------------------------------- 00073 000C 00074 begin: 000C 2042 00075 call checkmidi 00076 000D 0801 00077 movf TMR0,w ; if timer has wrapped 000E 1D03 00078 btfss STATUS,Z 000F 2812 00079 goto carryon 0010 30FF 00080 movlw 0xff 0011 0086 00081 movwf PORTB ; clear all out pins 00082 ;incf plen,f 0012 00083 carryon: 00084 00085 ; update all outputs 00086 ; 1 0012 01A9 00087 clrf voiceid 0013 202A 00088 call updatepw 00089 00090 ; 2 0014 2042 00091 call checkmidi ; need to do this sporadically 0015 0AA9 00092 incf voiceid,f 0016 202A 00093 call updatepw 00094 00095 ; 3 0017 2042 00096 call checkmidi ; need to do this sporadically 0018 0AA9 00097 incf voiceid,f 0019 202A 00098 call updatepw 00099 00100 ; 4 001A 2042 00101 call checkmidi ; need to do this sporadically 001B 0AA9 00102 incf voiceid,f gpasm-0.11.8 alpha synth2.asm 6-8-2004 12:55:44 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 001C 202A 00103 call updatepw 00104 00105 ; 5 001D 2042 00106 call checkmidi ; need to do this sporadically 001E 0AA9 00107 incf voiceid,f 001F 202A 00108 call updatepw 00109 00110 ; 6 0020 2042 00111 call checkmidi ; need to do this sporadically 0021 0AA9 00112 incf voiceid,f 0022 202A 00113 call updatepw 00114 00115 ; 7 0023 2042 00116 call checkmidi ; need to do this sporadically 0024 0AA9 00117 incf voiceid,f 0025 202A 00118 call updatepw 00119 00120 ; 8 0026 2042 00121 call checkmidi ; need to do this sporadically 0027 0AA9 00122 incf voiceid,f 0028 202A 00123 call updatepw 00124 0029 280C 00125 goto begin 00126 002A 00127 updatepw: 00128 ; get the midi note 002A 3019 00129 movlw vnote ; copy vnotes base address 002B 0084 00130 movwf FSR ; to the fsr 002C 0818 00131 movf bitcount,w ; load the voice num 002D 0784 00132 addwf FSR,f ; add it to the fsr 002E 0800 00133 movf 0,w ; load the midi note 002F 0091 00134 movwf plen ; indirect address 00135 00136 ; try using the midi note as the pulsewidth 00137 ; can correct and tune in circuitry, but will 00138 ; this need to be logarithmic? 00139 0030 0D91 00140 rlf plen,f 0031 0D91 00141 rlf plen,f 0032 0D91 00142 rlf plen,f 00143 00144 ; is it time to flip? 0033 0801 00145 movf TMR0,w 0034 0211 00146 subwf plen,w 0035 1803 00147 btfsc STATUS,C 0036 0008 00148 return 00149 00150 ; set the right output bit 0037 0806 00151 movf PORTB,w 0038 20AB 00152 call clrbit 0039 0086 00153 movwf PORTB 00154 003A 0008 00155 return 00156 gpasm-0.11.8 alpha synth2.asm 6-8-2004 12:55:44 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00157 ;--------------------------------------------------------- 00158 ; dodgy 8 bit random 00159 003B 00160 rand: 003B 301D 00161 movlw 0x1d 003C 0790 00162 addwf random,f 003D 1003 00163 clrc 003E 0D90 00164 rlf random,f 003F 1803 00165 skpnc 0040 0690 00166 xorwf random,f 0041 3400 00167 retlw 0 00168 00169 ;------------------------------------------------------ 00170 ; check for, read and interpret a midi message 00171 0042 00172 checkmidi: 0042 1805 00173 btfsc PORTA,midipin ; is start bit low? 0043 3400 00174 retlw 0 00175 0044 207C 00176 call readmidibyte ; read first byte 0045 0813 00177 movf midibyte,w 0046 0094 00178 movwf midifirst 0047 207C 00179 call readmidibyte ; read note num 0048 0813 00180 movf midibyte,w 0049 0095 00181 movwf midinote 004A 207C 00182 call readmidibyte ; read velocity 004B 0813 00183 movf midibyte,w 004C 0096 00184 movwf midivelocity 00185 00186 ; check if it's a note on 004D 30F0 00187 movlw 0xf0 ; mask lower nibble out 004E 0514 00188 andwf midifirst,w 004F 3C90 00189 sublw 0x90 ; compare with note on 0050 1903 00190 btfsc STATUS,Z 0051 2858 00191 goto noteon 00192 00193 ; check if it's a note off 0052 30F0 00194 movlw 0xf0 ; mask lower nibble out 0053 0514 00195 andwf midifirst,w 0054 3C80 00196 sublw 0x80 ; compare with note off 0055 1903 00197 btfsc STATUS,Z 0056 286F 00198 goto noteoff 00199 00200 ; i don't understand this message 0057 3400 00201 retlw 0 00202 0058 00203 noteon: 0058 1485 00204 bsf PORTA,mididebugpin 00205 0059 0816 00206 movf midivelocity,w ; check for velocity=0 005A 1903 00207 btfsc STATUS,Z ; style note off (roland) 005B 286F 00208 goto noteoff 005C 0814 00209 movf midifirst,w ; get the channel num 005D 390F 00210 andlw 0x0f ; mask off the top nibble gpasm-0.11.8 alpha synth2.asm 6-8-2004 12:55:44 PAGE 5 LOC OBJECT CODE LINE SOURCE TEXT VALUE 005E 0098 00211 movwf bitcount ; setup bitcount 005F 0812 00212 movf voicestate,w ; set the state 0060 209C 00213 call setbit ; set the bit 0061 0092 00214 movwf voicestate 00215 0062 3019 00216 movlw vnote ; copy vnotes base address 0063 0084 00217 movwf FSR ; to the fsr 0064 0818 00218 movf bitcount,w ; load the voice num 0065 0784 00219 addwf FSR,f ; add it to the fsr 0066 0815 00220 movf midinote,w ; load the current midi note 0067 0080 00221 movwf 0 ; indirect address 00222 0068 3021 00223 movlw vtime ; get vtime base address 0069 0084 00224 movwf FSR ; copy it to the fsr 006A 0818 00225 movf bitcount,w ; load the voice num 006B 0784 00226 addwf FSR,f ; add it to the fsr 006C 3000 00227 movlw 0x00 ; load 0 006D 0080 00228 movwf 0 ; set it to be the time 00229 006E 3401 00230 retlw 1 00231 006F 00232 noteoff: 006F 1085 00233 bcf PORTA,mididebugpin 00234 0070 0814 00235 movf midifirst,w ; get the channel num 0071 390F 00236 andlw 0x0f ; mask off the top nibble 0072 0098 00237 movwf bitcount ; setup bitcount 0073 0812 00238 movf voicestate,w 0074 20AB 00239 call clrbit ; clear the bit 0075 0092 00240 movwf voicestate 00241 0076 3019 00242 movlw vnote ; copy vnotes base address 0077 0084 00243 movwf FSR ; to the fsr 0078 0818 00244 movf bitcount,w ; load the voice num 0079 0784 00245 addwf FSR,f ; add it to the fsr 007A 0180 00246 clrf 0 ; clear the midi note 00247 007B 3401 00248 retlw 1 00249 00250 ;------------------------------------------- 00251 ; low level byte reading for midi messages 00252 007C 00253 readmidibyte: 007C 3018 00254 movlw D'24' ; delay 73 clocks 007D 0097 00255 movwf temp ; | 007E 0B97 00256 decfsz temp,f ; | 007F 287E 00257 goto $-1 ; end delay 00258 0080 3008 00259 movlw D'8' ; read 8 bits 0081 0098 00260 movwf bitcount 00261 0082 00262 readbits: 0082 0C93 00263 rrf midibyte,f ; set up for the next bit 0083 1C05 00264 btfss PORTA,midipin gpasm-0.11.8 alpha synth2.asm 6-8-2004 12:55:44 PAGE 6 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0084 2888 00265 goto pad ; pad keeps proc time same 0085 1793 00266 bsf midibyte,7 0086 0000 00267 nop 0087 288B 00268 goto endread 0088 00269 pad: 0088 1393 00270 bcf midibyte,7 0089 0000 00271 nop 008A 0000 00272 nop 008B 00273 endread: 008B 3017 00274 movlw D'23' ; delay 008C 0097 00275 movwf temp ; before reading 008D 0B97 00276 decfsz temp,f ; next bit 008E 288D 00277 goto $-1 008F 0B98 00278 decfsz bitcount,f ; have we finished? 0090 2882 00279 goto readbits 0091 0000 00280 nop ; delay to ignore stop bit 0092 0000 00281 nop 0093 0000 00282 nop 0094 0000 00283 nop 0095 0000 00284 nop 0096 0000 00285 nop 0097 301A 00286 movlw D'26' ; delay 79 clocks: 2 + (25 * 3 + 1 * 2) 0098 0097 00287 movwf temp ; | 0099 0B97 00288 decfsz temp,f ; | 009A 2899 00289 goto $-1 ; end delay 009B 0008 00290 return 00291 00292 ;------------------------------------------ 00293 ; sets a bit of w given by bitselect 00294 ; is there a much simpler way with bsf i'm missing? 00295 ; could use rlf, but this is less instructions 00296 009C 00297 setbit: 009C 0097 00298 movwf temp 009D 0818 00299 movf bitcount,w 009E 20A2 00300 call settable 009F 0497 00301 iorwf temp,f 00A0 0817 00302 movf temp,w 00A1 0008 00303 return 00A2 00304 settable: 00A2 0782 00305 addwf 2,f 00A3 3401 00306 retlw B'00000001' 00A4 3402 00307 retlw B'00000010' 00A5 3404 00308 retlw B'00000100' 00A6 3408 00309 retlw B'00001000' 00A7 3410 00310 retlw B'00010000' 00A8 3420 00311 retlw B'00100000' 00A9 3440 00312 retlw B'01000000' 00AA 3480 00313 retlw B'10000000' 00314 00315 ;------------------------------------------ 00316 ; clear a bit of w given by bitselect 00AB 00317 clrbit: 00AB 0097 00318 movwf temp gpasm-0.11.8 alpha synth2.asm 6-8-2004 12:55:44 PAGE 7 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00AC 0818 00319 movf bitcount,w 00AD 20B1 00320 call clrtable 00AE 0597 00321 andwf temp,f 00AF 0817 00322 movf temp,w 00B0 0008 00323 return 00B1 00324 clrtable: 00B1 0782 00325 addwf 2,f 00B2 34FE 00326 retlw B'11111110' 00B3 34FD 00327 retlw B'11111101' 00B4 34FB 00328 retlw B'11111011' 00B5 34F7 00329 retlw B'11110111' 00B6 34EF 00330 retlw B'11101111' 00B7 34DF 00331 retlw B'11011111' 00B8 34BF 00332 retlw B'10111111' 00B9 347F 00333 retlw B'01111111' 00334 gpasm-0.11.8 alpha synth2.asm 6-8-2004 12:55:44 PAGE 8 SYMBOL TABLE LABEL VALUE C 00000000 DC 00000001 EEADR 00000009 EECON1 00000088 EECON2 00000089 EEDATA 00000008 EEIE 00000006 EEIF 00000004 F 00000001 FSR 00000004 GIE 00000007 INDF 00000000 INTCON 0000000B INTE 00000004 INTEDG 00000006 INTF 00000001 IRP 00000007 NOT_PD 00000003 NOT_RBPU 00000007 NOT_TO 00000004 OPTION_REG 00000081 PCL 00000002 PCLATH 0000000A PORTA 00000005 PORTB 00000006 PS0 00000000 PS1 00000001 PS2 00000002 PSA 00000003 RBIE 00000003 RBIF 00000000 RD 00000000 RP0 00000005 RP1 00000006 STATUS 00000003 T0CS 00000005 T0IE 00000005 T0IF 00000002 T0SE 00000004 TMR0 00000001 TRISA 00000085 TRISB 00000086 W 00000000 WR 00000001 WREN 00000002 WRERR 00000003 Z 00000002 _CP_OFF 00003FFF _CP_ON 0000000F _HS_OSC 00003FFE _LP_OSC 00003FFC _PWRTE_OFF 00003FFF _PWRTE_ON 00003FF7 gpasm-0.11.8 alpha synth2.asm 6-8-2004 12:55:44 PAGE 9 LOC OBJECT CODE LINE SOURCE TEXT VALUE _RC_OSC 00003FFF _WDT_OFF 00003FFB _WDT_ON 00003FFF _XT_OSC 00003FFD __16F84 00000001 begin 0000000C bitcount 00000018 carryon 00000012 checkmidi 00000042 clrbit 000000AB clrtable 000000B1 endread 0000008B main 00000000 midibyte 00000013 mididebugpin 00000001 midifirst 00000014 midinote 00000015 midipin 00000000 midivelocity 00000016 noteoff 0000006F noteon 00000058 pad 00000088 plen 00000011 rand 0000003B random 00000010 readbits 00000082 readmidibyte 0000007C setbit 0000009C settable 000000A2 temp 00000017 updatepw 0000002A vnote 00000019 voiceid 00000029 voicestate 00000012 vtime 00000021 MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXX------ 2000 : -------X-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 187 Errors : 0 Warnings : 3 reported, 0 suppressed Messages : 0 reported, 0 suppressed