jam_007
member
คะแนน 1
ออฟไลน์
กระทู้: 30
|
|
« ตอบ #8 เมื่อ: เมษายน 21, 2010, 09:39:38 am » |
|
code program asm ครับ
;***************************************** ; Program to tx MIDI data with 10Mhz clock ; MIDI Drum-Pads POLYPHONIC ; NOTE MIDI: ; 099h note-on channel 10 "09=on 9=ch10" ; 089h note-off channel 10 "08=off 9=ch10" ; 097h note-on channel 8 "09=on 7=ch8" ; 087h note-off channel 8 "08=off 7=ch8" ; ; 07fh max velocity "0-127" (06e=110) ; ; RA0=out midi ; PA1=down mode PA2=up mode PA3=MidiCh PA4=store ; ; rel1.3 22 02 2003 ;*****************************************
PROCESSOR 16f84a RADIX hex INCLUDE "P16F84a.INC" ERRORLEVEL -302 ERRORLEVEL -305 __CONFIG 3FFAH
;***************************************** ; Port Assignments ;*****************************************
PCL equ 0x02 STATUS equ 0x03 PORTA equ 0x05 PORTB equ 0x06
;***************************************** ; Variable Assignment Addresses ;***************************************** dlyreg equ 0x0C xcount equ 0x0D xmtreg equ 0x0E delay1 equ 0x0F count equ 0x10 drum equ 0x11 ;store ee ch_now equ 0x12 ;channel midi 0=10 1=08 ch_comp equ 0x13 ;compare for skip value equ 0x14 ;input pressed value1 equ 0x15 value2 equ 0x16 ;input for map ee delay equ 0x17 ;delay drumpad pressed
drum0 equ 0x18 drum1 equ 0x19 drum2 equ 0x1A drum3 equ 0x1B drum4 equ 0x1C drum5 equ 0x1D drum6 equ 0x1E drum7 equ 0x1F
;***************************************** ; Variable drum sound ;***************************************** snd00 equ 0x20 snd01 equ 0x21 snd02 equ 0x22 snd03 equ 0x23 snd04 equ 0x24 snd05 equ 0x25 snd06 equ 0x26 snd07 equ 0x27 Tx_FE equ 0x28 Tx_FF equ 0x29
;***************************************** ; PROGRAM Reset Point ;*****************************************
org 0x00 goto INIT
;***************************************** ; map new sound ;*****************************************
convert addwf PCL nop goto convert0 goto convert1 goto convert2 goto convert3 goto convert4 goto convert5 goto convert6 goto convert7
convert0 movf snd00,w return convert1 movf snd01,w return convert2 movf snd02,w return convert3 movf snd03,w return convert4 movf snd04,w return convert5 movf snd05,w return convert6 movf snd06,w return convert7 movf snd07,w return
;************************************* ; drive for call sound ;*************************************
dr_pad clrf count drum? incf count,F rrf value btfss STATUS,C goto drum? movf count,W call convert movwf drum return
;***************************************** ; Initialise Software ;***************************************** INIT bsf STATUS,RP0 clrf PORTA movlw 0x1E ;xxx11110b bit0=out movwf TRISA clrf PORTB movlw 0xFF ;11111111b movwf TRISB bcf STATUS,RP0 bsf PORTA,0
;***************************************** ; Recall EEp memory ;*****************************************
Rd_ee00 bcf STATUS,RP0 ;read the sndmap from eeprom movlw 0x00 movwf EEADR bsf STATUS,RP0 bsf EECON1,0x00 bcf STATUS,RP0 movf EEDATA,W movwf snd00
Rd_ee01 bcf STATUS,RP0 movlw 0x01 movwf EEADR bsf STATUS,RP0 bsf EECON1,0x00 bcf STATUS,RP0 movf EEDATA,W movwf snd01
Rd_ee02 bcf STATUS,RP0 movlw 0x02 movwf EEADR bsf STATUS,RP0 bsf EECON1,0x00 bcf STATUS,RP0 movf EEDATA,W movwf snd02
Rd_ee03 bcf STATUS,RP0 movlw 0x03 movwf EEADR bsf STATUS,RP0 bsf EECON1,0x00 bcf STATUS,RP0 movf EEDATA,W movwf snd03
Rd_ee04 bcf STATUS,RP0 movlw 0x04 movwf EEADR bsf STATUS,RP0 bsf EECON1,0x00 bcf STATUS,RP0 movf EEDATA,W movwf snd04
Rd_ee05 bcf STATUS,RP0 movlw 0x05 movwf EEADR bsf STATUS,RP0 bsf EECON1,0x00 bcf STATUS,RP0 movf EEDATA,W movwf snd05
Rd_ee06 bcf STATUS,RP0 movlw 0x06 movwf EEADR bsf STATUS,RP0 bsf EECON1,0x00 bcf STATUS,RP0 movf EEDATA,W movwf snd06
Rd_ee07 bcf STATUS,RP0 movlw 0x07 movwf EEADR bsf STATUS,RP0 bsf EECON1,0x00 bcf STATUS,RP0 movf EEDATA,W movwf snd07
;***************************************** ; Main Programme Start ;***************************************** main clrf PORTB movf PORTA,W andlw 0x0E ;in PORTA1;2;3;B00001110 btfss STATUS,Z call select btfsc PORTA,4 ;pa4 only store call ee_rec
movf PORTB,W main_1 movwf value ;from value the input pressed movwf value1 xorlw 0x00 btfsc STATUS,Z goto tx_fe goto tx_nn tx_fe decfsz Tx_FE goto main decfsz Tx_FF goto main movlw 0xFE ;on line FE movwf xmtreg call txmidi movlw 0x7F ;127x2 = ca500ms movwf Tx_FE movwf Tx_FF goto main
tx_nn movf value1,w movwf value2 ;store ee andlw 0x01 movwf value btfsc value,0 call dr_pad movwf drum0 movf value1,w andlw 0x02 movwf value btfsc value,1 call dr_pad movwf drum1
movf value1,w andlw 0x04 movwf value btfsc value,2 call dr_pad movwf drum2
movf value1,w andlw 0x08 movwf value btfsc value,3 call dr_pad movwf drum3
movf value1,w andlw 0x10 movwf value btfsc value,4 call dr_pad movwf drum4
movf value1,w andlw 0x20 movwf value btfsc value,5 call dr_pad movwf drum5
movf value1,w andlw 0x40 movwf value btfsc value,6 call dr_pad movwf drum6
movf value1,w andlw 0x80 movwf value btfsc value,7 call dr_pad movwf drum7 ;************************************* ; Select bit midi channel and go tx ;*************************************
play btfsc ch_now,0 ;selection channel midi 8-10 goto nch10 ;if0 goto goto nch08 ;if1 goto
nch10 call noteon0 call noteoff0 goto main
nch08 call noteon1 call noteoff1 goto main
;***************************************** ; note-on subroutine ;*****************************************
noteon0 movlw 099h ;note-on ch10 movwf xmtreg call txmidi goto laston
noteon1 movlw 097h ;note-on ch8 movwf xmtreg call txmidi goto laston
laston movf drum0,W ;drum note1 xorlw 0x00 btfsc STATUS,Z goto l1 movwf xmtreg call txmidi
movlw 06eh ;max velocity1 movwf xmtreg call txmidi
l1 movf drum1,W ;drum note2 xorlw 0x00 btfsc STATUS,Z goto l2 movwf xmtreg call txmidi movlw 06eh ;max velocity2 movwf xmtreg call txmidi
l2 movf drum2,W ;drum note3 xorlw 0x00 btfsc STATUS,Z goto l3 movwf xmtreg call txmidi
movlw 06eh ;max velocity3 movwf xmtreg call txmidi
l3 movf drum3,W ;drum note4 xorlw 0x00 btfsc STATUS,Z goto l4 movwf xmtreg call txmidi
movlw 06eh ;max velocity4 movwf xmtreg call txmidi
l4 movf drum4,W ;drum note5 xorlw 0x00 btfsc STATUS,Z goto l5 movwf xmtreg call txmidi
movlw 06eh ;max velocity5 movwf xmtreg call txmidi
l5 movf drum5,W ;drum note6 xorlw 0x00 btfsc STATUS,Z goto l6 movwf xmtreg call txmidi movlw 06eh ;max velocity6 movwf xmtreg call txmidi
l6 movf drum6,W ;drum note7 xorlw 0x00 btfsc STATUS,Z goto l7 movwf xmtreg call txmidi
movlw 06eh ;max velocity7 movwf xmtreg call txmidi
l7 movf drum7,W ;drum note8 xorlw 0x00 btfsc STATUS,Z return movwf xmtreg call txmidi
movlw 06eh ;max velocity8 movwf xmtreg call txmidi
return
;***************************************** ; note-off subroutine ;*****************************************
noteoff0 movlw 089h ;note-off ch10 movwf xmtreg call txmidi goto lastoff
noteoff1 movlw 087h ;note-off ch8 movwf xmtreg call txmidi goto lastoff
lastoff movf drum0,W ;drum note1 xorlw 0x00 btfsc STATUS,Z goto l11 movwf xmtreg call txmidi
movlw 06eh ;max velocity1 movwf xmtreg call txmidi
l11 movf drum1,W ;drum note2 xorlw 0x00 btfsc STATUS,Z goto l12 movwf xmtreg call txmidi movlw 06eh ;max velocity2 movwf xmtreg call txmidi
l12 movf drum2,W ;drum note3 xorlw 0x00 btfsc STATUS,Z goto l13 movwf xmtreg call txmidi
movlw 06eh ;max velocity3 movwf xmtreg call txmidi
l13 movf drum3,W ;drum note4 xorlw 0x00 btfsc STATUS,Z goto l14 movwf xmtreg call txmidi
movlw 06eh ;max velocity4 movwf xmtreg call txmidi
l14 movf drum4,W ;drum note5 xorlw 0x00 btfsc STATUS,Z goto l15 movwf xmtreg call txmidi
movlw 06eh ;max velocity5 movwf xmtreg call txmidi
l15 movf drum5,W ;drum note6 xorlw 0x00 btfsc STATUS,Z goto l16 movwf xmtreg call txmidi movlw 06eh ;max velocity6 movwf xmtreg call txmidi
l16 movf drum6,W ;drum note7 xorlw 0x00 btfsc STATUS,Z goto l17 movwf xmtreg call txmidi
movlw 06eh ;max velocity7 movwf xmtreg call txmidi
l17 movf drum7,W ;drum note8 xorlw 0x00 btfsc STATUS,Z return movwf xmtreg call txmidi
movlw 06eh ;max velocity8 movwf xmtreg call txmidi
return ;***************************************** ; channel midi / increm / decrem ;*****************************************
select movlw 0x00 ;filter if drum 0x00 xorwf drum,w btfsc STATUS,Z return
btfss PORTA,3 goto chge_inc
xorwf ch_comp btfsc STATUS,Z return btfss ch_now,0 ;ch midi select goto ch08 movlw 0x00 ;0x00 for ch10 movwf ch_now goto chge_ch ch08 movlw 0x01 ;0x01 for ch08 movwf ch_now chge_ch movwf ch_comp
movlw 0xFE ;delay no bounce movwf delay loop_2 decfsz delay,f goto loop_2 chge_inc btfsc PORTA,2 incf drum,f ;+1 to snd0x
chge_dec btfsc PORTA,1 decf drum,f ;-1 to snd0x
loop_0 movf PORTA,W ;one shot andlw 0x0E ;in PORTA1;2;3;B00001110 btfss STATUS,Z goto loop_0
;**************************************** ; Demo when press for store in eeprom ;****************************************
btfsc ch_now,0 ;select channel 8-10 goto on_note0 ;if0 goto goto on_note1 ;if1 goto
on_note0 movlw 099h ;note on ch10 movwf xmtreg call txmidi
movf drum,W ;drum note movwf xmtreg call txmidi
movlw 06eh ;max velocity1 movwf xmtreg call txmidi
movlw 089h ;note-off ch10 movwf xmtreg call txmidi
movf drum,W ;drum note movwf xmtreg call txmidi
movlw 06eh ;max velocity1 movwf xmtreg call txmidi goto main
on_note1 movlw 097h ;note on ch8 movwf xmtreg call txmidi
movf drum,W ;drum note movwf xmtreg call txmidi
movlw 06eh ;max velocity1 movwf xmtreg call txmidi
movlw 087h ;note-off ch8 movwf xmtreg call txmidi
movf drum,W ;drum note movwf xmtreg call txmidi
movlw 06eh ;max velocity1 movwf xmtreg call txmidi goto main
;***************************************** ; Subroutines tx words midi ;*****************************************
delay2 movwf dlyreg ;delay=1+(n-1)*3+3 cycles dly2 decfsz dlyreg ;where n is in W reg. goto dly2 ;n=18 for delay=55 cycles nop return
bit_set nop nop bsf PORTA,0 return bit_clr bcf PORTA,0 nop nop return
txmidi ;return movlw .8 movwf xcount bcf PORTA,0 movlw .02 movwf delay1 dly1 decfsz delay1 goto dly1 xnext movlw .20 ;This loop has 25 cycles call delay2 ;Plus delay2 value. rrf xmtreg ;number of cycles to btfsc STATUS,0x00 ;bit set/clear =1+55+9=65. call bit_set ;number of cycles from btfss STATUS,0x00 ;bit set/clear =15. call bit_clr ;Total=80*0.4us=32uS decfsz xcount goto xnext
movlw .22 ;This loop requires 65 cycles call delay2 ;61 +4 so if n=20 nop bsf PORTA,0 ;delay=4+(n-1)*3=61
movlw .25 ;This loop requires 80 cycles call delay2 ;75+5 so if n=25 return ;delay=4+(n-1)*3=76
;***************************************** ; organizzation eeprom ;*****************************************
ee_rec movlw 0x00 ;the first start there is drum to 0x00 xorwf drum,w ;and if press PA2 write in to eep 0x00 btfsc STATUS,Z ;this confront if byte is 0x00 return ; movlw 0x00 ; xorwf value2,w ; btfsc STATUS,Z ; return ;
loop_1 movf PORTA,w ;one shot andlw 0x08 ;in PORTA4 ;B00001000 btfss STATUS,Z goto loop_1
btfsc value2,0 goto rec_0 btfsc value2,1 goto rec_1 btfsc value2,2 goto rec_2 btfsc value2,3 goto rec_3 btfsc value2,4 goto rec_4 btfsc value2,5 goto rec_5 btfsc value2,6 goto rec_6 btfsc value2,7 goto rec_7
rec_0 movlw 0x00 goto ee_wr rec_1 movlw 0x01 goto ee_wr rec_2 movlw 0x02 goto ee_wr rec_3 movlw 0x03 goto ee_wr rec_4 movlw 0x04 goto ee_wr rec_5 movlw 0x05 goto ee_wr rec_6 movlw 0x06 goto ee_wr rec_7 movlw 0x07 goto ee_wr
ee_wr movwf EEADR movf drum,w ;in drum storing the new note movwf EEDATA bsf STATUS,RP0 bsf EECON1,WREN movlw 0x55 movwf EECON2 movlw 0xAA movwf EECON2 bsf EECON1,WR ee_wait btfsc EECON1,WR goto ee_wait goto Rd_ee00 org 0x2100 DATA .36 ;bd (referiments decimal keys of keyboard) DATA .38 ;sn DATA .47 ;high tom DATA .45 ;mid tom DATA .41 ;low tom DATA .49 ;crash DATA .44 ;open hh DATA .46 ;close hh DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00
DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x00 DATA 0x56 ;Ver1.3 DATA 0x65 DATA 0x72 DATA 0x31 DATA 0x2E DATA 0x33
END
|