gpasm-0.11.8 alpha logimidi2.asm2-24-2004 10:39:31 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 00002 ; nebogeo corporation ltd 2004 00003 00004 ; CPU configuration 00005 processor 16f84 00006 include 00001 LIST 00002 ; P16F84.INC Standard Header File, Version 2.00 Microchip Technology, Inc. 00136 LIST 002007 3FF2 00007 __config _HS_OSC & _WDT_OFF & _PWRTE_ON 00008 0000002F 00009 temp equ H'2F' 0000002D 00010 xmit equ H'2D' 0000002C 00011 i equ H'2C' 0000002B 00012 j equ H'2B' 0000002A 00013 k equ H'2A' 00014 00000040 00015 state equ H'40' ; state of the pins 00000041 00016 note equ H'41' ; current note, offset from root 00000042 00017 root equ H'42' ; root note 00000043 00018 pin equ H'43' ; current pin for testing 00019 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 0185 00025 clrf PORTA 0001 3000 00026 movlw B'00000000' Warning [224] : Use of this instruction is not recommended. 0002 0065 00027 tris PORTA ; init port A as output 0003 0186 00028 clrf PORTB 0004 30FF 00029 movlw B'11111111' Warning [224] : Use of this instruction is not recommended. 0005 0066 00030 tris PORTB ; init port B as input 0006 1505 00031 bsf PORTA, 0x02 ; init midi out pin state 0007 01AF 00032 clrf temp 0008 01AD 00033 clrf xmit 00034 ;clrf state ; init state 0009 01C1 00035 clrf note ; init start note 000A 01C3 00036 clrf pin ; init pin 000B 303C 00037 movlw 0x3C 000C 00C2 00038 movwf root ; set root to middle C 00039 000D 00040 mainloop: 00041 ; clrf note 00042 00043 ; movlw B'00000001' 00044 ; movwf pin 00045 ; call checkinput 00046 ; incf note,f 00047 000D 0806 00048 movf PORTB,w 000E 0085 00049 movwf PORTA gpasm-0.11.8 alpha logimidi2.asm2-24-2004 10:39:31 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00050 000F 2037 00051 call delay 00052 00053 ; movlw B'00000010' 00054 ; movwf pin 00055 ; call checkinput 00056 ; incf note,f 00057 00058 ; movlw B'00000100' 00059 ; movwf pin 00060 ; call checkinput 00061 ; incf note,f 00062 00063 ; movlw B'00001000' 00064 ; movwf pin 00065 ; call checkinput 00066 ; incf note,f 00067 0010 280D 00068 goto mainloop 00069 00070 ;---------------------------------------------------------------- 00071 0011 00072 checkinput: 0011 0843 00073 movf pin,w ; load pin value 0012 0540 00074 andwf state,w ; and with status 0013 1D03 00075 btfss STATUS,Z ; if result is zero, pin status is is zero, do next 0014 2826 00076 goto checkforclear ; we are waiting to send a note off 00077 00078 ; check to see if there is a signal on this pin 00079 ; we are waiting to send a note on 0015 0806 00080 movf PORTB,w 0016 0543 00081 andwf pin,w ; and pin to check and input status 0017 1903 00082 btfsc STATUS,Z ; skip if pin is set 0018 0008 00083 return 00084 00085 ; bsf PORTA,0x01 00086 00087 ; we have a signal, so send a note on 0019 3090 00088 movlw 0x90 ; note on, channel 1 001A 00AD 00089 movwf xmit 001B 2044 00090 call sendmidi 001C 0842 00091 movf root,w ; get the root note 001D 0741 00092 addwf note,w ; add the current note 001E 00AD 00093 movwf xmit 001F 2044 00094 call sendmidi 0020 307F 00095 movlw 0x7F ; velocity 127 0021 00AD 00096 movwf xmit 0022 2044 00097 call sendmidi 00098 00099 ; bcf PORTA,0x01 00100 0023 0843 00101 movf pin,w 0024 04C0 00102 iorwf state,f ; set the state for this pin 0025 0008 00103 return gpasm-0.11.8 alpha logimidi2.asm2-24-2004 10:39:31 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00104 0026 00105 checkforclear: 00106 ; check to see if the signal has gone low on this pin 00107 ; we are waiting to send a note off 0026 0806 00108 movf PORTB,w ; load input value 0027 0543 00109 andwf pin,w ; and with our pin 0028 1D03 00110 btfss STATUS,Z ; skip if pin is clear 0029 0008 00111 return 00112 00113 ; bcf PORTA,0x01 00114 00115 ; we have no signal now, so send a note off 002A 3080 00116 movlw 0x80 ; note off, channel 1 002B 00AD 00117 movwf xmit 002C 2044 00118 call sendmidi 002D 0842 00119 movf root,w ; get the root note 002E 0741 00120 addwf note,w ; add the current note 002F 00AD 00121 movwf xmit 0030 2044 00122 call sendmidi 0031 3000 00123 movlw 0x0 ; velocity 0 0032 00AD 00124 movwf xmit 0033 2044 00125 call sendmidi 00126 00127 ; bcf PORTA,0x01 00128 0034 0843 00129 movf pin,w 0035 06C0 00130 xorwf state,f ; clear the state for this pin 0036 0008 00131 return 00132 00133 ; delay 0037 00134 delay: 0037 3001 00135 movlw D'1' 0038 00AC 00136 movwf i 0039 30FF 00137 iloop: movlw D'255' 003A 00AB 00138 movwf j 003B 300A 00139 jloop: movlw D'10' 003C 00AA 00140 movwf k 003D 0BAA 00141 kloop: decfsz k,f 003E 283D 00142 goto kloop 003F 0BAB 00143 decfsz j,f 0040 283B 00144 goto jloop 0041 0BAC 00145 decfsz i,f 0042 2839 00146 goto iloop 0043 0008 00147 return 00148 00149 ;---------------------------------------------------------------- 00150 ; many thanks to Ross Bencina for this function (and portaudio) 00151 ; sendmidi transmits one midi byte on RA2 00152 ; at 10mhz there are 80 instructions per midi bit 00153 ; xmit contains byte to send 00154 ; * this should be rewritten to support variable delays for 00155 ; * different clock speeds 00156 0044 00157 sendmidi: gpasm-0.11.8 alpha logimidi2.asm2-24-2004 10:39:31 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00158 0044 1105 00159 startb: bcf PORTA, 0x02 ; start bit 00160 0045 3018 00161 movlw D'24' ; delay 73 clocks: 2 + (23 * 3 + 1 * 2) 0046 00AF 00162 movwf temp ; | 0047 0BAF 00163 loop1: decfsz temp,f ; | 0048 2847 00164 goto loop1 ; end delay 00165 0049 3008 00166 movlw D'8' 004A 00AB 00167 movwf j 00168 004B 00169 sendloop: ; executes 5 instuctions before setting bit 004B 0CAD 00170 rrf xmit,f 004C 1803 00171 btfsc STATUS, C 004D 2851 00172 goto send1 00173 ; remember midi bits are opposite from our representation 004E 0000 00174 send0: nop 004F 1105 00175 bcf PORTA, 0x02 ;send a 0 bit 0050 2854 00176 goto endloop 00177 0051 1505 00178 send1: bsf PORTA, 0x02 ;send a 1 bit 0052 0000 00179 nop 0053 0000 00180 nop 00181 0054 00182 endloop: ; 00183 0054 3017 00184 movlw D'23' ;delay 70 instructions 2 + (22 * 3 + 1 * 2) 0055 00AF 00185 movwf temp ; | 0056 0BAF 00186 loop2: decfsz temp,f ; | 0057 2856 00187 goto loop2 ; end delay 00188 0058 0BAB 00189 decfsz j,f ; 0059 284B 00190 goto sendloop 00191 005A 00192 stopb: 005A 0000 00193 nop 005B 0000 00194 nop 005C 0000 00195 nop 005D 0000 00196 nop 005E 0000 00197 nop 005F 1505 00198 bsf PORTA, 0x02 ; stop bit 0060 301A 00199 movlw D'26' ; delay 79 clocks: 2 + (25 * 3 + 1 * 2) 0061 00AF 00200 movwf temp ; | 0062 0BAF 00201 loop3: decfsz temp,f ; | 0063 2862 00202 goto loop3 ; end delay 00203 0064 0008 00204 return 00205 gpasm-0.11.8 alpha logimidi2.asm2-24-2004 10:39:31 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 logimidi2.asm2-24-2004 10:39:31 PAGE 6 LOC OBJECT CODE LINE SOURCE TEXT VALUE _RC_OSC 00003FFF _WDT_OFF 00003FFB _WDT_ON 00003FFF _XT_OSC 00003FFD __16F84 00000001 checkforclear 00000026 checkinput 00000011 delay 00000037 endloop 00000054 i 0000002C iloop 00000039 j 0000002B jloop 0000003B k 0000002A kloop 0000003D loop1 00000047 loop2 00000056 loop3 00000062 mainloop 0000000D note 00000041 pin 00000043 root 00000042 send0 0000004E send1 00000051 sendloop 0000004B sendmidi 00000044 start 00000000 startb 00000044 state 00000040 stopb 0000005A temp 0000002F xmit 0000002D NUM_NOTES 5 MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXX----------- ---------------- 2000 : -------X-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 102 Errors : 0 Warnings : 2 reported, 0 suppressed Messages : 0 reported, 0 suppressed