;jimkim Looper 2002 on PIC 16F84 ;Important Note: This is the 4 Mhz Version ;Written by Jimkim on 08/2002 ; ;Version 1.00 ; ;F_osc=4MHz list p=16f84 __CONFIG _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF include "p16f84.inc" ;----------------------------------------------------------------------------- ; PIC16C84 PRIVATE REGISTERS ;----------------------------------------------------------------------------- status equ 03 ; status: flags, page register, ... porta equ 05 ; status of the port A's pins trisa equ 05 ; (page 1) port A's IN/OUT direction portb equ 06 ; status of the port B's pins trisb equ 06 ; (page 1) port B's IN/OUT direction eecon1 equ 08 eecon2 equ 09 eedata equ 08 eeadr equ 09 ;----------------------------------------------------------------------------- ; REGISTERS USED IN ROUTINES/PROCEDURES ;----------------------------------------------------------------------------- midi_header equ 0C ; Register for Midi Header midi_pgm equ 0D ; Register containing Midi Program Change value midi_data equ 0E ; Register containing Data for Midi Transmission display_out equ 0F ; Register holding data send to display data_out equ 10 ; Register containing the output switch values bit_count equ 11 ; Bit counter for midi send procedure i_count equ 12 ; Counter variable used in delay routine y_count equ 13 ; Counter variable used in delay routine z_count equ 14 ; Counter variable used in delay routine time equ 15 ; Counter variable used in receiver delay routine bank_value equ 16 ; Register containing Program Bank Value (1-8) patch_value equ 17 ; Register containing Program Patch Value (1-4) bank_count equ 18 ; Register for Midi Pgm assemble routine patch_reg equ 19 ; Register for Display_Out assembling Routine bank_reg equ 1A ; Register for Display_Out assembling Routine count_reg equ 1B ; Counter Variable used for Display_out assembling Routine ;----------------------------------------------------------------------------- ; SIGNIFICATIVE BITS OF PIC16F84 PRIVATE REGISTERS ;----------------------------------------------------------------------------- carry_bit equ 0 ; (status) carry/borrow bit zero_bit equ 2 ; (status) zero bit page_bit equ 5 ; (status) selector of register page ;----------------------------------------------------------------------------- ; CONSTANTS ;----------------------------------------------------------------------------- W equ 0 ;indicates Work Register as destination for the instruction F equ 1 ;indicates File Register as destination for the instruction ;----------------------------------------------------------------------------- ;Instructions start here ;----------------------------------------------------------------------------- org 0 goto start ;----------------------------------------------------------------------------- ;Support routines ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ;delay -- entry with number of ms in w (1 to 255) ;1 cycle = 1 us (MicroSeconds) with F_osc = 4 MHz ;----------------------------------------------------------------------------- delay200 movlw .200 ;Enter here for a 200ms delay movwf y_count ;/ delay200_1 movlw .124 ;load counter z movwf z_count delay200_2 nop ;((N - 1) x 8) + 7 nop nop nop nop decfsz z_count,F goto delay200_2 nop nop decfsz y_count,F goto delay200_1 retlw 0 ;return and set Work Register = 0 ;----------------------------------------------------------------------------- ;delay routine for midi transmit procedure (19 cycles) ;----------------------------------------------------------------------------- midi_delay movlw 5 ;load delay time = 1cycle movwf time ;into counter = 1cycle loop_m_dly decfsz time,1 ;decrease time (4 * 3) + 2 = 14 cycles goto loop_m_dly ;loop nop ;nop = 1cycle return ;and return = 2cycles, 19 cycles altogether ;----------------------------------------------------------------------------- ;general purpose delay routine (25 cycles) ;----------------------------------------------------------------------------- delay25 movlw 7 ;load delay time = 1cycle movwf time ;into counter = 1cycle loop_dly25 decfsz time,1 ;decrease time (6 * 3) + 2 = 20 cycles goto loop_dly25 ;loop nop ;nop = 1cycle return ;and return = 2cycles, 19 cycles altogether ;----------------------------------------------------------------------------- ;Read EEPROM at address which is stored in midi_pgm (Midi Data Register) ;then output data ;----------------------------------------------------------------------------- load_data_out movf midi_pgm, W ;move midi_pgm value into W movwf eeadr ;and set up eeprom address bsf status, page_bit ;shift to bank 1 bsf eecon1, RD ;set the read bit bcf status, page_bit ;shift back to bank 0 movf eedata, W ;return value in w movwf data_out ;save value in 'data_out' register ;----------------------------------------------------------------------------- ;Refresh Outputs ;----------------------------------------------------------------------------- refresh_outs bsf status,page_bit ;Shift to Bank1 of register page movlw b'00000000' ;PortB all outputs movwf trisb bcf status,page_bit ;Shift to Bank0 of register page movf data_out, W ;load 'data_out' value into work register movwf portb ;Trigger outputs according to value read from EEPROM bsf porta, 1 ;clock signal for IC3 call delay25 ;short delay bcf porta, 1 ;clock signal off bsf status,page_bit ;Shift to Bank1 of register page movlw b'11111111' ;PortB all inputs movwf trisb bcf status,page_bit ;Shift to Bank0 of register page return ;----------------------------------------------------------------------------- ;Assemble display_out value ;----------------------------------------------------------------------------- refresh_dspl movf bank_value, W ;load bank_value into work register movwf bank_reg ;and into bank_reg swapf bank_reg, F ;swap half bytes (7Segment LED is on Bit 4-7) movf patch_reg, W ;patch_reg into W addwf bank_reg, W ;bank_reg + patch_reg / result into W movwf display_out ;----------------------------------------------------------------------------- ;Refresh Display ;----------------------------------------------------------------------------- bsf status,page_bit ;Shift to Bank1 of register page movlw b'00000000' ;PortB all outputs movwf trisb bcf status,page_bit ;Shift to Bank0 of register page movf display_out, W ;display value into W movwf portb ;and into PortB bsf porta, 0 ;clock signal for IC2 call delay25 ;short delay bcf porta, 0 ;clock signal off bsf status,page_bit ;Shift to Bank1 of register page movlw b'11111111' ;PortB all inputs movwf trisb bcf status,page_bit ; Shift to Bank0 of register page return ;----------------------------------------------------------------------------- ;Assemble Midi Program Number ;----------------------------------------------------------------------------- assemble_pgm movf bank_value, W ;current bank value into W addlw .1 ;add 1 to bank_value so that bank_value does not get < 0 in following decfsz ;bank_value 0 assembles to midi_pgm 1-4 movwf bank_count ;into bank_count register clrw ;clear W (W=0) next_bank decfsz bank_count, F ;bank_count - 1 / jump if zero goto add_bank ;else add bank (4) goto add_patch ;no more bank to add / now add patch add_bank addlw 04h ;W + 4 goto next_bank ;add another bank (4) add_patch addwf patch_value, W ;W + patch movwf midi_pgm ;calculated value into Midi data register return ;----------------------------------------------------------------------------- ;Midi out -- send a midi byte at 31250 bps ;----------------------------------------------------------------------------- send_midi movlw 08h ;load counter for 8 bits movwf bit_count ;into counter bcf porta, 3 ;send start bit nop ;thes 6 nops plus midi_delay nop ;give 32 cycles (one bit length) nop ;for the start bit nop nop nop call midi_delay ;call delay for Midi routine loop_midi btfsc midi_data, 0 ;check Midi data register goto set_midi goto clear_midi set_midi bsf porta, 3 ;send high bit call midi_delay ;call delay goto continue_midi ;and go on clear_midi bcf porta, 3 ;send low bit call midi_delay ;call delay goto continue_midi ;and go on continue_midi rrf midi_data, 1 ;rotate Midi data register by one decfsz bit_count, 1 ;check bit counter goto loop_midi ;if > 0 then go on bsf porta, 3 ;else send stop bit call midi_delay ;wait some cycles call midi_delay ;wait some more cycles return ;----------------------------------------------------------------------------- ;Main program loop ;----------------------------------------------------------------------------- org 0x0100 start movlw b'01000' ;Preset port A: triggers off (low) except for midi port movwf porta movlw b'00000000' ;Preset port B: triggers off (low) movwf portb bsf status,page_bit ;Shift to Bank1 of register page movlw b'10000' ;PortA 0-3 outputs, 4 input movwf trisa movlw b'00000000' ;PortB all outputs movwf trisb bcf status,page_bit ;Shift to Bank0 of register page ;----------------------------------------------------------------------------- ;Step 1: Count from 0-9 on LED display for Function check ;----------------------------------------------------------------------------- and_again movlw .10 movwf i_count movlw b'00000000' ; movwf display_out ;into display status register display_init swapf display_out, F ;LED Display is driven by higher halfbyte call delay200 call delay200 movf display_out, W ;display value into W movwf portb ;and into PortB bsf porta, 0 ;clock signal for IC2 call delay25 ;short delay bcf porta, 0 ;clock signal off swapf display_out, F ;swap back display value incf display_out, F ;and increment by one decfsz i_count, 1 ;check counter goto display_init ;if counter > 0 then continue bsf status,page_bit ;Shift to Bank1 of register page movlw b'11111111' ;PortB all inputs movwf trisb bcf status,page_bit ;Shift to Bank0 of register page ;----------------------------------------------------------------------------- ;Initialize midi_header, bank and patch ;----------------------------------------------------------------------------- movlw b'11000000' ;Program Change on Channel 1 movwf midi_header ;into register movlw b'00000000' ;Bank 0 movwf bank_value ;into register movlw b'00000001' ;Patch 1 movwf patch_value ;into register movlw b'00000001' ;Patch LED 1 movwf patch_reg ;into register call assemble_pgm ;assemble Program Number call load_data_out ;load output settings for Program 1 call refresh_dspl ;refresh display ;----------------------------------------------------------------------------- ;Check Buttons on PortB; set Outputs according to selection ;----------------------------------------------------------------------------- key_00 btfss portb, 0 ;if key pressed continue goto key_01 ;else check next key call delay25 ;short delay btfss portb, 0 ;check key again to be sure goto key_01 ;no key press/ check next key goto bank_down ;bank down selected key_01 btfss portb, 1 ;if key pressed continue goto key_02 ;else check next key call delay25 ;short delay btfss portb, 1 ;check key again to be sure goto key_02 ;no key press/ check next key goto patch_01 ;patch 1 selected key_02 btfss portb, 2 ;if key pressed continue goto key_03 ;else check next key call delay25 ;short delay btfss portb, 2 ;check key again to be sure goto key_03 ;no key press/ check next key goto patch_02 ;patch 2 selected key_03 btfss portb, 3 ;if key pressed continue goto key_04 ;else check next key call delay25 ;short delay btfss portb, 3 ;check key again to be sure goto key_04 ;no key press/ check next key goto patch_03 ;patch 3 selected key_04 btfss portb, 4 ;if key pressed continue goto key_05 ;else check next key call delay25 ;short delay btfss portb, 4 ;check key again to be sure goto key_05 ;no key press/ check next key goto patch_04 ;patch 4 selected key_05 btfss portb, 5 ;if key pressed continue goto key_edit ;else check next key call delay25 ;short delay btfss portb, 5 ;check key again to be sure goto key_edit ;no key press/ check next key goto bank_up ;bank up selected key_edit btfss porta, 4 ;if key pressed continue goto key_00 ;else check next key call delay25 ;short delay btfss porta, 4 ;check key again to be sure goto key_00 ;no key press/ check next key goto edit_mode ;bank up selected ;----------------------------------------------------------------------------- ;Perform actions according to key pressed ;this is either bank up/down or patch select ;----------------------------------------------------------------------------- bank_down movf bank_value, W ;bank_value into W bcf status,zero_bit;clear Zero-Flag sublw .0 ;check if bank_value is = 0 or higher btfsc status,zero_bit;check if Zero-Flag = 0 / if not, then bank_value is > 0 goto rel_00 ;bank_value = 0 / skip following instructions because bank_value must not be < 0 movlw .1 ;1 into W subwf bank_value, F ;Bank -1 call assemble_pgm ;call Routine which assembles Program Number movf midi_header, W ;midi_header into W movwf midi_data ;and into midi_data register call send_midi ;send header via midi movf midi_pgm, W ;midi program into W movwf midi_data ;and into midi_data register call send_midi ;send program number via midi call load_data_out ;refresh outputs (load data from eeprom) call refresh_dspl ;refresh display rel_00 call delay25 ;short delay btfsc portb, 0 ;button released? goto rel_00 ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 0 ;still released? goto rel_00 ;if not, check again goto key_00 ;return and check keys bank_up movf bank_value, W ;bank_value into W bcf status,zero_bit;clear Zero-Flag sublw .9 ;check if bank_value is = 9 or lower btfsc status,zero_bit;check if Zero-Flag = 0 / if not, then bank_value is < 9 goto rel_05 ;bank_value = 9 / skip following instructions because bank_value must not be > 9 movlw .1 ;1 into W addwf bank_value, F ;Bank +1 call assemble_pgm ;call Routine which assembles Program Number movf midi_header, W ;midi_header into W movwf midi_data ;and into midi_data register call send_midi ;send header via midi movf midi_pgm, W ;midi program into W movwf midi_data ;and into midi_data register call send_midi ;send program number via midi call load_data_out ;refresh outputs (load data from eeprom) call refresh_dspl ;refresh display rel_05 call delay25 ;short delay btfsc portb, 5 ;button released? goto rel_05 ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 5 ;still released? goto rel_05 ;if not, check again goto key_00 ;return and check keys patch_01 movlw .1 ;Patch 1 movwf patch_value ;into register call assemble_pgm ;call Routine which assembles Program Number movf midi_header, W ;midi_header into W movwf midi_data ;and into midi_data register call send_midi ;send header via midi movf midi_pgm, W ;midi program into W movwf midi_data ;and into midi_data register call send_midi ;send program number via midi call load_data_out ;refresh outputs (load data from eeprom) movlw .1 ;Patch 1 / first Patch LED movwf patch_reg ;into patch_reg for patch LEDs call refresh_dspl ;refresh display rel_01 call delay25 ;short delay btfsc portb, 1 ;button released? goto rel_01 ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 1 ;still released? goto rel_01 ;if not, check again goto key_00 ;return and check keys patch_02 movlw .2 ;Patch 2 movwf patch_value ;into register call assemble_pgm ;call Routine which assembles Program Number movf midi_header, W ;midi_header into W movwf midi_data ;and into midi_data register call send_midi ;send header via midi movf midi_pgm, W ;midi program into W movwf midi_data ;and into midi_data register call send_midi ;send program number via midi call load_data_out ;refresh outputs (load data from eeprom) movlw .2 ;Patch 2 / second Patch LED movwf patch_reg ;into patch_reg for patch LEDs call refresh_dspl ;refresh display rel_02 call delay25 ;short delay btfsc portb, 2 ;button released? goto rel_02 ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 2 ;still released? goto rel_02 ;if not, check again goto key_00 ;return and check keys patch_03 movlw .3 ;Patch 2 movwf patch_value ;into register call assemble_pgm ;call Routine which assembles Program Number movf midi_header, W ;midi_header into W movwf midi_data ;and into midi_data register call send_midi ;send header via midi movf midi_pgm, W ;midi program into W movwf midi_data ;and into midi_data register call send_midi ;send program number via midi call load_data_out ;refresh outputs (load data from eeprom) movlw .4 ;Patch 3 / third Patch LED movwf patch_reg ;into patch_reg for patch LEDs call refresh_dspl ;refresh display rel_03 call delay25 ;short delay btfsc portb, 3 ;button released? goto rel_03 ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 3 ;still released? goto rel_03 ;if not, check again goto key_00 ;return and check keys patch_04 movlw .4 ;Patch 2 movwf patch_value ;into register call assemble_pgm ;call Routine which assembles Program Number movf midi_header, W ;midi_header into W movwf midi_data ;and into midi_data register call send_midi ;send header via midi movf midi_pgm, W ;midi program into W movwf midi_data ;and into midi_data register call send_midi ;send program number via midi call load_data_out ;refresh outputs (load data from eeprom) movlw .8 ;Patch 4 / fourth Patch LED movwf patch_reg ;into patch_reg for patch LEDs call refresh_dspl ;refresh display rel_04 call delay25 ;short delay btfsc portb, 4 ;button released? goto rel_04 ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 4 ;still released? goto rel_04 ;if not, check again goto key_00 ;return and check keys ;----------------------------------------------------------------------------- ;Edit Mode; toggle outputs and save to eeprom ;----------------------------------------------------------------------------- edit_mode bsf porta, 2 ;Turn on LED on PortB2 to indicate Programming Mode ;----------------------------------------------------------------------------- ;wait until edit button has been released ;----------------------------------------------------------------------------- key_rel call delay25 ;short delay btfsc porta, 4 ;button released? goto key_rel ;if not, check again call delay25 ;short delay btfsc porta, 4 ;still released? goto key_rel ;if not, check again key_00_b btfss portb, 0 ;if key pressed continue goto key_01_b ;else check next key call delay25 ;short delay btfss portb, 0 ;check key again to be sure goto key_01_b ;no key press/ check next key goto toggle_out1 ;toggle out 1 key_01_b btfss portb, 1 ;if key pressed continue goto key_02_b ;else check next key call delay25 ;short delay btfss portb, 1 ;check key again to be sure goto key_02_b ;no key press/ check next key goto toggle_out2 ;toggle out 2 key_02_b btfss portb, 2 ;if key pressed continue goto key_03_b ;else check next key call delay25 ;short delay btfss portb, 2 ;check key again to be sure goto key_03_b ;no key press/ check next key goto toggle_out3 ;toggle out 3 key_03_b btfss portb, 3 ;if key pressed continue goto key_04_b ;else check next key call delay25 ;short delay btfss portb, 3 ;check key again to be sure goto key_04_b ;no key press/ check next key goto toggle_out4 ;toggle out 4 key_04_b btfss portb, 4 ;if key pressed continue goto key_05_b ;else check next key call delay25 ;short delay btfss portb, 4 ;check key again to be sure goto key_05_b ;no key press/ check next key goto toggle_out5 ;toggle out 5 key_05_b btfss portb, 5 ;if key pressed continue goto key_06_b ;else check next key call delay25 ;short delay btfss portb, 5 ;check key again to be sure goto key_06_b ;no key press/ check next key goto toggle_out6 ;toggle out 6 key_06_b btfss portb, 6 ;if key pressed continue goto key_07_b ;else check next key call delay25 ;short delay btfss portb, 6 ;check key again to be sure goto key_07_b ;no key press/ check next key goto toggle_out7 ;toggle out 7 key_07_b btfss portb, 7 ;if key pressed continue goto key_esc_edit ;else check next key call delay25 ;short delay btfss portb, 7 ;check key again to be sure goto key_esc_edit ;no key press/ check next key goto toggle_out8 ;toggle out 8 key_esc_edit btfss porta, 4 ;if key pressed continue goto key_00_b ;else check next key call delay25 ;short delay btfss porta, 4 ;check key again to be sure goto key_00_b ;no key press/ check next key goto esc_edit_mode ;escape edit mode selected ;----------------------------------------------------------------------------- ;toggle outputs according to key press ;----------------------------------------------------------------------------- toggle_out1 btfsc data_out, 0 ;check current state of output goto clear_out1 ;if output is set, then clear output set_out1 bsf data_out, 0 ;set bit in data_out register goto refresh1 ;jump and check if key has been released clear_out1 bcf data_out, 0 ;clear bit in data_out register refresh1 call refresh_outs ;update outputs rel_00_b call delay25 ;short delay btfsc portb, 0 ;button released? goto rel_00_b ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 0 ;still released? goto rel_00_b ;if not, check again goto key_00_b ;return and check keys toggle_out2 btfsc data_out, 1 ;check current state of output goto clear_out2 ;if output is set, then clear output set_out2 bsf data_out, 1 ;set bit in data_out register goto refresh2 ;jump and check if key has been released clear_out2 bcf data_out, 1 ;clear bit in data_out register refresh2 call refresh_outs ;update outputs rel_01_b call delay25 ;short delay btfsc portb, 1 ;button released? goto rel_01_b ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 1 ;still released? goto rel_01_b ;if not, check again goto key_00_b ;return and check keys toggle_out3 btfsc data_out, 2 ;check current state of output goto clear_out3 ;if output is set, then clear output set_out3 bsf data_out, 2 ;set bit in data_out register goto refresh3 ;jump and check if key has been released clear_out3 bcf data_out, 2 ;clear bit in data_out register refresh3 call refresh_outs ;update outputs rel_02_b call delay25 ;short delay btfsc portb, 2 ;button released? goto rel_02_b ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 2 ;still released? goto rel_02_b ;if not, check again goto key_00_b ;return and check keys toggle_out4 btfsc data_out, 3 ;check current state of output goto clear_out4 ;if output is set, then clear output set_out4 bsf data_out, 3 ;set bit in data_out register goto refresh4 ;jump and check if key has been released clear_out4 bcf data_out, 3 ;clear bit in data_out register refresh4 call refresh_outs ;update outputs rel_03_b call delay25 ;short delay btfsc portb, 3 ;button released? goto rel_03_b ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 3 ;still released? goto rel_03_b ;if not, check again goto key_00_b ;return and check keys toggle_out5 btfsc data_out, 4 ;check current state of output goto clear_out5 ;if output is set, then clear output set_out5 bsf data_out, 4 ;set bit in data_out register goto refresh5 ;jump and check if key has been released clear_out5 bcf data_out, 4 ;clear bit in data_out register refresh5 call refresh_outs ;update outputs rel_04_b call delay25 ;short delay btfsc portb, 4 ;button released? goto rel_04_b ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 4 ;still released? goto rel_04_b ;if not, check again goto key_00_b ;return and check keys toggle_out6 btfsc data_out, 5 ;check current state of output goto clear_out6 ;if output is set, then clear output set_out6 bsf data_out, 5 ;set bit in data_out register goto refresh6 ;jump and check if key has been released clear_out6 bcf data_out, 5 ;clear bit in data_out register refresh6 call refresh_outs ;update outputs rel_05_b call delay25 ;short delay btfsc portb, 5 ;button released? goto rel_05_b ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 5 ;still released? goto rel_05_b ;if not, check again goto key_00_b ;return and check keys toggle_out7 btfsc data_out, 6 ;check current state of output goto clear_out7 ;if output is set, then clear output set_out7 bsf data_out, 6 ;set bit in data_out register goto refresh7 ;jump and check if key has been released clear_out7 bcf data_out, 6 ;clear bit in data_out register refresh7 call refresh_outs ;update outputs rel_06_b call delay25 ;short delay btfsc portb, 6 ;button released? goto rel_06_b ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 6 ;still released? goto rel_06_b ;if not, check again goto key_00_b ;return and check keys toggle_out8 btfsc data_out, 7 ;check current state of output goto clear_out8 ;if output is set, then clear output set_out8 bsf data_out, 7 ;set bit in data_out register goto refresh8 ;jump and check if key has been released clear_out8 bcf data_out, 7 ;clear bit in data_out register refresh8 call refresh_outs ;update outputs rel_07_b call delay25 ;short delay btfsc portb, 7 ;button released? goto rel_07_b ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc portb, 7 ;still released? goto rel_07_b ;if not, check again goto key_00_b ;return and check keys ;----------------------------------------------------------------------------- ;write new data to EEPROM/ first check if button has been released ;----------------------------------------------------------------------------- esc_edit_mode nop rel_edit_key call delay25 ;short delay btfsc porta, 4 ;button released? goto rel_edit_key ;if not, check again call delay200 ;slightly longer delay (for debouncing of keys) btfsc porta, 4 ;still released? goto rel_edit_key ;if not, check again movf midi_pgm, W ;move recv value into W (last midi program change) movwf eeadr ;and set up eeprom address movf data_out, W ;move data_out value into W (output switch settings) movwf eedata ;and set up eedata value bsf status, RP0 ;shift to bank 1 bsf eecon1, WREN ;enable write to EEPROM movlw 55h ;sequence which initializes write process movwf eecon2 movlw 0AAh movwf eecon2 bsf eecon1, WR call delay25 ;short delay (about 25 us) to complete write process eeloop btfsc eecon1, WR ;wait for WR to go low (write process completed) goto eeloop bcf eecon1, WREN ;disable write to EEPROM bcf status, RP0 ;shift back to bank 0 ;----------------------------------------------------------------------------- ;Turn off LED that indicates Programming mode ;return and check keys for next command ;----------------------------------------------------------------------------- bcf porta, 2 goto key_00 ;----------------------------------------------------------------------------- ;That's it, pal! ;----------------------------------------------------------------------------- end