; WRITTEN BY: TOM SCARFF ; DATE: 06/02/2002 ; ITERATION: 1.0 ; FILE SAVED AS: k_mel_bc.ASM ; FOR: PIC16F877 ; CLOCK: 4.00 MHz CRYSTAL ; INSTRUCTION CLOCK: 1.00 MHz T= luS ; PROGRAMME FUNCTION: To read melodion keyboard b/c ; and to transmit MIDI out ; MODIFICATION: When the switch is closed, the unit acts in PUSH mode. ; When it is open, the unit acts in PULL mode. ; key layout of the B/C melodion. ;Right Hand Keys ;10 Keys C ;switch Key Push Pull ;0 1 E(52) A(57) ;1 2 G(55) B(59) ;2 3 C(60) D(62) ;3 4 E(64) F(65) ;4 5 G(67) A(69) ;5 6 C(72) B(71) ;6 7 E(76) D(74) ;7 8 G(79) F(77) ;8 9 C(84) A(81) ;9 10 E(88) B(83) ;11 Keys B ;switch key Push Pull ;10 1 D#(51) G#(56) ;11 2 F#(54) A#(58) ;12 3 B(59) C#(61) ;13 4 D#(63) E(64) ;14 5 F#(66) G#(68) ;15 6 B(71) A#(70) ;16 7 D#(75) C#(73) ;17 8 F#(78) E(76) ;18 9 B(83) G#(80) ;19 10 D#(87) A#(82) ;20 11 F#(90) C#(85) ;Left Hand Keys ;switch Key Push ;21 1 G(G(55),B(59),D(62)) ;22 2 E(E(52),G#(56),B(59)) ;23 3 G(G(67),G(55)) ;24 4 E(E(64),E(52) ;25 5 C(C(60),E(64),G(67)) ;26 6 D(D(50),F#(54),A(57)) ;27 7 C(C(60),C(48)) ;28 8 D(D(62),D(50)) ;switch Key Pull ;21 1 D(D(50),F#(54),A(57)) ;22 2 A(A(57),C#(61),E(64)) ;23 3 D(D(62),D(50)) ;24 4 A(A(57),A(45)) ;25 5 G(G(55),B(59),D(62) ;26 6 F(F(53),A(57),C(60)) ;27 7 G(G(67),G(55)) ;28 8 F(F(65),F(53)) ; ; ; list p=16F877 ; tells the assembler which PIC #include "p16F877.inc" ; general register file __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_OFF & _LVP_OFF & _DEBUG_OFF & _CPD_OFF ; '__CONFIG' directive is used to embed configuration data within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. #DEFINE PAGE0 BCF 3,5 #DEFINE PAGE1 BSF 3,5 TEMP EQU 20 COUNT EQU 21 CHANA EQU 22 ;midi channel number minus 1 note equ 23 midich equ 24 dlyreg3 equ 25 tab_val equ 26 select equ 27 flags equ 28 push_pull_flag equ 29 NTEREG EQU 50 ;reserved for ;note register ;128 bytes ;addreses 64 - 192 ;******************************************************* ; START OF PROGRAM MEMORY ;******************************************************* ORG 0 goto INIT ;************************************* ; Delay Subroutine (770uS) ;************************************* delay3 movlw .255 movwf dlyreg3 dly3 decfsz dlyreg3 goto dly3 nop return ;****************************************** ; transmission complete subroutine ;***************+************************** txchar bsf STATUS,RP0 btfss TXSTA,1 ; test for end of transmission goto $-1 bcf STATUS,RP0 return ;******************************************* ; Initialization ;******************************************* INIT PAGE1 movlw 05h ; enable weak pull-up resistors movwf OPTION_REG ; and TMR0 set to 1:64=16mS MOVLW 6 MOVWF ADCON1 ;set port a as digital CLRF TRISA ;all pins outputs CLRF TRISD ;all pins outputs movlw b'00000100' ; RE2 is push/pull input MOVWF TRISE ;all pins outputs MOVLW 0FFh MOVWF TRISB ;all pins inputs PAGE0 CALL SETBAUD ;set up usart movf PORTC,W andlw 0Fh movwf midich goto main ;********************************************************************* ; Clear bits 0-7, RAM 64-79, 16x8 Flag REGISTER ;********************************************************************* clearflags MOVLW .64 ; Start at .64 MOVWF FSR ; First address used in RAM MOVLW .00 ; Clear RAM MOVWF INDF LOOPIT INCF FSR,F CLRW MOVWF INDF ;max velocity MOVFW FSR ;copy position to w XORLW .79 ;have we reached the end BTFSS STATUS,Z ; GOTO LOOPIT ;no so next one please ;yes job done return ;********************************************************************** ; Scan RB0-7 inputs (8) and compare with INDF, 0 to 7 ;********************************************************************** key_det ;call delay3 incf note,F btfsc PORTB,0 goto flagoff0? btfss INDF,0 goto setflag0 movfw flags btfss STATUS,Z goto clearflag0_rev goto cont1 flagoff0? btfsc INDF,0 goto clearflag0 goto cont1 setflag0 bsf INDF,0 call noteon_chk goto cont1 clearflag0_rev bcf INDF,0 call noteoff_chk_rev goto cont1 clearflag0 bcf INDF,0 call noteoff_chk ;----------------------- cont1 ;call delay3 incf note,F btfsc PORTB,1 goto flagoff1? btfss INDF,1 goto setflag1 movfw flags btfss STATUS,Z goto clearflag1_rev goto cont2 flagoff1? btfsc INDF,1 goto clearflag1 goto cont2 setflag1 bsf INDF,1 call noteon_chk goto cont2 clearflag1_rev bcf INDF,1 call noteoff_chk_rev goto cont2 clearflag1 bcf INDF,1 call noteoff_chk ;----------------------- cont2 ;call delay3 incf note,F btfsc PORTB,2 goto flagoff2? btfss INDF,2 goto setflag2 movfw flags btfss STATUS,Z goto clearflag2_rev goto cont3 flagoff2? btfsc INDF,2 goto clearflag2 goto cont3 setflag2 bsf INDF,2 call noteon_chk goto cont3 clearflag2_rev bcf INDF,2 call noteoff_chk_rev goto cont3 clearflag2 bcf INDF,2 call noteoff_chk ;----------------------- cont3 ;call delay3 incf note,F btfsc PORTB,3 goto flagoff3? btfss INDF,3 goto setflag3 movfw flags btfss STATUS,Z goto clearflag3_rev goto cont4 flagoff3? btfsc INDF,3 goto clearflag3 goto cont4 setflag3 bsf INDF,3 call noteon_chk goto cont4 clearflag3_rev bcf INDF,3 call noteoff_chk_rev goto cont4 clearflag3 bcf INDF,3 call noteoff_chk ;----------------------- cont4 ;call delay3 incf note,F btfsc PORTB,4 goto flagoff4? btfss INDF,4 goto setflag4 movfw flags btfss STATUS,Z goto clearflag4_rev goto cont5 flagoff4? btfsc INDF,4 goto clearflag4 goto cont5 setflag4 bsf INDF,4 call noteon_chk goto cont5 clearflag4_rev bcf INDF,4 call noteoff_chk_rev goto cont5 clearflag4 bcf INDF,4 call noteoff_chk ;----------------------- cont5 ;call delay3 incf note,F btfsc PORTB,5 goto flagoff5? btfss INDF,5 goto setflag5 movfw flags btfss STATUS,Z goto clearflag5_rev goto cont6 flagoff5? btfsc INDF,5 goto clearflag5 goto cont6 setflag5 bsf INDF,5 call noteon_chk goto cont6 clearflag5_rev bcf INDF,5 call noteoff_chk_rev goto cont6 clearflag5 bcf INDF,5 call noteoff_chk ;----------------------- cont6 ;call delay3 incf note,F btfsc PORTB,6 goto flagoff6? btfss INDF,6 goto setflag6 movfw flags btfss STATUS,Z goto clearflag6_rev goto cont7 flagoff6? btfsc INDF,6 goto clearflag6 goto cont7 setflag6 bsf INDF,6 call noteon_chk goto cont7 clearflag6_rev bcf INDF,6 call noteoff_chk_rev goto cont7 clearflag6 bcf INDF,6 call noteoff_chk ;----------------------- cont7 ;call delay3 incf note,F btfsc PORTB,7 goto flagoff7? btfss INDF,7 goto setflag7 movfw flags btfss STATUS,Z goto clearflag7_rev goto cont8 flagoff7? btfsc INDF,7 goto clearflag7 goto cont8 setflag7 bsf INDF,7 call noteon_chk goto cont8 clearflag7_rev bcf INDF,7 call noteoff_chk_rev goto cont8 clearflag7 bcf INDF,7 call noteoff_chk cont8 ;call delay3 incf FSR,F return ;******************************************************** ; 1) Push-on switch select output ;******************************************************** push_on movlw 00h subwf select,W btfsc STATUS,Z goto sel_psh0 movlw 01h subwf select,W btfsc STATUS,Z goto sel_psh1 movlw 02h subwf select,W btfsc STATUS,Z goto sel_psh2 movlw 03h subwf select,W btfsc STATUS,Z goto sel_psh3 movlw 04h subwf select,W btfsc STATUS,Z goto sel_psh4 movlw 05h subwf select,W btfsc STATUS,Z goto sel_psh5 movlw 06h subwf select,W btfsc STATUS,Z goto sel_psh6 movlw 07h subwf select,W btfsc STATUS,Z goto sel_psh7 movlw 08h subwf select,W btfsc STATUS,Z goto sel_psh8 movlw 09h subwf select,W btfsc STATUS,Z goto sel_psh9 ;------------------------------------------ movlw .10 subwf select,W btfsc STATUS,Z goto sel_psh10 movlw .11 subwf select,W btfsc STATUS,Z goto sel_psh11 movlw .12 subwf select,W btfsc STATUS,Z goto sel_psh12 movlw .13 subwf select,W btfsc STATUS,Z goto sel_psh13 movlw .14 subwf select,W btfsc STATUS,Z goto sel_psh14 movlw .15 subwf select,W btfsc STATUS,Z goto sel_psh15 movlw .16 subwf select,W btfsc STATUS,Z goto sel_psh16 movlw .17 subwf select,W btfsc STATUS,Z goto sel_psh17 movlw .18 subwf select,W btfsc STATUS,Z goto sel_psh18 movlw .19 subwf select,W btfsc STATUS,Z goto sel_psh19 movlw .20 subwf select,W btfsc STATUS,Z goto sel_psh20 ;------------------------------------- movlw .21 subwf select,W btfsc STATUS,Z goto sel_psh21 movlw .22 subwf select,W btfsc STATUS,Z goto sel_psh22 movlw .23 subwf select,W btfsc STATUS,Z goto sel_psh23 movlw .24 subwf select,W btfsc STATUS,Z goto sel_psh24 movlw .25 subwf select,W btfsc STATUS,Z goto sel_psh25 movlw .26 subwf select,W btfsc STATUS,Z goto sel_psh26 movlw .27 subwf select,W btfsc STATUS,Z goto sel_psh27 movlw .28 subwf select,W btfsc STATUS,Z goto sel_psh28 return ;++++++++++++++++++++++++++++++++++++++++++++++++ sel_psh0 movlw .52 movwf note call noteon return sel_psh1 movlw .55 movwf note call noteon return sel_psh2 movlw .60 movwf note call noteon return sel_psh3 movlw .64 movwf note call noteon return sel_psh4 movlw .67 movwf note call noteon return sel_psh5 movlw .72 movwf note call noteon return sel_psh6 movlw .76 movwf note call noteon return sel_psh7 movlw .79 movwf note call noteon return sel_psh8 movlw .84 movwf note call noteon return sel_psh9 movlw .88 movwf note call noteon return ;-------------------11 keys B ---------------------- sel_psh10 movlw .51 movwf note call noteon return sel_psh11 movlw .54 movwf note call noteon return sel_psh12 movlw .59 movwf note call noteon return sel_psh13 movlw .63 movwf note call noteon return sel_psh14 movlw .66 movwf note call noteon return sel_psh15 movlw .71 movwf note call noteon return sel_psh16 movlw .75 movwf note call noteon return sel_psh17 movlw .78 movwf note call noteon return sel_psh18 movlw .83 movwf note call noteon return sel_psh19 movlw .87 movwf note call noteon return sel_psh20 movlw .90 movwf note call noteon return ;---------start of bass------------------- sel_psh21 movlw .55 movwf note call noteon movlw .59 movwf note call noteon movlw .62 movwf note call noteon return sel_psh22 movlw .52 movwf note call noteon movlw .56 movwf note call noteon movlw .59 movwf note call noteon return sel_psh23 movlw .67 movwf note call noteon movlw .55 movwf note call noteon return sel_psh24 movlw .64 movwf note call noteon movlw .52 movwf note call noteon return sel_psh25 movlw .60 movwf note call noteon movlw .64 movwf note call noteon movlw .67 movwf note call noteon return sel_psh26 movlw .50 movwf note call noteon movlw .54 movwf note call noteon movlw .57 movwf note call noteon return sel_psh27 movlw .60 movwf note call noteon movlw .48 movwf note call noteon return sel_psh28 movlw .62 movwf note call noteon movlw .50 movwf note call noteon return ;******************************************************** ; 2) Pull-on switch select output ;******************************************************** pull_on movlw 00h subwf select,W btfsc STATUS,Z goto sel_pul0 movlw 01h subwf select,W btfsc STATUS,Z goto sel_pul1 movlw 02h subwf select,W btfsc STATUS,Z goto sel_pul2 movlw 03h subwf select,W btfsc STATUS,Z goto sel_pul3 movlw 04h subwf select,W btfsc STATUS,Z goto sel_pul4 movlw 05h subwf select,W btfsc STATUS,Z goto sel_pul5 movlw 06h subwf select,W btfsc STATUS,Z goto sel_pul6 movlw 07h subwf select,W btfsc STATUS,Z goto sel_pul7 movlw 08h subwf select,W btfsc STATUS,Z goto sel_pul8 movlw 09h subwf select,W btfsc STATUS,Z goto sel_pul9 ;------------------------------------------ movlw .10 subwf select,W btfsc STATUS,Z goto sel_pul10 movlw .11 subwf select,W btfsc STATUS,Z goto sel_pul11 movlw .12 subwf select,W btfsc STATUS,Z goto sel_pul12 movlw .13 subwf select,W btfsc STATUS,Z goto sel_pul13 movlw .14 subwf select,W btfsc STATUS,Z goto sel_pul14 movlw .15 subwf select,W btfsc STATUS,Z goto sel_pul15 movlw .16 subwf select,W btfsc STATUS,Z goto sel_pul16 movlw .17 subwf select,W btfsc STATUS,Z goto sel_pul17 movlw .18 subwf select,W btfsc STATUS,Z goto sel_pul18 movlw .19 subwf select,W btfsc STATUS,Z goto sel_pul19 movlw .20 subwf select,W btfsc STATUS,Z goto sel_pul20 ;------------------------------------- movlw .21 subwf select,W btfsc STATUS,Z goto sel_pul21 movlw .22 subwf select,W btfsc STATUS,Z goto sel_pul22 movlw .23 subwf select,W btfsc STATUS,Z goto sel_pul23 movlw .24 subwf select,W btfsc STATUS,Z goto sel_pul24 movlw .25 subwf select,W btfsc STATUS,Z goto sel_pul25 movlw .26 subwf select,W btfsc STATUS,Z goto sel_pul26 movlw .27 subwf select,W btfsc STATUS,Z goto sel_pul27 movlw .28 subwf select,W btfsc STATUS,Z goto sel_pul28 return ;++++++++++++++++++++++++++++++++++++++++++++++++ sel_pul0 movlw .57 movwf note call noteon return sel_pul1 movlw .59 movwf note call noteon return sel_pul2 movlw .62 movwf note call noteon return sel_pul3 movlw .65 movwf note call noteon return sel_pul4 movlw .69 movwf note call noteon return sel_pul5 movlw .71 movwf note call noteon return sel_pul6 movlw .74 movwf note call noteon return sel_pul7 movlw .77 movwf note call noteon return sel_pul8 movlw .81 movwf note call noteon return sel_pul9 movlw .83 movwf note call noteon return ;----------------------------- sel_pul10 movlw .56 movwf note call noteon return sel_pul11 movlw .58 movwf note call noteon return sel_pul12 movlw .61 movwf note call noteon return sel_pul13 movlw .64 movwf note call noteon return sel_pul14 movlw .68 movwf note call noteon return sel_pul15 movlw .70 movwf note call noteon return sel_pul16 movlw .73 movwf note call noteon return sel_pul17 movlw .76 movwf note call noteon return sel_pul18 movlw .80 movwf note call noteon return sel_pul19 movlw .82 movwf note call noteon return sel_pul20 movlw .85 movwf note call noteon return ;-----------bass notes--------- sel_pul21 movlw .50 movwf note call noteon movlw .54 movwf note call noteon movlw .57 movwf note call noteon return sel_pul22 movlw .57 movwf note call noteon movlw .61 movwf note call noteon movlw .64 movwf note call noteon return sel_pul23 movlw .62 movwf note call noteon movlw .50 movwf note call noteon return sel_pul24 movlw .57 movwf note call noteon movlw .45 movwf note call noteon return sel_pul25 movlw .55 movwf note call noteon movlw .59 movwf note call noteon movlw .62 movwf note call noteon return sel_pul26 movlw .53 movwf note call noteon movlw .57 movwf note call noteon movlw .60 movwf note call noteon return sel_pul27 movlw .67 movwf note call noteon movlw .55 movwf note call noteon return sel_pul28 movlw .65 movwf note call noteon movlw .53 movwf note call noteon return ;******************************************************** ; 3) Push-off switch select output ;******************************************************** push_off movlw 00h subwf select,W btfsc STATUS,Z goto sel_pshoff0 movlw 01h subwf select,W btfsc STATUS,Z goto sel_pshoff1 movlw 02h subwf select,W btfsc STATUS,Z goto sel_pshoff2 movlw 03h subwf select,W btfsc STATUS,Z goto sel_pshoff3 movlw 04h subwf select,W btfsc STATUS,Z goto sel_pshoff4 movlw 05h subwf select,W btfsc STATUS,Z goto sel_pshoff5 movlw 06h subwf select,W btfsc STATUS,Z goto sel_pshoff6 movlw 07h subwf select,W btfsc STATUS,Z goto sel_pshoff7 movlw 08h subwf select,W btfsc STATUS,Z goto sel_pshoff8 movlw 09h subwf select,W btfsc STATUS,Z goto sel_pshoff9 movlw .10 subwf select,W btfsc STATUS,Z goto sel_pshoff10 movlw .11 subwf select,W btfsc STATUS,Z goto sel_pshoff11 movlw .12 subwf select,W btfsc STATUS,Z goto sel_pshoff12 movlw .13 subwf select,W btfsc STATUS,Z goto sel_pshoff13 movlw .14 subwf select,W btfsc STATUS,Z goto sel_pshoff14 movlw .15 subwf select,W btfsc STATUS,Z goto sel_pshoff15 movlw .16 subwf select,W btfsc STATUS,Z goto sel_pshoff16 movlw .17 subwf select,W btfsc STATUS,Z goto sel_pshoff17 movlw .18 subwf select,W btfsc STATUS,Z goto sel_pshoff18 movlw .19 subwf select,W btfsc STATUS,Z goto sel_pshoff19 movlw .20 subwf select,W btfsc STATUS,Z goto sel_pshoff20 movlw .21 subwf select,W btfsc STATUS,Z goto sel_pshoff21 movlw .22 subwf select,W btfsc STATUS,Z goto sel_pshoff22 movlw .23 subwf select,W btfsc STATUS,Z goto sel_pshoff23 movlw .24 subwf select,W btfsc STATUS,Z goto sel_pshoff24 movlw .25 subwf select,W btfsc STATUS,Z goto sel_pshoff25 movlw .26 subwf select,W btfsc STATUS,Z goto sel_pshoff26 movlw .27 subwf select,W btfsc STATUS,Z goto sel_pshoff27 movlw .28 subwf select,W btfsc STATUS,Z goto sel_pshoff28 return ;############################################################## sel_pshoff0 movlw .52 movwf note call noteoff return sel_pshoff1 movlw .55 movwf note call noteoff return sel_pshoff2 movlw .60 movwf note call noteoff return sel_pshoff3 movlw .64 movwf note call noteoff return sel_pshoff4 movlw .67 movwf note call noteoff return sel_pshoff5 movlw .72 movwf note call noteoff return sel_pshoff6 movlw .76 movwf note call noteoff return sel_pshoff7 movlw .79 movwf note call noteoff return sel_pshoff8 movlw .84 movwf note call noteoff return sel_pshoff9 movlw .88 movwf note call noteoff return ;------------------------------------ sel_pshoff10 movlw .51 movwf note call noteoff return sel_pshoff11 movlw .54 movwf note call noteoff return sel_pshoff12 movlw .59 movwf note call noteoff return sel_pshoff13 movlw .63 movwf note call noteoff return sel_pshoff14 movlw .66 movwf note call noteoff return sel_pshoff15 movlw .71 movwf note call noteoff return sel_pshoff16 movlw .75 movwf note call noteoff return sel_pshoff17 movlw .78 movwf note call noteoff return sel_pshoff18 movlw .83 movwf note call noteoff return sel_pshoff19 movlw .87 movwf note call noteoff return sel_pshoff20 movlw .90 movwf note call noteoff return ;---------start of bass------------------- sel_pshoff21 movlw .55 movwf note call noteoff movlw .59 movwf note call noteoff movlw .62 movwf note call noteoff return sel_pshoff22 movlw .52 movwf note call noteoff movlw .56 movwf note call noteoff movlw .59 movwf note call noteoff return sel_pshoff23 movlw .67 movwf note call noteoff movlw .55 movwf note call noteoff return sel_pshoff24 movlw .64 movwf note call noteoff movlw .52 movwf note call noteoff return sel_pshoff25 movlw .60 movwf note call noteoff movlw .64 movwf note call noteoff movlw .67 movwf note call noteoff return sel_pshoff26 movlw .50 movwf note call noteoff movlw .54 movwf note call noteoff movlw .57 movwf note call noteoff return sel_pshoff27 movlw .60 movwf note call noteoff movlw .48 movwf note call noteoff return sel_pshoff28 movlw .62 movwf note call noteoff movlw .50 movwf note call noteoff return ;############################################################# ;******************************************************** ; 4) Pull-off switch select output ;******************************************************** pull_off movlw 00h subwf select,W btfsc STATUS,Z goto sel_puloff0 movlw 01h subwf select,W btfsc STATUS,Z goto sel_puloff1 movlw 02h subwf select,W btfsc STATUS,Z goto sel_puloff2 movlw 03h subwf select,W btfsc STATUS,Z goto sel_puloff3 movlw 04h subwf select,W btfsc STATUS,Z goto sel_puloff4 movlw 05h subwf select,W btfsc STATUS,Z goto sel_puloff5 movlw 06h subwf select,W btfsc STATUS,Z goto sel_puloff6 movlw 07h subwf select,W btfsc STATUS,Z goto sel_puloff7 movlw 08h subwf select,W btfsc STATUS,Z goto sel_puloff8 movlw 09h subwf select,W btfsc STATUS,Z goto sel_puloff9 movlw .10 subwf select,W btfsc STATUS,Z goto sel_puloff10 movlw .11 subwf select,W btfsc STATUS,Z goto sel_puloff11 movlw .12 subwf select,W btfsc STATUS,Z goto sel_puloff12 movlw .13 subwf select,W btfsc STATUS,Z goto sel_puloff13 movlw .14 subwf select,W btfsc STATUS,Z goto sel_puloff14 movlw .15 subwf select,W btfsc STATUS,Z goto sel_puloff15 movlw .16 subwf select,W btfsc STATUS,Z goto sel_puloff16 movlw .17 subwf select,W btfsc STATUS,Z goto sel_puloff17 movlw .18 subwf select,W btfsc STATUS,Z goto sel_puloff18 movlw .19 subwf select,W btfsc STATUS,Z goto sel_puloff19 movlw .20 subwf select,W btfsc STATUS,Z goto sel_puloff20 movlw .21 subwf select,W btfsc STATUS,Z goto sel_puloff21 movlw .22 subwf select,W btfsc STATUS,Z goto sel_puloff22 movlw .23 subwf select,W btfsc STATUS,Z goto sel_puloff23 movlw .24 subwf select,W btfsc STATUS,Z goto sel_puloff24 movlw .25 subwf select,W btfsc STATUS,Z goto sel_puloff25 movlw .26 subwf select,W btfsc STATUS,Z goto sel_puloff26 movlw .27 subwf select,W btfsc STATUS,Z goto sel_puloff27 movlw .28 subwf select,W btfsc STATUS,Z goto sel_puloff28 return ;################################################## sel_puloff0 movlw .57 movwf note call noteoff return sel_puloff1 movlw .59 movwf note call noteoff return sel_puloff2 movlw .62 movwf note call noteoff return sel_puloff3 movlw .65 movwf note call noteoff return sel_puloff4 movlw .69 movwf note call noteoff return sel_puloff5 movlw .71 movwf note call noteoff return sel_puloff6 movlw .74 movwf note call noteoff return sel_puloff7 movlw .77 movwf note call noteoff return sel_puloff8 movlw .81 movwf note call noteoff return sel_puloff9 movlw .83 movwf note call noteoff return ;----------------------------- sel_puloff10 movlw .56 movwf note call noteoff return sel_puloff11 movlw .58 movwf note call noteoff return sel_puloff12 movlw .61 movwf note call noteoff return sel_puloff13 movlw .64 movwf note call noteoff return sel_puloff14 movlw .68 movwf note call noteoff return sel_puloff15 movlw .70 movwf note call noteoff return sel_puloff16 movlw .73 movwf note call noteoff return sel_puloff17 movlw .76 movwf note call noteoff return sel_puloff18 movlw .80 movwf note call noteoff return sel_puloff19 movlw .82 movwf note call noteoff return sel_puloff20 movlw .85 movwf note call noteoff return ;-----------bass notes--------- sel_puloff21 movlw .50 movwf note call noteoff movlw .54 movwf note call noteoff movlw .57 movwf note call noteoff return sel_puloff22 movlw .57 movwf note call noteoff movlw .61 movwf note call noteoff movlw .64 movwf note call noteoff return sel_puloff23 movlw .62 movwf note call noteoff movlw .50 movwf note call noteoff return sel_puloff24 movlw .57 movwf note call noteoff movlw .45 movwf note call noteoff return sel_puloff25 movlw .55 movwf note call noteoff movlw .59 movwf note call noteoff movlw .62 movwf note call noteoff return sel_puloff26 movlw .53 movwf note call noteoff movlw .57 movwf note call noteoff movlw .60 movwf note call noteoff return sel_puloff27 movlw .67 movwf note call noteoff movlw .55 movwf note call noteoff return sel_puloff28 movlw .65 movwf note call noteoff movlw .53 movwf note call noteoff return ;################################################### ;_________________________________________________ ;************************************************************************ ; Check MIDI NOTE-On data and convert ;*********************************************************************** noteon_chk movf note,W movwf select btfsc PORTE,2 goto pul_on goto psh_on pul_on call pull_on ; if switch is pressed return psh_on call push_on return ;************************************************************************ ; Check MIDI NOTE-Off data and convert ;*********************************************************************** noteoff_chk movf note,W movwf select btfsc PORTE,2 goto pul_off goto psh_off pul_off call pull_off ; if switch is pressed return psh_off call push_off return ;************************************************************************ ; Check MIDI NOTE-Off data and convert ;*********************************************************************** noteoff_chk_rev movf note,W movwf select btfss PORTE,2 goto pul_off_rev goto psh_off_rev pul_off_rev call pull_off ; if switch is pressed return psh_off_rev call push_off return ;************************************************************************ ; Output MIDI All Notes Off data ;*********************************************************************** alloff movlw 0B0h ; Control addwf midich,W movwf TXREG ; send character from W call txchar movlw 07Bh movwf TXREG ; send character from W call txchar movlw 00h ; movwf TXREG ; send character from W call txchar return ;************************************************************************ ; Output MIDI NOTE-On data ;*********************************************************************** noteon movlw 090h ; Note-on ch.? addwf midich,W movwf TXREG ; send chazacter from W call txchar movf note,W movwf TXREG ; send character from W call txchar movlw 040h ; Half velocity movwf TXREG ; send character from W call txchar return ;********************************************************************** ; Output MIDI Note-off data ;********************************************************************** noteoff movlw 080h ; Note-off ch.? addwf midich,W movwf TXREG ; send character from W call txchar movf note,W movwf TXREG ; send character from W call txchar movlw 040h ; movwf TXREG ; send character from W call txchar return ;******************************************************************** SETBAUD ; Set up USART bsf STATUS,RP0 ; goto page 1 movlw b'10001111' ; RC7 is RX input movwf TRISC ; RC0-3 is MIDI ch. sel. Sw. movlw 01h ; 31250 baud for MIDI movwf SPBRG movlw b'00100000' ; async tx 8 bit movwf TXSTA bcf STATUS,RP0 ; return to page 0 movlw b'10010000' ; async rx 8 bit movwf RCSTA RETURN ;********************************************************************** ; Main Programme Start ;********************************************************************** main call clearflags clrf flags clrf push_pull_flag ;********************************************************************** ; Scan 128 keys with RD0-7, RA0-5 and RE0-1 all outputs (16) ; and RB0-7 inputs (8) 16x8=128 ;********************************************************************** scankey clrf TMR0 movlw 0FFh movwf note MOVLW .64 ; 64+16=>79 MOVWF FSR movlw 0FFh movwf PORTD movwf PORTA movwf PORTE bcf PORTD,0 call key_det bsf PORTD,0 movlw 0FFh movwf PORTD bcf PORTD,1 call key_det bsf PORTD,1 movlw 0FFh movwf PORTD bcf PORTD,2 call key_det bsf PORTD,2 movlw 0FFh movwf PORTD bcf PORTD,3 call key_det bsf PORTD,3 movlw 0FFh movwf PORTD bcf PORTD,4 call key_det bsf PORTD,4 movlw 0FFh movwf PORTD bcf PORTD,5 call key_det bsf PORTD,5 movlw 0FFh movwf PORTD bcf PORTD,6 call key_det bsf PORTD,6 movlw 0FFh movwf PORTD bcf PORTD,7 call key_det bsf PORTD,7 movlw 0FFh movwf PORTD movwf PORTA movlw 0FFh movwf PORTA bcf PORTA,0 call key_det bsf PORTA,0 movlw 0FFh movwf PORTA bcf PORTA,1 call key_det bsf PORTA,1 movlw 0FFh movwf PORTA bcf PORTA,2 call key_det bsf PORTA,2 movlw 0FFh movwf PORTA bcf PORTA,3 call key_det bsf PORTA,3 movlw 0FFh movwf PORTA bcf PORTA,4 call key_det bsf PORTA,4 movlw 0FFh movwf PORTA bcf PORTA,5 call key_det bsf PORTA,5 movlw 0FFh movwf PORTA movwf PORTE movlw 0FFh movwf PORTE bcf PORTE,0 call key_det bsf PORTE,0 movlw 0FFh movwf PORTE bcf PORTE,1 call key_det bsf PORTE,1 ;-------------------------------------- ; Check press/release push/pull switch ;-------------------------------------- btfss flags,0 goto chk_sw1 bcf flags,0 ; clear push flag bsf push_pull_flag,0 ; set push/pull flag goto chk_over chk_sw1 btfss PORTE,2 goto chk_psh_pul btfss push_pull_flag,0 ; push/pull flag clear? bsf flags,0 ; set push flag goto chk_over chk_psh_pul btfss push_pull_flag,0 ; push/pull flag clear? goto chk_pul_flag bcf push_pull_flag,0 ; clear push/pull flag bsf flags,2 ; set pull flag goto chk_over chk_pul_flag btfsc flags,2 bcf flags,2 ; clear pull flag chk_over nop ;----------------------------------------- sw_dbnc movf TMR0,W ;call delay xorlw 00h btfss STATUS,Z goto sw_dbnc goto scankey ;*********************************************************************************************** END