LIST p=16F84 #include p16f84.inc ;Program to tx MIDI controller pedal data ;MIDI Drum-Pads ;PROGRAM: T. Scarff ;DATE: 21/01/2000 ;FILENAME: prg_ped.asm ;ITERATION: 1.1:added start/stop option ;Modification: 29/05/2003 MIDI ch RB4-7, MIDI out RB0, prog. sw. RA1, ;CLOCK: 4 Mhz ;******************************** ; Variable Assignment Addresses ;******************************** dlyreg equ 0Ch xcount equ 0Dh xmtreg equ 0Eh dlyreg4 equ 0Fh count equ 10h timer equ 11h clkdown equ 12h midich equ 13h value1 equ 14h rcount equ 15h rcvreg equ 16h base_addr equ 17h dlyreg5 equ 18h vel equ 19h select equ 1Ah pedal_val equ 1Bh port_time equ 1Ch ;******************************** ; Constant Assignments ;******************************** CARRY equ 00 MSB equ 07 BORROW equ 00 LED equ 07 W equ 00 F equ 01 Z equ 02 C equ 00 dx equ 00 ;******************************** ; Port Assignments ;******************************** PCL equ 02 STATUS equ 03 PORTA equ 05 PORTB equ 06 ;************************************ ; PROGRAMME Reset Point ;************************************ org 0 goto INIT ;************************************ ; Switch Debounce Delay (50mS) ;************************************ sw_dbnc movlw 80h ; Delay routine movwf count debnce call delay3 decfsz count goto debnce return ;************************************* ; Delay Subroutine (770uS) ;************************************* delay3 movlw .255 movwf dlyreg dly3 decfsz dlyreg goto dly3 nop return ;************************************* ; MIDI out Subroutine (PORTB,0) ;************************************* delay4 movwf dlyreg4 ;delay=1+(n-1)*3+3 cycles dly4 decfsz dlyreg4 ;where n is in W reg. goto dly4 ;n=18 for delay=55 cycles nop return bit_set nop nop bsf PORTB,0 return bit_clr bcf PORTB,0 nop nop return txmidi movlw .8 movwf xcount bcf PORTB,0 movlw .1 movwf dlyreg5 nop nop dly5 decfsz dlyreg5 goto dly5 xnext movlw .4 ;This loop has 25 cycles call delay4 ;Plus delay2 value. rrf xmtreg ;number of cycles to btfsc STATUS,CARRY ;bit set/clear =1+55+9=65. call bit_set ;number of cycles from btfss STATUS,CARRY ;bit set/clear =15. call bit_clr ;Total=80*0.4us=32uS decfsz xcount goto xnext movlw .6 ;This loop requires 65 cycles call delay4 ;61 +4 so if n=20 nop bsf PORTB,0 ;delay=4+(n-1)*3=61 movlw .9 ;This loop requires 80 cycles call delay4 ;75+5 so if n=25 return ;delay=4+(n-1)*3=76 ;************************************ ; Control Pedal Loop ;************************************ pedloop call sw_dbnc sw_on? btfsc PORTA,0 ; Switch i/p OFF? goto sw_on? call ctrlon call sw_dbnc sw_off? btfss PORTA,0 ; Switch i/p OFF? goto sw_off? call ctrloff return ;************************************ ; Portamento Pedal Loop ;************************************ portloop call sw_dbnc btfsc PORTA,0 ; Switch i/p OFF? goto $-1 call portmon call sw_dbnc btfss PORTA,0 ; Switch i/p OFF? goto $-1 call portmoff return ;***************************************************** ; Control-on subroutine ;***************************************************** ctrlon movf midich,W addlw 0B0h ; Control Change movwf xmtreg call txmidi movf pedal_val,W ; controller value movwf xmtreg call txmidi movlw 07fh ; control on movwf xmtreg call txmidi return ;***************************************************** ; Control-off subroutine ;***************************************************** ctrloff movf midich,W addlw 0B0h ; Control Change movwf xmtreg call txmidi movf pedal_val,W movwf xmtreg call txmidi movlw 00h ; control off movwf xmtreg call txmidi return ;***************************************************** ; Start-on subroutine ;***************************************************** starton movlw 0FAh ;Start movwf xmtreg call txmidi return ;***************************************************** ; Continue subroutine ;***************************************************** continue movlw 0FBh ; Continue movwf xmtreg call txmidi return ;***************************************************** ; Stop subroutine ;***************************************************** stop movlw 0FCh ;Stop movwf xmtreg call txmidi return ;************************************ ; Portamento +time on ;************************************ portmon movf midich,W addlw 0B0h ; Control Change movwf xmtreg call txmidi movlw .05 ; Portamento Time control movwf xmtreg call txmidi movf port_time,W movwf xmtreg call txmidi movf pedal_val,W ; controller value movwf xmtreg call txmidi movlw 07fh ; control on movwf xmtreg call txmidi return ;************************************ ; Portamento off ;************************************ portmoff movf midich,W addlw 0B0h ; Control Change movwf xmtreg call txmidi movf pedal_val,W ; controller value movwf xmtreg call txmidi movlw 00h ; control off movwf xmtreg call txmidi return ;***************************************************** ; Write to EEPROM subroutine ;***************************************************** ee_wr movf base_addr,W; start addr. EEPROM movwf EEADR movf select,W andlw 07Fh movwf EEDATA bsf STATUS,RP0 ;writing to eeprom bcf INTCON,GIE bsf EECON1,WREN movlw 55h movwf EECON2 movlw 0AAh movwf EECON2 bsf EECON1,WR test_wr btfsc EECON1,WR; is write finished? goto test_wr bcf STATUS,RP0 bsf INTCON,GIE return ;************************************ ; Initialise Software ;************************************ ; RB0 MIDI out ; RB4-7 MIDI Channel in ; RA0 Input Sw. ; RA1 Prog. Sw. ; RA2 Prog. LED INIT bsf STATUS,RP0 ;enable weak pull-up resistors movlw 07Fh movwf OPTION_REG ; Option Register bcf STATUS,RP0 clrf PORTB movlw 0FEh ; 1111 1110 TRIS PORTB ;MAKE PORTB all I/P'S except RB0 bsf PORTB,0 ; set MIDI out 'HIGH' clrf PORTA movlw 0FBh ; 1111 1011 TRIS PORTA ;make porta all inputs, RA2=o/p movf PORTB,W ; read midich. switches andlw 0F0h movwf midich swapf midich,F ;************************************** ; Programme EEPROM ;************************************** main0 btfsc PORTA,1 ; is prog. sw. pressed? goto main1 ; No! bsf PORTA,2 ; Switch on prog. LED movlw 00h movwf base_addr movlw 01h movwf count movf PORTB,W ; Read DIP switches andlw 0Fh movwf select ; selection 1-16 call ee_wr call sw_dbnc bcf PORTA,2 ; Switch off prog. LED ;************************************** ; Read EEPROM and write to select ;************************************** main1 clrf base_addr; start addr. at 00h? movf base_addr,W movwf EEADR bsf STATUS,RP0 bsf EECON1,RD r1 btfsc EECON1,RD ; Wait to finish read. goto r1 bcf STATUS,RP0 movf EEDATA,W andlw 07Fh movwf select ;*************************************** ; Main Programme ;*************************************** main2 movlw 00h subwf select,W btfsc STATUS,Z goto sel1 movlw 01h subwf select,W btfsc STATUS,Z goto sel2 movlw 02h subwf select,W btfsc STATUS,Z goto sel3 movlw 03h subwf select,W btfsc STATUS,Z goto sel4 movlw 04h subwf select,W btfsc STATUS,Z goto sel5 movlw 05h subwf select,W btfsc STATUS,Z goto sel6 movlw 06h subwf select,W btfsc STATUS,Z goto sel7 movlw 07h subwf select,W btfsc STATUS,Z goto sel8 movlw 08h subwf select,W btfsc STATUS,Z goto sel9 movlw 09h subwf select,W btfsc STATUS,Z goto sel10 movlw 0Ah subwf select,W btfsc STATUS,Z goto sel11 movlw 0Bh subwf select,W btfsc STATUS,Z goto sel12 movlw 0Ch subwf select,W btfsc STATUS,Z goto sel13 movlw 0Dh subwf select,W btfsc STATUS,Z goto sel14 movlw 0Eh subwf select,W btfsc STATUS,Z goto sel15 movlw 0Fh subwf select,W btfsc STATUS,Z goto sel16 ;------------------------------------------- sel1 movlw .64 ; Sustain movwf pedal_val call pedloop goto sel1 ;------------------------------------------- sel2 movlw .66 ; Sostenuto movwf pedal_val call pedloop goto sel2 ;------------------------------------------- sel3 movlw .67 ; Soft Pedal movwf pedal_val call pedloop goto sel3 ;------------------------------------------- sel4 movlw .68 ; Legato Pedal movwf pedal_val call pedloop goto sel4 ;------------------------------------------- sel5 movlw .69 ; Hold 2 Pedal movwf pedal_val call pedloop goto sel5 ;------------------------------------------- sel6 btfsc PORTA,0 ; is Start sw. pressed? goto sel6 call starton call sw_dbnc tstoff1 btfss PORTA,0 ; is Start sw. released? goto tstoff1 call sw_dbnc goto sel6 ;------------------------------------------- sel7 btfsc PORTA,0 ; is Start sw. pressed? goto $-1 call starton call sw_dbnc btfss PORTA,0 ; is Start sw. released? goto $-1 call sw_dbnc btfsc PORTA,0 ; is Start sw. pressed again? goto $-1 call stop call sw_dbnc btfss PORTA,0 ; is Start sw. released? goto $-1 call sw_dbnc goto sel7 ;------------------------------------------- sel8 btfsc PORTA,0 ; is Start sw. pressed? goto $-1 call starton call sw_dbnc btfss PORTA,0 ; is Start sw. released? goto $-1 call sw_dbnc btfsc PORTA,0 ; is Start sw. pressed again? goto $-1 call continue call sw_dbnc btfss PORTA,0 ; is Start sw. released? goto $-1 call sw_dbnc btfsc PORTA,0 ; is Start sw. pressed again? goto $-1 call stop call sw_dbnc btfss PORTA,0 ; is Start sw. released? goto $-1 call sw_dbnc goto sel8 ;------------------------------------------- sel9 movlw .1 ; Portamento time movwf port_time movlw .65 ; Portamento movwf pedal_val call portloop goto sel9 ;------------------------------------------- sel10 movlw .2 ; Portamento time movwf port_time movlw .65 ; Portamento movwf pedal_val call portloop goto sel10 ;------------------------------------------- sel11 movlw .4 ; Portamento time movwf port_time movlw .65 ; Portamento movwf pedal_val call portloop goto sel11 ;------------------------------------------- sel12 movlw .8 ; Portamento time movwf port_time movlw .65 ; Portamento movwf pedal_val call portloop goto sel12 ;------------------------------------------- sel13 movlw .16 ; Portamento time movwf port_time movlw .65 ; Portamento movwf pedal_val call portloop goto sel13 ;------------------------------------------- sel14 movlw .32 ; Portamento time movwf port_time movlw .65 ; Portamento movwf pedal_val call portloop goto sel14 ;------------------------------------------- sel15 movlw .64 ; Portamento time movwf port_time movlw .65 ; Portamento movwf pedal_val call portloop goto sel15 ;------------------------------------------- sel16 movlw .127 ; Portamento time movwf port_time movlw .65 ; Portamento movwf pedal_val call portloop goto sel16 ;------------------------------------------- goto main2 end