gpasm-0.11.8 alpha logimidi.asm12-6-2003 23:25:05 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ; nebogeo corporation ltd 2004 00002 00003 ; CPU configuration 00004 processor 16f84 00005 include 00001 LIST 00002 ; P16F84.INC Standard Header File, Version 2.00 Microchip Technology, Inc. 00136 LIST 002007 3FF2 00006 __config _HS_OSC & _WDT_OFF & _PWRTE_ON 00007 0000001F 00008 temp equ H'1F' 0000001D 00009 xmit equ H'1D' 0000001C 00010 i equ H'1C' 0000001B 00011 j equ H'1B' 0000001A 00012 k equ H'1A' 00013 00000020 00014 state equ H'20' ; state of the pins 00000021 00015 note equ H'21' ; current note, offset from root 00000022 00016 root equ H'22' ; root note 00000023 00017 pin equ H'23' ; current pin for testing 00018 00019 #define PIN 1 ; input pin 00020 #define NUM_NOTES 5 ; number of notes in the sequence 00021 0000 00022 org 0 ; start at address 0 00023 0000 00024 start: 0000 3000 00025 movlw B'00000000' Warning [224] : Use of this instruction is not recommended. 0001 0065 00026 tris PORTA ; init port A as output 0002 30FF 00027 movlw B'11111111' Warning [224] : Use of this instruction is not recommended. 0003 0066 00028 tris PORTB ; init port B as input 0004 1505 00029 bsf PORTA, 0x02 ; init midi out pin state 0005 01A0 00030 clrf state ; init state 0006 3005 00031 movlw NUM_NOTES 0007 00A1 00032 movwf note ; init start note 0008 303C 00033 movlw 0x3C 0009 00A2 00034 movwf root ; set root to middle C 00035 000A 00036 mainloop: 000A 2033 00037 call delay 000B 3001 00038 movlw B'00000001' ; checking pin one only for now 000C 00A3 00039 movwf pin 000D 200F 00040 call checkinput 000E 280A 00041 goto mainloop 00042 00043 ;---------------------------------------------------------------- 00044 000F 00045 checkinput: 000F 18A0 00046 btfsc state,PIN ; skip if the state for this pin is clear 0010 2825 00047 goto checkforclear ; we are waiting to send a note off 00048 00049 ; check to see if there is a signal on this pin gpasm-0.11.8 alpha logimidi.asm12-6-2003 23:25:05 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00050 ; we are waiting to send a note on 0011 1C86 00051 btfss PORTB,PIN ; skip if the pin is set 0012 0008 00052 return 00053 0013 03A1 00054 decf note,f ; dec the current note 0014 0821 00055 movf note,w 0015 1D03 00056 btfss STATUS,Z ; if it's reached zero, skip 0016 2819 00057 goto skipreset ; skip the note reset 00058 0017 3005 00059 movlw NUM_NOTES 0018 00A1 00060 movwf note ; init start note 00061 0019 00062 skipreset: 00063 00064 ; we have a signal, so send a note on 0019 3090 00065 movlw 0x90 ; note on, channel 1 001A 009D 00066 movwf xmit 001B 2040 00067 call sendmidi 001C 0822 00068 movf root,w ; get the root note 001D 0721 00069 addwf note,w ; add the current note 001E 009D 00070 movwf xmit 001F 2040 00071 call sendmidi 0020 307F 00072 movlw 0x7F ; velocity 127 0021 009D 00073 movwf xmit 0022 2040 00074 call sendmidi 00075 0023 14A0 00076 bsf state,PIN ; set the state for this pin 0024 0008 00077 return 00078 0025 00079 checkforclear: 00080 ; check to see if the signal has gone low on this pin 00081 ; we are waiting to send a note off 0025 1886 00082 btfsc PORTB,PIN ; skip if the pin is clear 0026 0008 00083 return 00084 00085 ; we have no signal now, so send a note off 0027 3080 00086 movlw 0x80 ; note off, channel 1 0028 009D 00087 movwf xmit 0029 2040 00088 call sendmidi 002A 0822 00089 movf root,w ; get the root note 002B 0721 00090 addwf note,w ; add the current note 002C 009D 00091 movwf xmit 002D 2040 00092 call sendmidi 002E 3000 00093 movlw 0x0 ; velocity 0 002F 009D 00094 movwf xmit 0030 2040 00095 call sendmidi 00096 0031 10A0 00097 bcf state,PIN ; clear the state for this pin 0032 0008 00098 return 00099 00100 00101 ; delay 0033 00102 delay: 0033 300D 00103 movlw D'13' gpasm-0.11.8 alpha logimidi.asm12-6-2003 23:25:05 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0034 009C 00104 movwf i 0035 30FF 00105 iloop: movlw D'255' 0036 009B 00106 movwf j 0037 300A 00107 jloop: movlw D'10' 0038 009A 00108 movwf k 0039 0B9A 00109 kloop: decfsz k,f 003A 2839 00110 goto kloop 003B 0B9B 00111 decfsz j,f 003C 2837 00112 goto jloop 003D 0B9C 00113 decfsz i,f 003E 2835 00114 goto iloop 003F 0008 00115 return 00116 00117 ;---------------------------------------------------------------- 00118 ; many thanks to Ross Bencina for this function (and portaudio) 00119 ; sendmidi transmits one midi byte on RA2 00120 ; at 10mhz there are 80 instructions per midi bit 00121 ; xmit contains byte to send 00122 ; * this should be rewritten to support variable delays for 00123 ; * different clock speeds 00124 0040 00125 sendmidi: 00126 0040 1105 00127 startb: bcf PORTA, 0x02 ; start bit 00128 0041 3018 00129 movlw D'24' ; delay 73 clocks: 2 + (23 * 3 + 1 * 2) 0042 009F 00130 movwf temp ; | 0043 0B9F 00131 loop1: decfsz temp,f ; | 0044 2843 00132 goto loop1 ; end delay 00133 0045 3008 00134 movlw D'8' 0046 009B 00135 movwf j 00136 0047 00137 sendloop: ; executes 5 instuctions before setting bit 0047 0C9D 00138 rrf xmit,f 0048 1803 00139 btfsc STATUS, C 0049 284D 00140 goto send1 00141 ; remember midi bits are opposite from our representation 004A 0000 00142 send0: nop 004B 1105 00143 bcf PORTA, 0x02 ;send a 0 bit 004C 2850 00144 goto endloop 00145 004D 1505 00146 send1: bsf PORTA, 0x02 ;send a 1 bit 004E 0000 00147 nop 004F 0000 00148 nop 00149 0050 00150 endloop: ; 00151 0050 3017 00152 movlw D'23' ;delay 70 instructions 2 + (22 * 3 + 1 * 2) 0051 009F 00153 movwf temp ; | 0052 0B9F 00154 loop2: decfsz temp,f ; | 0053 2852 00155 goto loop2 ; end delay 00156 0054 0B9B 00157 decfsz j,f ; gpasm-0.11.8 alpha logimidi.asm12-6-2003 23:25:05 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0055 2847 00158 goto sendloop 00159 0056 00160 stopb: 0056 0000 00161 nop 0057 0000 00162 nop 0058 0000 00163 nop 0059 0000 00164 nop 005A 0000 00165 nop 005B 1505 00166 bsf PORTA, 0x02 ; stop bit 005C 301A 00167 movlw D'26' ; delay 79 clocks: 2 + (25 * 3 + 1 * 2) 005D 009F 00168 movwf temp ; | 005E 0B9F 00169 loop3: decfsz temp,f ; | 005F 285E 00170 goto loop3 ; end delay 00171 0060 0008 00172 return 00173 gpasm-0.11.8 alpha logimidi.asm12-6-2003 23:25:05 PAGE 5 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 logimidi.asm12-6-2003 23:25:05 PAGE 6 LOC OBJECT CODE LINE SOURCE TEXT VALUE _RC_OSC 00003FFF _WDT_OFF 00003FFB _WDT_ON 00003FFF _XT_OSC 00003FFD __16F84 00000001 checkforclear 00000025 checkinput 0000000F delay 00000033 endloop 00000050 i 0000001C iloop 00000035 j 0000001B jloop 00000037 k 0000001A kloop 00000039 loop1 00000043 loop2 00000052 loop3 0000005E mainloop 0000000A note 00000021 pin 00000023 root 00000022 send0 0000004A send1 0000004D sendloop 00000047 sendmidi 00000040 skipreset 00000019 start 00000000 startb 00000040 state 00000020 stopb 00000056 temp 0000001F xmit 0000001D NUM_NOTES 5 PIN 1 MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX X--------------- ---------------- 2000 : -------X-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 98 Errors : 0 Warnings : 2 reported, 0 suppressed Messages : 0 reported, 0 suppressed