gpasm-0.11.8 alpha rhythm-seq.asm11-9-2003 02:45:46 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ; CPU configuration 00002 processor 16f84 00003 include 00001 LIST 00002 ; P16F84.INC Standard Header File, Version 2.00 Microchip Technology, Inc. 00136 LIST 002007 3FF2 00004 __config _HS_OSC & _WDT_OFF & _PWRTE_ON 00005 00006 ; memory map 00007 ; ---------- 00008 ; 20 time <- start 00009 ; 21 length 00010 ; ... 00011 ; 40 map 1 size <- event maps 00012 ; } map 1 events 00013 ; 50 map 2 size 00014 ; } map 2 events 00015 ; 60 ... 00016 00017 #define NO_MAPS 2 00018 #define MAP_SIZE 16 00019 #define MAP_START 40 00020 00000020 00021 time equ H'20' 00000021 00022 length equ H'21' 00000022 00023 curmap equ H'22' 00000023 00024 pressed equ H'23' 00025 00026 ; Program 00027 0000 00028 start: 0000 3000 00029 movlw B'00000000' Warning [224] : Use of this instruction is not recommended. 0001 0065 00030 tris PORTA ; init port A as output 0002 30FF 00031 movlw B'11111111' Warning [224] : Use of this instruction is not recommended. 0003 0066 00032 tris PORTB ; init port B as input 0004 1505 00033 bsf PORTA, 0x02 ; init midi out pin state 00034 00035 ; init 0005 01A0 00036 clrf time 0006 01A2 00037 clrf curmap 0007 01A3 00038 clrf pressed 0008 300A 00039 movlw D'10' 0009 00A1 00040 movwf length 00041 00042 000A 00043 mainloop: Message [305] : Using default destination of 1 (file). 000A 0AA0 00044 incf time ; increment time 000B 0821 00045 movf length, w ; load the total length 000C 0220 00046 subwf time,w ; time-length 000D 1803 00047 skpnc ; skip on no carry 000E 01A0 00048 clrf time ; reset clock to start of loop gpasm-0.11.8 alpha rhythm-seq.asm11-9-2003 02:45:46 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00049 00050 ; check button 00051 ; set event if necc 00052 ; check maps 000F 280A 00053 goto mainloop 00054 00055 00056 00057 00058 ;---------------------------------------------------------------- 00059 00060 ; put an event in the current map 0010 00061 recevent: 0010 0008 00062 return 00063 00064 ;---------------------------------------------------------------- 00065 00066 ; send a midi event if the time is right, checking all maps 0011 00067 sendevents: 0011 0008 00068 return 00069 00070 ;---------------------------------------------------------------- 00071 ; send a midi event now! 0012 00072 send: 0012 3090 00073 movlw 0x90 ; note on, channel 1 0013 009D 00074 movwf xmit 0014 2029 00075 call sendmidi 00076 0015 303C 00077 movlw 0x3C ; middle C 0016 009D 00078 movwf xmit 0017 2029 00079 call sendmidi 00080 0018 307F 00081 movlw 0x7F ; velocity 127 0019 009D 00082 movwf xmit 001A 2029 00083 call sendmidi 00084 00085 ; movlw 0x80 ; note off, channel 1 00086 ; movwf xmit 00087 ; call sendmidi 00088 00089 ; movlw 0x3C ; middle C 00090 ; movwf xmit 00091 ; call sendmidi 00092 00093 ; movlw 0x7F ; velocity 127 00094 ; movwf xmit 00095 ; call sendmidi 00096 001B 0008 00097 return 00098 00099 ;---------------------------------------------------------------------- 00100 00101 ; secdelay delays for one second ( 2500000 instructions ) 00102 ; kloop = (2 + 254 * 3 + 1 * 2) = 766 gpasm-0.11.8 alpha rhythm-seq.asm11-9-2003 02:45:46 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00103 ; jloop = 2 + kloop * 255 + (3 * 254 + 1 * 2) = 196096 00104 ; iloop = 2 + jloop * 13 + (3*254 + 1*2) = 2550014 = 1.02 seconds 00105 ; x = 001C 00106 secdelay: 001C 300D 00107 movlw D'13' 001D 009C 00108 movwf i 001E 30FF 00109 iloop: movlw D'255' 001F 009B 00110 movwf j 0020 30FF 00111 jloop: movlw D'255' 0021 009A 00112 movwf k 0022 0B9A 00113 kloop: decfsz k,f 0023 2822 00114 goto kloop 0024 0B9B 00115 decfsz j,f 0025 2820 00116 goto jloop 0026 0B9C 00117 decfsz i,f 0027 281E 00118 goto iloop 0028 0008 00119 return 00120 00121 00122 include "midi.inc" 00001 ; Assembly code for a 10MHz PIC16F84 microcontroller 00002 ; Modified from work by Ross Bencina 00003 0000001F 00004 temp equ H'1F' 0000001D 00005 xmit equ H'1D' 0000001C 00006 i equ H'1C' 0000001B 00007 j equ H'1B' 0000001A 00008 k equ H'1A' 00009 00010 ; sendmidi transmits one midi byte on RA2 00011 ; at 10mhz there are 80 instructions per midi bit 00012 ; xmit contains byte to send 00013 ; * this should be rewritten to support variable delays for 00014 ; * different clock speeds 00015 0029 00016 sendmidi: 00017 0029 1105 00018 startb: bcf PORTA, 0x02 ; start bit 00019 002A 3018 00020 movlw D'24' ; delay 73 clocks: 2 + (23 * 3 + 1 * 2) 002B 009F 00021 movwf temp ; | 002C 0B9F 00022 loop1: decfsz temp,f ; | 002D 282C 00023 goto loop1 ; end delay 00024 002E 3008 00025 movlw D'8' 002F 009B 00026 movwf j 00027 0030 00028 sendloop: ; executes 5 instuctions before setting bit 0030 0C9D 00029 rrf xmit,f 0031 1803 00030 btfsc STATUS, C 0032 2836 00031 goto send1 00032 ; remember midi bits are opposite from our representation 0033 0000 00033 send0: nop 0034 1105 00034 bcf PORTA, 0x02 ;send a 0 bit gpasm-0.11.8 alpha rhythm-seq.asm11-9-2003 02:45:46 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0035 2839 00035 goto endloop 00036 0036 1505 00037 send1: bsf PORTA, 0x02 ;send a 1 bit 0037 0000 00038 nop 0038 0000 00039 nop 00040 0039 00041 endloop: ; 00042 0039 3017 00043 movlw D'23' ;delay 70 instructions 2 + (22 * 3 + 1 * 2) 003A 009F 00044 movwf temp ; | 003B 0B9F 00045 loop2: decfsz temp,f ; | 003C 283B 00046 goto loop2 ; end delay 00047 003D 0B9B 00048 decfsz j,f ; 003E 2830 00049 goto sendloop 00050 003F 00051 stopb: 003F 0000 00052 nop 0040 0000 00053 nop 0041 0000 00054 nop 0042 0000 00055 nop 0043 0000 00056 nop 0044 1505 00057 bsf PORTA, 0x02 ; stop bit 0045 301A 00058 movlw D'26' ; delay 79 clocks: 2 + (25 * 3 + 1 * 2) 0046 009F 00059 movwf temp ; | 0047 0B9F 00060 loop3: decfsz temp,f ; | 0048 2847 00061 goto loop3 ; end delay 00062 0049 0008 00063 return 00064 00123 gpasm-0.11.8 alpha rhythm-seq.asm11-9-2003 02:45:46 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 rhythm-seq.asm11-9-2003 02:45:46 PAGE 6 LOC OBJECT CODE LINE SOURCE TEXT VALUE _RC_OSC 00003FFF _WDT_OFF 00003FFB _WDT_ON 00003FFF _XT_OSC 00003FFD __16F84 00000001 curmap 00000022 endloop 00000039 i 0000001C iloop 0000001E j 0000001B jloop 00000020 k 0000001A kloop 00000022 length 00000021 loop1 0000002C loop2 0000003B loop3 00000047 mainloop 0000000A pressed 00000023 recevent 00000010 secdelay 0000001C send 00000012 send0 00000033 send1 00000036 sendevents 00000011 sendloop 00000030 sendmidi 00000029 start 00000000 startb 00000029 stopb 0000003F temp 0000001F time 00000020 xmit 0000001D MAP_SIZE 16 MAP_START 40 NO_MAPS 2 MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXX------ ---------------- ---------------- ---------------- 2000 : -------X-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 75 Errors : 0 Warnings : 2 reported, 0 suppressed Messages : 1 reported, 0 suppressed