;-----------------------------------------------------------------------------------------------; ; Program: CVS4 Alesis HR-16 Divider Sequencer ; ; Developed by David J. Brown ; ; Copyright (c) April 13, 2004 David J. Brown ; ; Email: davebr@earthlink.net ; ; Web site: http://modularsynthesis.com ; ;-----------------------------------------------------------------------------------------------; ; LICENSE AGREEMENT: ; ; This program is free software. You can redistribute it and/or modify it. ; ; ; ; This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, ; ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ; ;-----------------------------------------------------------------------------------------------; ; ; Description: ; This program maps a 10 volt control voltage on four channels to 1 of 16 drum samples on an ; Alesis HR-16 Digital Drum Machine on the rising edge of Aux In. Velocity is fixed at 64. ; ; Each of the four input channels has a corresponding enable counter. The counter high and low ; count is selected from one of eight patterns by an input control voltage. The counter false ; output (0V) mutes the corresponding drum channel and the counter true output (10V) enables the ; corresponding drum channel. Patterns and drum names are displayed on the LCD. ; ; Counters 1 and 2 share patterns and counters 3 and 4 share a different set of patterns. ; Counters 1 and 2 can be set to can be continous on. ; ; Start begins the drum sequence. Stop disables the drum sequence and resets the counters. ; ; 0.00V - 0.63V = kick, midi note 35 ; 0.63V - 1.25V = snare, midi note 38 ; 1.25V - 1.88V = claps, midi note 39 ; 1.88V - 2.50V = tom3, midi note 41 ; 2.50V - 3.13V = closed hat, midi note 42 ; 3.13V - 3.75V = mid hat, midi note 44 ; 3.75V - 4.38V = tom2, midi note 45 ; 4.38V - 5.00V = open hat, midi note 46 ; 5.00V - 5.63V = tom1, midi note 48 ; 5.63V - 6.25V = crash, midi note 49 ; 6.25V - 6.88V = ride, midi note 51 ; 6.88V - 7.50V = perc2, midi note 62 ; 7.50V - 8.13V = tom4, midi note 63 ; 8.13V - 8.75V = perc1, midi note 65 ; 8.75V - 9.38V = perc3, midi note 67 ; 9.38V - 10.0V = perc4, midi note 68 ; ; Inputs: ; Start = Starts ; Stop = Stops and resets ; In-1 = channel 1 cv ; In-2 = channel 1 count selection ; In-3 = channel 2 cv ; In-4 = channel 2 count selection ; In-5 = channel 3 cv ; In-6 = channel 3 count selection ; In-7 = channel 4 cv ; In-8 = channel 4 count selection ; Aux = clock in ; Midi-In = ; ; Outputs: ; Out-1 = LED indication of In-1 ; Out-2 = LED indication of channel 1 enable (on=enable) ; Out-3 = LED indication of In-2 ; Out-4 = LED indication of channel 2 enable (on=enable) ; Out-5 = LED indication of In-3 ; Out-6 = LED indication of channel 3 enable (on=enable) ; Out-7 = LED indication of In-4 ; Out-8 = LED indication of channel 4 enable (on=enable) ; Aux = ; Midi-Out= HR-16 MIDI ; SpeakJet= ; ; Display = displays program name and drum names ; Run led = toggles @ 0.5 S (timer interrupts enabled) ; Stop led= blinks on rising edge of Aux In ; ; Revision: 0.0S2 ; Date Sept 23, 2010 ; History: 0.0S2 changed serial for Studio 2 ; 0.0S initial release of program ; Written: June 13, 2010 ; ;---------PSIM, CVS, OR CVS-4 CONDITIONAL COMPILE OPTION----------------------------------------; ; ; ; UNCOMMENT ONE OF NEXT THREE LINES TO SELECT TARGET MODULE ; cvs con 1 ;define for CVS module ; ;cvs4 con 1 ;define for 4 channel CVS module ; ;psim con 1 ;define for PSIM module ; ;-----------------------------------------------------------------------------------------------; ;---------SPEAKJET CONDITIONAL COMPILE OPTION---------------------------------------------------; ; ; ; UNCOMMENT NEXT LINE IF SPEAKJET HARDWARE USED ; ;spj con 1 ;define for SpeakJet hardware ; ;-----------------------------------------------------------------------------------------------; ;---------ENABLE AUX_IN RISING EDGE INTERRUPT CONDITIONAL COMPILE OPTION------------------------; ; ; ; COMMENT OUT NEXT LINE TO DISABLE AUX INPUT RISING EDGE INTERRUPTS ; ;aux_int_en con 1 ;define to enable aux_in rising edge interrupts ; ; ;comment to disable aux_in rising edge interrupts ; ;-----------------------------------------------------------------------------------------------; ;---------ENABLE TIMER INTERRUPT CONDITIONAL COMPILE OPTION-------------------------------------; ; Notes: run led will blink to verify timer operation ; ; ; ; COMMENT OUT NEXT LINE TO DISABLE TIMER INTERRUPTS ; ;timer_int_en con 1 ;define to enable timer interrupts ; ; ;comment to disable timer interrupts ; ; ; ; ;------ENABLE AVERAGED ANALOG-IN IN TIMER INTERRUPT CONDITIONAL COMPILE OPTION------------; ; ; ; Note: requires timer_int_en to be defined ; ; ; ; ; ; ; ; COMMENT OUT NEXT LINE TO DISABLE ANALOG-IN ON TIMER INTERRUPTS/ENABLE POLLED ANALOG-IN ; ; ;input_int_en con 1 ;define to enable input interrupt mode ; ; ; ; ;comment to set polled input mode ; ; ; ;-----------------------------------------------------------------------------------------; ; ; ; ; ;------ENABLE RISING EDGE DETECT IN TIMER INTERRUPT CONDITIONAL COMPILE OPTION------------; ; ; ; Note: requires timer_int_en to be defined ; ; ; ; pulse must be > 1 mS and > 8 mS period (7 timer clocks low / 1 timer clock high) ; ; ; ; ; ; ; ; COMMENT OUT NEXT LINE TO DISABLE RISING EDGE DETECT IN TIMER INTERRUPTS ; ; ;edge_int_en con 1 ;define to enable rising edge detect mode ; ; ; ; ;comment to disable rising edge detect mode ; ; ; ; UNCOMMENT ONE OF NEXT THREE LINES TO SELECT INPUT FOR RISING EDGE DETECT ; ; ;edge_in var in4 ;use start jack for rising edge detect input ; ; ;edge_in var in5 ;use stop jack for rising edge detect input ; ; ;edge_in var in8 ;use aux jack for rising edge detect input ; ; ; ;-----------------------------------------------------------------------------------------; ; ; ; ;-----------------------------------------------------------------------------------------------; ; Program: PSIM-CVS-CVS4 Template ; Developed by David J. Brown ; Revision: 1.5S ; Date: April 14, 2010 ; History: 1.62 included MIDI text string tables and NV memory map, ; added speakjet conditional compile ; 1.5S changed i2cin, i2cout, and shiftout for Studio ; 1.5 fixed midi sysex, added pin modifications for IDE 8.0.1.7 ; 1.4 fixed hex2ascii ; 1.3 added 4 channel CVS configuration, replaced variable ; tmp_dig with tempb ; 1.2 removed all push/pop commands, simplified hex2ascii ; 1.1 added subroutines for programmed characters ; 1.0 added CVS configuration and midi processor code, ; simplified hex2ascii and changed from byte to word, ; added get_inputs_hy, rewrote display_in and display_out ; 0.8 removed conditionals for MIDI interrupts, deleted ; polled routines check_midi and get_rcx_bfr, deleted ; obsolete debug_led and hex_console routines, optimized ; midi command subroutines ; 0.7 converted speakjet to i2c protocol, modified speakjet ; phrase definitions and changed hex_speakjet ; 0.66 added edge_flg to detect rising edges in timer isr, ; added aux_cnt for aux_in rising edge interrupts, added ; display command summary ; 0.65 added display_in to display four input voltages, ; added display_out to display four output voltages, ; programmed voltage characters, updated sample code, ; added GPL ; 0.64 added hex2ascii for conversion with leading 0's, ; default display message, removed serial hex_led routine ; 0.63 removed 'high midi_sdata' command which limited ; TxD (P15) to V(ol)=1.5 volts ; 0.62 added hex_lcd routine, changed debug_data to ; data_hex, changed debug_speakjet to hex_speakjet, ; debug_led to hex_led, and debug_console to hex_console, ; added start message ; 0.61 change dirs command for MIDI out pin, changed ; load_outputs to 'or' instead of 'add' ; 0.6 changed midi drivers to use hserial interrupt ; mechanism ; 0.51 changed midi-out during timer interrupt to use ; timerA on 512 uS ; 0.5 added midi-out during timer interrupt, added ; put_tx_bfr, modified send_midi routine, added ; conditional midi-out compile option, added send_cc ; 0.44 streamlined debug_speakjet routine, changed ; gra divisor from 2000 to 2001 for accurate time ; 0.43 corrected send_speakjet pin label error, changed ; display_led to debug_led, changed send_console to ; debug_console, added debug_speakjet routine, changed ; led_data and con_data to debug_data ; 0.42 renamed start_b to start_j, renamed stop_b to ; stop_j, added push/pop to display_led, changed ; comment delimiter to semicolon, added send_console ; routine, re-aliased input pins, sends midi all notes ; off during initialization, added midi program change ; 0.41 upper case conversion to lower, variables and ; labels renamed ; 0.4 added averaged input input driver (polled or ; interrupt mode), display_led driver (for debug), ; speakjet driver, renamed program to djb template ; 0.3 added program header information, modified ; pin initialization ; 0.2 initialize aux output low and speakjet pins ; 0.1 added DAC & led initialization, 1 mS timestamp, ; stop led blinks when midi data received, run ; led toggles @ 0.5 S for health indication ; 0.0 initial release of midi input & output program ; Written: April 13, 2004 ; ;-----------------------------------------------------------------------------------------------; ; AtomPro Pin Definitions ; ;-----------------------------------------------------------------------------------------------; ; P0 - analog in-1 ; ; P1 - analog in-2 ; ; P2 - analog in-3 ; ; P3 - analog in-4 ; ; P4 - start button (no input/default=low, pressed=hi) ; ; P5 - stop button (no input/default=low, pressed=hi) ; ; P6 - I2C data ; ; P7 - I2C clock ; ; P8 - aux in/out (PSIM: no input=hi, CVS: no input=low) ; ; P9 - stop led (low=off, hi=on) ; ; P10 - run led (low=off hi=on) ; ; P11 - DAC loaddacs ; ; P12 - DAC serial data ; ; P13 - DAC clock ; ; P14 - MIDI in ; ; P15 - MIDI out ; ; P16 - analog in-5 (CVS) ; ; P17 - analog in-6 (CVS) ; ; P18 - analog in-7 (CVS) ; ; P19 - analog in-8 (CVS) ; ;-----------------------------------------------------------------------------------------------; ; LCD Commands ; ;-----------------------------------------------------------------------------------------------; ; $08 - (backspace) moves the active display position one backwards ; ; $09 - (tab) moves the active display position one forward ; ; $0a - (line feed) clears the display & sets active display position to beginning of line 1 ; ; $0b - (vertical tab) sets the active display position to beginning of line 2 ; ; $0c - (form feed) clears the display & sets active display position to beginning of line 2 ; ; $0d - (carriage return) Sets the active display position to beginning of line 1 ; ; $0e - (shift out) selects the lower characters set for display ; ; $0f - (shift in) selects the upper characters set for display ; ; $10 - program character0 row7, row6 ... row0 (bottom) ; ; $11 - program character1 row7, row6 ... row0 (bottom) ; ; $12 - program character2 row7, row6 ... row0 (bottom) ; ; $13 - program character3 row7, row6 ... row0 (bottom) ; ; $14 - program character4 row7, row6 ... row0 (bottom) ; ; $15 - program character5 row7, row6 ... row0 (bottom) ; ; $16 - program character6 row7, row6 ... row0 (bottom) ; ; $17 - program character7 row7, row6 ... row0 (bottom) ; ; $18 - sets the display mode to overwrite; new characters overwrite previous ; ; $19 - sets the display mode to scroll; display scrolls for new characters ; ; $1a - sets absolute position data ; ; $1b - sets relative position data ; ; $1c - n/a ; ; $1d - n/a ; ; $1e - n/a ; ; $1f - writes new default message character 1, character 2 ... character 32 ; ; ; LCD Commands (DJB-PSIM) ; ; $1a - n/a ; ; $1b - n/a ; ; $1c - set Out1 data (0=no change, 1=reset to low, 2=set to hi, 3=toggle) ; ; $1d - set Out2 data (0=no change, 1=reset to low, 2=set to hi, 3=toggle) ; ; $1e - set Out3 data (0=no change, 1=reset to low, 2=set to hi, 3=toggle) ; ; $1f - set Out4 data (0=no change, 1=reset to low, 2=set to hi, 3=toggle) ; ;-----------------------------------------------------------------------------------------------; ; TTS-256 Commands (DJB-PSIM) ; ;-----------------------------------------------------------------------------------------------; ; enable TTS256 pass through: i2cout i2c_data,i2c_clk,$0,[($48<<1),"passthruon",$0d] ; ; terminate TTS256 pass through: i2cout i2c_data,i2c_clk,$0,[($48<<1),"X"] ; ;-----------------------------------------------------------------------------------------------; ; SpeakJet Commands (DJB-PSIM) ; ;-----------------------------------------------------------------------------------------------; ; $00 - pause 0 mS ; ; $01 - pause 100 mS ; ; $02 - pause 200 mS ; ; $03 - pause 700 mS ; ; $04 - pause 30 mS ; ; $05 - pause 60 mS ; ; $06 - pause 90 mS ; ; $07 - play next sound fast ; ; $08 - play next sound slow ; ; $0e - play next sound high tone ; ; $0f - play next sound low tone ; ; $15 - speed ; ; $16 - pitch ; ; $17 - pitch ; ; $c8 to $d1 - robot sounds ; ; $d2 to $db - alarm sounds ; ; $dc to $e5 - beep sounds ; ; $e6 to $ef - biological sounds ; ; $f0 to $fb - DTMF sounds (0 - 9, *, #) ; ; $fc - sonar ping ; ; $fd - pistol shot ; ; $fe - wow ; ;-----------------------------------------------------------------------------------------------; ; Non-Volatile Memory Map ; ;-----------------------------------------------------------------------------------------------; nv_step_max con 0 ;adr000 step_max nv_midi_offset con 1 ;adr001 midi_offset nv_gate1_lo con 2 ;adr002 gate1.byte0 nv_gate1_hi con 3 ;adr003 gate1.byte1 nv_gate2_lo con 4 ;adr004 gate2.byte0 nv_gate2_hi con 5 ;adr005 gate2.byte1 nv_patch con 6 ;16 byte patch array ;nv_patch(0) con 6 ;adr006 step 1 patch ;nv_patch(1) con 7 ;adr007 step 2 patch ;nv_patch(2) con 8 ;adr008 step 3 patch ;nv_patch(3) con 9 ;adr009 step 4 patch ;nv_patch(4) con 10 ;adr010 step 5 patch ;nv_patch(5) con 11 ;adr011 step 6 patch ;nv_patch(6) con 12 ;adr012 step 7 patch ;nv_patch(7) con 13 ;adr013 step 8 patch ;nv_patch(8) con 14 ;adr014 step 9 patch ;nv_patch(9) con 15 ;adr015 step 10 patch ;nv_patch(10) con 16 ;adr016 step 11 patch ;nv_patch(11) con 17 ;adr017 step 12 patch ;nv_patch(12) con 18 ;adr018 step 13 patch ;nv_patch(13) con 19 ;adr019 step 14 patch ;nv_patch(14) con 20 ;adr020 step 15 patch ;nv_patch(15) con 21 ;adr021 step 16 patch nv_seq_mode con 22 ;adr022 seq_mode nv_unused con 23 ;unused address ;-----------------------------------------------------------------------------------------------; ; Pin Declarations ; ;-----------------------------------------------------------------------------------------------; pin_j1 con p0 ;in-1 pin pin_j2 con p1 ;in-2 pin pin_j3 con p2 ;in-3 pin pin_j4 con p3 ;in-4 pin #ifdef cvs ;these pin definitions changed between IDE 8.0.1.0 and 8.0.1.7 ;uncomment the correct definitions for the version of IDE ;-----------------------------------------------------------------------------------------------; ;IDE 8.0.1.0 and previous ; ; pin_j5 con p16 ;in-5 pin ; ; pin_j6 con p17 ;in-6 pin ; ; pin_j7 con p18 ;in-7 pin ; ; pin_j8 con p19 ;in-8 pin ; ;-----------------------------------------------------------------------------------------------; ;IDE 8.0.1.7 ; pin_j5 con p18 ;in-5 pin ; pin_j6 con p19 ;in-6 pin ; pin_j7 con p17 ;in-7 pin ; pin_j8 con p16 ;in-8 pin ; ;-----------------------------------------------------------------------------------------------; #endif start_j var in4 ;start jack and switch stop_j var in5 ;stop jack and switch i2c_data con p6 ;i2c data pin i2c_clk con p7 ;i2c clock pin aux_j con p8 ;aux jack (use for output) aux_in var in8 ;aux jack (use for input) stop_led con p9 ;stop led stop_led_out var out9 ;stop led alias (for use with LET command) run_led con p10 ;run led run_led_out var out10 ;run led alias (for use with LET command) dac_load con p11 ;dac loaddacs pin dac_sdata con p12 ;dac serial data pin dac_clk con p13 ;dac clock pin ;-----------------------------------------------------------------------------------------------; ; I/O Declarations ; ;-----------------------------------------------------------------------------------------------; in_j1 var word ;in-1 value: get_inputs, get_inputs_avg, avg1 in_j2 var word ;in-2 value: get_inputs, get_inputs_avg, avc2 in_j3 var word ;in-3 value: get_inputs, get_inputs_avg, avg3 in_j4 var word ;in-4 value: get_inputs, get_inputs_avg, avg4 #ifdef cvs in_j5 var word ;in-5 value: get_inputs, get_inputs_avg, avg1 in_j6 var word ;in-6 value: get_inputs, get_inputs_avg, avc2 in_j7 var word ;in-7 value: get_inputs, get_inputs_avg, avg3 in_j8 var word ;in-8 value: get_inputs, get_inputs_avg, avg4 #endif out_j1 var word ;out-1 value: load_outputs out_j2 var word ;out-2 value: load_outputs out_j3 var word ;out-3 value: load_outputs out_j4 var word ;out-4 value: load_outputs #ifdef cvs out_j5 var word ;out-5 value: load_outputs out_j6 var word ;out-6 value: load_outputs out_j7 var word ;out-7 value: load_outputs out_j8 var word ;out-8 value: load_outputs #endif #ifndef psim olat var byte ;control output latch: load_outputs ; bit7=dac2 select (hi=enable) ; bit6=dac1 select (hi=enable) ; bit5=n/a ; bit4=n/a ; bit3=n/a ; bit2=offset range (hi=5 volts, low=10 volts) ; bit1=offset voltage enable (hi=enable) ; bit0=control voltage enable (hi=enable) #endif ;-----------------------------------------------------------------------------------------------; ; MIDI Declarations ; ;-----------------------------------------------------------------------------------------------; allup con $7b ;midi all notes-off command keyup con $80 ;midi note-off command keydn con $90 ;midi note-on command conctrl con $b0 ;midi continuous controller command pgmchg con $c0 ;midi program change command chnprs con $d0 ;midi channel pressure command pitchb con $e0 ;midi pitch bend command midi_chan var nib ;midi channel: send_note_on, send_note_off, send_cc, send_prog_change midi_note var byte ;midi note value: send_note_on, send_note_off midi_vel var byte ;midi velocity value: send_note_on, send_note_off midi_pgm var byte ;midi program change value: send_prog_change midi_cc var byte ;midi continuous controller number: send_cc trans_chan var byte ;midi in channel transpose (added to midi channel) trans_note var byte ;midi in note tranpose (added to note value) last_cmd var byte ;last midi command for running status midi_cmd var byte ;branch address for running status sys_cmd var byte ;branch address for system commands midi_data var byte ;variable: send_midi, get_rcx_bfr, send_note_on, send_note_off rcx_data_flg var bit ;received data flag (1=data, 0=no data): get_rcx_bfr ;-----------------------------------------------------------------------------------------------; ; Timer Declarations ; ;-----------------------------------------------------------------------------------------------; #ifdef timer_int_en time_count var long ;1 mS timer count value: tm_isr turn_off var long ;time value to turn off stop led: tm_isr #endif ;-----------------------------------------------------------------------------------------------; ; Edge Detect Declarations ; ;-----------------------------------------------------------------------------------------------; #ifdef edge_int_en edge_state var byte ;eight samples of edge input: tm_isr edge_flg var byte ;edge flag (1=rising edge, 0=no rising edge): tm_isr #endif #ifdef aux_int_en aux_cnt var word ;aux interrupt count: aux_isr #endif ;-----------------------------------------------------------------------------------------------; ; Input Buffer Declarations ; ;-----------------------------------------------------------------------------------------------; in_j1_ptr var byte ;in-1 buffer pointer: avgx, get_inputs_avg isr_cnt var nib ;timer pass counter: tm_isr (always define due to conditionals) #ifdef input_int_en in_j2_ptr var byte ;in-2 buffer pointer: avgx in_j3_ptr var byte ;in-3 buffer pointer: avgx in_j4_ptr var byte ;in-4 buffer pointer: avgx in_j5_ptr var byte ;in-5 buffer pointer: avgx in_j6_ptr var byte ;in-6 buffer pointer: avgx in_j7_ptr var byte ;in-7 buffer pointer: avgx in_j8_ptr var byte ;in-8 buffer pointer: avgx #endif in_j1_tmp var long ;in-1 temporary variable: avgx, get_inputs_avg in_j2_tmp var long ;in-2 temporary variable: avgx, get_inputs_avg in_j3_tmp var long ;in-3 temporary variable: avgx, get_inputs_avg in_j4_tmp var long ;in-4 temporary variable: avgx, get_inputs_avg #ifdef cvs in_j5_tmp var long ;in-5 temporary variable: avgx, get_inputs_avg in_j6_tmp var long ;in-6 temporary variable: avgx, get_inputs_avg in_j7_tmp var long ;in-7 temporary variable: avgx, get_inputs_avg in_j8_tmp var long ;in-8 temporary variable: avgx, get_inputs_avg #endif in_j1_bfr var long(2) ;in-1 last 4 samples buffer: avgx, get_inputs_avg in_j2_bfr var long(2) ;in-2 last 4 samples buffer: avgx, get_inputs_avg in_j3_bfr var long(2) ;in-3 last 4 samples buffer: avgx, get_inputs_avg in_j4_bfr var long(2) ;in-4 last 4 samples buffer: avgx, get_inputs_avg #ifdef cvs in_j5_bfr var long(2) ;in-5 last 4 samples buffer: avgx, get_inputs_avg in_j6_bfr var long(2) ;in-6 last 4 samples buffer: avgx, get_inputs_avg in_j7_bfr var long(2) ;in-7 last 4 samples buffer: avgx, get_inputs_avg in_j8_bfr var long(2) ;in-8 last 4 samples buffer: avgx, get_inputs_avg #endif #ifdef psim hys con 3 ;PSIM hysteresis +/- value #else hys con 1 ;CVS hysteresis +/- value #endif in_j1_low var word ;in-1 low value: get_inputs_hy in_j1_high var word ;in-1 high value: get_inputs_hy in_j2_low var word ;in-2 low value: get_inputs_hy in_j2_high var word ;in-2 high value: get_inputs_hy in_j3_low var word ;in-3 low value: get_inputs_hy in_j3_high var word ;in-3 high value: get_inputs_hy in_j4_low var word ;in-4 low value: get_inputs_hy in_j4_high var word ;in-4 high value: get_inputs_hy #ifdef cvs in_j5_low var word ;in-5 low value: get_inputs_hy in_j5_high var word ;in-5 high value: get_inputs_hy in_j6_low var word ;in-6 low value: get_inputs_hy in_j6_high var word ;in-6 high value: get_inputs_hy in_j7_low var word ;in-7 low value: get_inputs_hy in_j7_high var word ;in-7 high value: get_inputs_hy in_j8_low var word ;in-8 low value: get_inputs_hy in_j8_high var word ;in-8 high value: get_inputs_hy #endif ;-----------------------------------------------------------------------------------------------; ; LCD Declarations ; ;-----------------------------------------------------------------------------------------------; num_data var word ;data for ascii conversion: hex2ascii tths var byte ;ten thousands digit: hex2ascii thos var byte ;thousands digit: hex2ascii huns var byte ;hundreds digit: hex2ascii tens var byte ;tens digit: hex2ascii, display_in, display_out ones var byte ;ones digit: hex2ascii, display_in, display_out #ifndef psim ;-----------------------------------------------------------------------------------------------; ; External Controls Declarations ; ;-----------------------------------------------------------------------------------------------; ext_ctrl var byte ;external control flag (1=present, 0=not present): check_ext key_data var byte ;keypad data: key_keynum key_prev var byte ;previous keypad data: key_keynum key_temp var byte ;temp keypad: key_keynum key_entry var word ;0-999 keypad entry: get_keyentry #endif ;-----------------------------------------------------------------------------------------------; ; Speakjet Declarations ; ;-----------------------------------------------------------------------------------------------; #ifdef spj spkj_data var byte ;data: send_speakjet phrase1 var byte ;temporary variable: hex_speakjet phrase2 var byte ;temporary variable: hex_speakjet data_hex var byte ;hex data: hex_speakjet #endif ;-----------------------------------------------------------------------------------------------; ; Misc Declarations ; ;-----------------------------------------------------------------------------------------------; tempb var byte ;temporary variable tempw var word ;temporary variable fivevolts con 1920 ;5 volt output value #ifdef cvs gra_val con 2003 ;measured resonator divisor for 1 mS #endif #ifdef cvs4 gra_val con 2000 ;measured resonator divisor for 1 mS #endif #ifdef psim gra_val con 2005 ;measured resonator divisor for 1 mS #endif out2_hi var byte ;counter 1 hi time clocks out2_lo var byte ;counter 1 lo time clocks out4_hi var byte ;counter 2 hi time clocks out4_lo var byte ;counter 2 lo time clocks out6_hi var byte ;counter 3 hi time clocks out6_lo var byte ;counter 3 lo time clocks out8_hi var byte ;counter 4 hi time clocks out8_lo var byte ;counter 4 lo time clocks out2_cnt_hi var byte ;out 1 counter hi out2_cnt_lo var byte ;out 1 counter lo out4_cnt_hi var byte ;out 2 counter hi out4_cnt_lo var byte ;out 2 counter lo out6_cnt_hi var byte ;out 3 counter hi out6_cnt_lo var byte ;out 3 counter lo out8_cnt_hi var byte ;out 4 counter hi out8_cnt_lo var byte ;out 4 counter lo ;-----------------------------------------------------------------------------------------------; ; Tables ; ;-----------------------------------------------------------------------------------------------; phrase bytetable "0123456789ABCDEF" ;tts256 digit phrases for hex output step_tbl bytetable 256,128,86,64,52,43,37,32,29,26,24,22,20,19,18,17 ;byte to step max divisors note_tbl bytetable "C C",$02,"D D",$02,"E F F",$02,"G G",$02,"A A",$02,"B ";semitone number to note conversion gate_tbl bytetable "084C2A6E195D3B7F" ;gate hex value conversion patch_tbl bytetable | ;GM instrument patch names "AcouGrnd", | ; 1 "BrightAc", | ; 2 "ElecGrnd", | ; 3 "HonkyTnk", | ; 4 "ElPiano1", | ; 5 "ElPiano2", | ; 6 "Harpscrd", | ; 7 "Clavinet", | ; 8 "Celesta ", | ; 9 "Glcknspl", | ;10 "MusicBox", | ;11 "Vibraphn", | ;12 "Marimba ", | ;13 "Xylophon", | ;14 "TubBells", | ;15 "Dulcimer", | ;16 "Drawbar ", | ;17 "Perc Org", | ;18 "Rock Org", | ;19 "Church ", | ;20 "Reed Org", | ;21 "Acordian", | ;22 "Harmnica", | ;23 "TangoAcc", | ;24 "NylonGtr", | ;25 "SteelGtr", | ;26 "Jazz Gtr", | ;27 "CleanGtr", | ;28 "MutedGtr", | ;29 "OverDriv", | ;30 "Distortn", | ;31 "Harmonic", | ;32 "AcouBass", | ;33 "FingerAc", | ;34 "PickBass", | ;35 "Fretless", | ;36 "Slp1Bass", | ;37 "Slp2Bass", | ;38 "SynBass1", | ;39 "SynBass2", | ;40 "Violin ", | ;41 "Viola ", | ;42 "Cello ", | ;43 "Contra ", | ;44 "Trem Str", | ;45 "Pizicato", | ;46 "Orchestl", | ;47 "Timpani ", | ;48 "StrEnsm1", | ;49 "StrEnsm2", | ;50 "SynStr1 ", | ;51 "SynStr2 ", | ;52 "ChoirAhs", | ;53 "VoiceOhs", | ;54 "SynthVoc", | ;55 "OrchHits", | ;56 "Trumpet ", | ;57 "Trombone", | ;58 "Tuba ", | ;59 "MuteTrmp", | ;60 "FrnchHrn", | ;61 "BrassSec", | ;62 "SynBrss1", | ;63 "SynBrss2", | ;64 "SoprnSax", | ;65 "Alto Sax", | ;66 "TenorSax", | ;67 "Baritone", | ;68 "Oboe ", | ;69 "English ", | ;70 "Bassoon ", | ;71 "Clarinet", | ;72 "Piccolo ", | ;73 "Flute ", | ;74 "Recorder", | ;75 "PanFlute", | ;76 "BlownBtl", | ;77 "Shakuhac", | ;78 "Whistle ", | ;79 "Ocarina ", | ;80 "SquareWv", | ;81 "Sawtooth", | ;82 "Calliope", | ;83 "Chiff Ld", | ;84 "Charang ", | ;85 "Voice Ld", | ;86 "5thsLead", | ;87 "BassLead", | ;88 "New Age ", | ;89 "Warm Syn", | ;90 "Poly Syn", | ;91 "ChoirPad", | ;92 "BowedPad", | ;93 "Metallic", | ;94 "Halo Pad", | ;95 "SweepPad", | ;96 "Rain Fx ", | ;97 "Soundtrk", | ;98 "Crystal ", | ;99 "Atmosphr", | ;100 "Britness", | ;101 "Goblins ", | ;102 "EchoesFx", | ;103 "SciFi Fx", | ;104 "Sitar ", | ;105 "Banjo ", | ;106 "Shamisen", | ;107 "Koto ", | ;108 "Kalimba ", | ;109 "Bag Pipe", | ;110 "Fiddle ", | ;111 "Shanai ", | ;112 "TinklBel", | ;113 "Agogo ", | ;114 "SteelDrm", | ;115 "Woodblok", | ;116 "TaikoDrm", | ;117 "Melodic ", | ;118 "Syn Drum", | ;119 "RevCymbl", | ;120 "Gtr Fret", | ;121 "Breath ", | ;122 "Seashore", | ;123 "BrdTweet", | ;124 "Tel Ring", | ;125 "Helicptr", | ;126 "Applause", | ;127 "Gunshot " ;128 drm_tbl bytetable 35,38,39,41,42,44,45,46,48,49,51,62,63,65,67,68 ;drum to note conversion pt1_tbl bytetable 0,1, 1,1, 1,3, 3,1, 2,2, 2,6, 3,5, 4,4 ;counter 1&2 drum hi-lo patterns pt2_tbl bytetable 1,1, 1,3, 3,1, 1,7, 3,5, 5,3, 2,6, 6,2 ;counter 3&4 drum hi-lo patterns nam_tbl bytetable | ;drum patch names "Kick", | ;kick "Snar", | ;snare "Clap", | ;claps "Tom3", | ;tom3 "ClHt", | ;closed hat "MdHt", | ;mid hat "Tom2", | ;tom2 "OpHt", | ;open hat "Tom1", | ;tom1 "Crsh", | ;crash "Ride", | ;ride "Prc2", | ;perc2 "Tom4", | ;tom4 "Prc1", | ;perc1 "Prc3", | ;perc3 "Prc4", | ;perc4 ; ;-----------------------------------------------------------------------------------------------; ; NV Memory Map ; ;-----------------------------------------------------------------------------------------------; ; address variable ; ------- -------- nv_step_max con 0 ;adr000 step_max nv_midi_offset con 1 ;adr001 midi_offset nv_gate1_lo con 2 ;adr002 gate1.byte0 nv_gate1_hi con 3 ;adr003 gate1.byte1 nv_gate2_lo con 4 ;adr004 gate2.byte0 nv_gate2_hi con 5 ;adr005 gate2.byte1 nv_patch con 6 ;adr006 step 1 patch ;nv_patch(1) con 7 ;adr007 step 2 patch ;nv_patch(2) con 8 ;adr008 step 3 patch ;nv_patch(3) con 9 ;adr009 step 4 patch ;nv_patch(4) con 10 ;adr010 step 5 patch ;nv_patch(5) con 11 ;adr011 step 6 patch ;nv_patch(6) con 12 ;adr012 step 7 patch ;nv_patch(7) con 13 ;adr013 step 8 patch ;nv_patch(8) con 14 ;adr014 step 9 patch ;nv_patch(9) con 15 ;adr015 step 10 patch ;nv_patch(10) con 16 ;adr016 step 11 patch ;nv_patch(11) con 17 ;adr017 step 12 patch ;nv_patch(12) con 18 ;adr018 step 13 patch ;nv_patch(13) con 19 ;adr019 step 14 patch ;nv_patch(14) con 20 ;adr020 step 15 patch ;nv_patch(15) con 21 ;adr021 step 16 patch nv_seq_mode con 22 ;adr022 seq_mode ; ;-----------------------------------------------------------------------------------------------; ; Initialization ; ;-----------------------------------------------------------------------------------------------; ; ;initialize pins #ifndef psim dires=%0000000000000000 ;configure pin direction (1=output, 0=input) ;inputs: in-7, in-6, in-5, in-4 #endif dirs =%0001011000000000 ;configure pin direction (1=output, 0=input) ;note: setting midi-out, i2c_clock, i2c_data, and dac_load to outputs can glitch so initialize as inputs ;inputs: midi-in, aux, start, stop, in-4, in-3, in-2, in-1 ;initialize as inputs: midi-out, dac_clk, dac_load, ic2_data, ic2_clk ;outputs: dac_sdata, stop led, run led high dac_load ;set dac load high high dac_clk ;set dac clock high so chip select will not clock low run_led ;reset run led low stop_led ;reset stop led ;initialize control hardware #ifndef psim let olat=$ff ;set olat to default i2cout i2c_data,i2c_clk,($20<<1),[$0a,olat];set outputs to olat i2cout i2c_data,i2c_clk,($20<<1),[$00,$00] ;then set iodir to output #endif ;initialize outputs let out_j1=0 ;set out-1 low let out_j2=0 ;set out-2 low let out_j3=0 ;set out-3 low let out_j4=0 ;set out-4 low #ifdef cvs let out_j5=0 ;set out-5 low let out_j6=0 ;set out-6 low let out_j7=0 ;set out-7 low let out_j8=0 ;set out-8 low #endif gosub load_outputs ;initialize input variables let in_j1_ptr=0 ;reset in-1 pointer #ifdef input_int_en let in_j2_ptr=0 ;reset in-2 pointer let in_j3_ptr=0 ;reset in-3 pointer let in_j4_ptr=0 ;reset in-4 pointer let isr_cnt=0 ;reset isr pass counter #endif let in_j1_bfr(0)=0 ;reset in-1 buffer data let in_j1_bfr(1)=0 let in_j2_bfr(0)=0 ;reset in-2 buffer data let in_j2_bfr(1)=0 let in_j3_bfr(0)=0 ;reset in-3 buffer data let in_j3_bfr(1)=0 let in_j4_bfr(0)=0 ;reset in-4 buffer data let in_j4_bfr(1)=0 #ifdef cvs let in_j5_bfr(0)=0 ;reset in-5 buffer data let in_j5_bfr(1)=0 let in_j6_bfr(0)=0 ;reset in-6 buffer data let in_j6_bfr(1)=0 let in_j7_bfr(0)=0 ;reset in-7 buffer data let in_j7_bfr(1)=0 let in_j8_bfr(0)=0 ;reset in-8 buffer data let in_j8_bfr(1)=0 #endif let in_j1_low=0 ;initialize in-1 hysteresis value let in_j1_high=2*hys let in_j2_low=0 ;initialize in-2 hysteresis value let in_j2_high=2*hys let in_j3_low=0 ;initialize in-3 hysteresis value let in_j3_high=2*hys let in_j4_low=0 ;initialize in-4 hysteresis value let in_j4_high=2*hys #ifdef cvs let in_j5_low=0 ;initialize in-5 hysteresis value let in_j5_high=2*hys let in_j6_low=0 ;initialize in-6 hysteresis value let in_j6_high=2*hys let in_j7_low=0 ;initialize in-7 hysteresis value let in_j7_high=2*hys let in_j8_low=0 ;initialize in-8 hysteresis value let in_j8_high=2*hys #endif ;initialize midi variables let midi_chan=0 ;initialize midi channel let midi_note=0 ;initialize midi note let midi_vel=64 ;initialize default velocity let midi_cmd=$0f ;initialize last midi command to invalid let trans_note=0 ;initialize transpose note to none let trans_chan=0 ;initialize transpose channel to none #ifndef psim ;define external control variables let key_prev=255 ;set keypad to all keys up let ext_ctrl=0 ;default to external controls not present #endif #ifdef edge_int_en ;define edge interrupt variables let edge_state=0 ;reset current state let edge_flg=0 ;reset edge flag ;enable aux_in rising edge interrupts let aux_cnt=0 ;reset count let pmr1=pmr1|%00100000 ;set Port Mode Register to enable irq1 let iegr1=iegr1|%00000010 ;set irq1 to rising edge let irr1=irr1&%11111101 ;clear any pending interrupt oninterrupt irq1int,aux_isr enable irq1int ;enable rising edge interrupts #endif ;initialize timerW hardware for 1 mS #ifdef timer_int_en let tmrw=%10001000 ;set Timer Mode Register to enable count let tcrw=%10110000 ;set Timer Control Register ; clear on compare match A ; 16 MHz clock /8 prescalar S = 2 MHz timer clock let gra=gra_val ;divide 2 MHz for 1 mS interrupt let time_count=0 ;initialize real time count let turn_off=0 ;initialize turn off time oninterrupt timerwint_imiea, tm_isr enable timerwint_imiea ;enable timer interrupt #endif ;enable midi hardware sethserial1 h31200,h8databits,hnoparity,h1stopbits gosub send_all_off ;turn off any stuck notes ; ;-----------------------------------------------------------------------------------------------; ; Main Program ; ;-----------------------------------------------------------------------------------------------; ; ;written by David J. Brown hserout [$f0,$7d,$10,$04,$04,$04,$04,$15,$0e,$04,$f7] ;program start character start: let out_j1=0 ;set out-1 low let out_j2=0 ;set out-2 low let out_j3=0 ;set out-3 low let out_j4=0 ;set out-4 low let out_j5=0 ;set out-5 low let out_j6=0 ;set out-6 low let out_j7=0 ;set out-7 low let out_j8=0 ;set out-8 low gosub load_outputs hserout [$f0,$7d,$0a,$18,"HR-16 DividerSeqStopped.. ",$00,"Start",$f7] start1: if start_j=0 then start1 ;check for start high ;initialize counter values let out2_cnt_hi=0 ;initialize counter for enable let out2_cnt_lo=1 let out4_cnt_hi=1 ;initialize counter for mute let out4_cnt_lo=0 let out6_cnt_hi=0 ;initialize counter for enable let out6_cnt_lo=1 let out8_cnt_hi=1 ;initialize counter for mute let out8_cnt_lo=0 goto clk_l ;wait for next clock high transition ; clk_h: if aux_in=0 then clk_h ;wait for clock high transition high run_led high stop_led gosub get_inputs ;get input voltages ;set counters 1 and 2 patterns let in_j2=in_j2/128 ;keep to 8 values let out2_hi=pt1_tbl(in_j2*2) ;set hi count length let out2_lo=pt1_tbl((in_j2*2)+1) ;set lo count length let in_j4=in_j4/128 ;keep to 8 values let out4_hi=pt1_tbl(in_j4*2) ;set hi count length let out4_lo=pt1_tbl((in_j4*2)+1) ;set lo count length ;set counters 3 and 4 patterns let in_j6=in_j6/128 ;keep to 8 values let out6_hi=pt2_tbl(in_j6*2) ;set hi count length let out6_lo=pt2_tbl((in_j6*2)+1) ;set lo count length let in_j8=in_j8/128 ;keep to 8 values let out8_hi=pt2_tbl(in_j8*2) ;sethi count length let out8_lo=pt2_tbl((in_j8*2)+1) ;set lo count length ;display patterns hserout [$f0,$7d,$0d,dec out2_hi,"/",dec out2_lo," ",dec out4_hi,"/",dec out4_lo," ", | dec out6_hi,"/",dec out6_lo," ",dec out8_hi,"/",dec out8_lo," ", $f7] ;counter 1 if out2_cnt_hi=0 then ;determine if counting hi or low let out2_cnt_lo=out2_cnt_lo-1 ;counting low time if out2_cnt_lo=0 then ;done? let out2_cnt_hi=out2_hi ;reset hi counter let out_j2=fivevolts*2 ;set bit high if out2_cnt_hi=0 then ;check for continuous on let out2_cnt_lo=1 ;set lo count endif endif else let out2_cnt_hi=out2_cnt_hi-1 ;counting hi time if out2_cnt_hi=0 then ;done? let out2_cnt_lo=out2_lo ;reset low counter let out_j2=0 ;set bit low endif endif ;counter 2 if out4_cnt_hi=0 then ;determine if counting hi or low out4_cnt_lo=out4_cnt_lo-1 ;counting low time if out4_cnt_lo=0 then ;done? let out4_cnt_hi=out4_hi ;reset hi counter let out_j4=fivevolts*2 ;set bit high if out4_cnt_hi=0 then ;check for continuous on let out4_cnt_lo=1 ;set lo count endif endif else out4_cnt_hi=out4_cnt_hi-1 ;counting hi time if out4_cnt_hi=0 then ;done? let out4_cnt_lo=out4_lo ;reset low counter let out_j4=0 ;set bit low endif endif ;counter 3 if out6_cnt_hi=0 then ;determine if counting hi or low out6_cnt_lo=out6_cnt_lo-1 ;counting low time if out6_cnt_lo=0 then ;done? let out6_cnt_hi=out6_hi ;reset hi counter let out_j6=fivevolts*2 ;set bit high endif else out6_cnt_hi=out6_cnt_hi-1 ;counting hi time if out6_cnt_hi=0 then ;done? let out6_cnt_lo=out6_lo ;reset low counter let out_j6=0 ;set bit low endif endif ;counter 4 if out8_cnt_hi=0 then ;determine if counting hi or low out8_cnt_lo=out8_cnt_lo-1 ;counting low time if out8_cnt_lo=0 then ;done? let out8_cnt_hi=out8_hi ;reset hi counter let out_j8=fivevolts*2 ;set bit high endif else out8_cnt_hi=out8_cnt_hi-1 ;counting hi time if out8_cnt_hi=0 then ;done? let out8_cnt_lo=out8_lo ;reset low counter let out_j8=0 ;set bit low endif endif ;calculate drum notes and names ;channel 1 let out_j1=in_j1*15/4 ;pass in to out let in_j1=in_j1/64 ;keep to 16 values if out_j2=0 then let in_j1=0 ;mute channel hserout [$f0,$7d,$0b," -- ",$f7] ;display mute else hserout [$f0,$7d,$0b] ;display drum name for tempb=0 to 3 ;get characters of patch name hserout [nam_tbl((in_j1*4)+tempb)] next hserout [$f7] let midi_note=drm_tbl(in_j1) hserout [keydn|00,midi_note,64] endif ;channel 2 let out_j3=in_j3*15/4 ;pass in to out let in_j3=in_j3/64 ;keep to 16 values if out_j4=0 then let in_j3=0 ;mute channel hserout [$f0,$7d," -- ",$f7] ;display mute else hserout [$f0,$7d] ;display drum name for tempb=0 to 3 ;get characters of patch name hserout [nam_tbl((in_j3*4)+tempb)] next hserout [$f7] let midi_note=drm_tbl(in_j3) hserout [keydn|00,midi_note,64] endif ;channel 3 let out_j5=in_j5*15/4 ;pass in to out let in_j5=in_j5/64 ;keep to 16 values if out_j6=0 then let in_j5=0 ;mute channel hserout [$f0,$7d," -- ",$f7] ;display mute else hserout [$f0,$7d] ;display drum name for tempb=0 to 3 ;get characters of patch name hserout [nam_tbl((in_j5*4)+tempb)] next hserout [$f7] let midi_note=drm_tbl(in_j5) hserout [keydn|00,midi_note,64] endif ;channel 4 let out_j7=in_j7*15/4 ;pass in to out let in_j7=in_j7/64 ;keep to 16 values if out_j8=0 then let in_j7=0 ;mute channel hserout [$f0,$7d," -- ",$f7] ;display mute else hserout [$f0,$7d] ;display drum name for tempb=0 to 3 ;get characters of patch name hserout [nam_tbl((in_j7*4)+tempb)] next hserout [$f7] let midi_note=drm_tbl(in_j7) hserout [keydn|00,midi_note,64] endif low stop_led gosub load_outputs clk_l: if stop_j=1 then start ;check for stop switch if aux_in=1 then clk_l ;wait for clock low transition low run_led goto clk_h ; ;-----------------------------------------------------------------------------------------------; ; MIDI Protocol Subroutines ; ;-----------------------------------------------------------------------------------------------; ; ;process midi in commands ;transposes note to midi note+trans_note ;transposes channel to midi channel+trans_chan ;written by David J. Brown proc_midi: hserin proc_none,0,[midi_data] if midi_data=$fe then proc_midi ;ignore active status high stop_led #ifdef timer_int_en disable timerwint_imiea let turn_off=time_count+20 ;set led time enable timerwint_imiea #endif if midi_data>$f7 then real_time ;check for real time if midi_data.bit7=0 then running ;check to see if running status let last_cmd=midi_data ;save command to expand running let midi_cmd=(midi_data>>4)&$07 ;strip midi channel for branch branch midi_cmd,[mkey_up,mkey_dn,key_prs,ctrl_chg,prgm_chg,chan_prs,ptch_bnd,sys_com] ; proc_none: return ; ;running status running: let tempb=(last_cmd&$f0)|((last_cmd+trans_chan)&$0f) ;expand to non-running and transpose midi channel hserout [tempb] branch midi_cmd,[mkey_upr,mkey_dnr,key_prsr,ctrl_chgr,prgm_chgr,chan_prsr,ptch_bndr,proc_none] ; ;note off command mkey_up: let midi_data=keyup|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer mkey_upr: let midi_data=midi_data+trans_note ;transpose midi note hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;note on command mkey_dn: let midi_data=keydn|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer mkey_dnr: let midi_data=midi_data+trans_note ;transpose midi note hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;key pressure command key_prs: let midi_data=chnprs|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer key_prsr: hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;control change command ctrl_chg: let midi_data=conctrl|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer ctrl_chgr: hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;program change command prgm_chg: let midi_data=pgmchg|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer prgm_chgr: hserout [midi_data] return ; ;channel pressure command chan_prs: let midi_data=chnprs|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer chan_prsr: hserout [midi_data] return ; ;pitch bend command ptch_bnd: let midi_data=pitchb|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer ptch_bndr: hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;system common command sys_com: let sys_cmd=midi_data&$07 ;get system common command branch sys_cmd,[sys_ex,proc_none,song_ptr,song_sel,proc_none,proc_none,tune_req,proc_none] ; ;system exclusive sys_ex: hserout [midi_data] sys_ex2: gosub get_next_byte ;get data from received buffer hserout [midi_data] ;send it if midi_data<$80 then sys_ex2 ;check for end of string return ; ;song pointer command song_ptr: hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;song select command song_sel: hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;tune_request command tune_req: hserout [midi_data] return ; ;real time commands real_time: let sys_cmd=midi_data&$07 ;strip high bits for branch branch sys_cmd,[time_clk,proc_none,start_cmd,cont_cmd,stop_cmd,proc_none,proc_none,reset_cmd] return ; ;timing clock command time_clk: hserout [midi_data] return ; ;start command start_cmd: hserout [midi_data] return ; ;continue command cont_cmd: hserout [midi_data] return ; ;stop command stop_cmd: hserout [midi_data] return ; ;reset command reset_cmd: hserout [midi_data] return ; ;wait for data and check for real time data get_next_byte: hserin get_next_byte,0,[midi_data] if midi_data=$fe then get_next_byte ;ignore active status if midi_data>$f7 then ;check for real time gosub real_time goto get_next_byte endif return ; ;-----------------------------------------------------------------------------------------------; ; MIDI Subroutines ; ;-----------------------------------------------------------------------------------------------; ; ;send midi note-on command ;midi_chan is channel ;midi_note is note ;midi_vel is velocity send_note_on: hserout [keydn|midi_chan,midi_note,midi_vel] return ; ;send midi note-off command ;midi_chan is channel ;midi_note is note send_note_off: hserout [keyup|midi_chan,midi_note,0] return ; ;send midi all notes off command on all channels send_all_off: for tempb=0 to 15 ;send on all channels hserout [conctrl|tempb,allup,0] ;send all notes off next return ; ;send midi program change command ;midi_chan is channel ;midi_pgm is program change send_prog_change: hserout [pgmchg|midi_chan,midi_pgm] return ; ;send midi continuous controller command ;midi_cc is controller number ;midi_data is controller data send_cc: hserout [conctrl|midi_chan,midi_cc,midi_data] return ; ;get midi_data from buffer ;rcx_data_flg=1 if successful, rcx_data_flg=0 if no data in buffer get_rcx_bfr: let rcx_data_flg=0 ;set empty flag get_rcx_bfr1: hserin get_rcx_bfr2,0,[midi_data] if midi_data=$fe then get_rcx_bfr1 ;ignore active status let rcx_data_flg=1 ;set data returned flag get_rcx_bfr2: return ; ;send midi_data send_midi: hserout [midi_data] ;put data in transmit buffer return ; ;-----------------------------------------------------------------------------------------------; ; SpeakJet Subroutines ; ;-----------------------------------------------------------------------------------------------; ; #ifdef spj ;send spkj_data via i2c ;retransmit on error for flow control send_speakjet: i2cout i2c_data,i2c_clk,send_speakjet,($48<<1),[spkj_data] ;send to TTS256 return ; ;send data_hex to speakjet ;pause 100 mS before first nibble and 60 mS before second nibble ;written by David J. Brown hex_speakjet: let phrase1=data_hex>>4 ;get high nibble let phrase1=phrase(phrase1) ;get first byte let phrase2=data_hex&$0f ;get bottom nibble let phrase2=phrase(phrase2) ;get first byte hex_error: i2cout i2c_data,i2c_clk,hex_error,($48<<1),[$01,phrase1,$05,phrase2,$0d] ;send to TTS256 return #endif ; ;-----------------------------------------------------------------------------------------------; ; Display Subroutines ; ;-----------------------------------------------------------------------------------------------; ; ;program input voltage characters prog_in_chars: hserout [$f0,$7d,$10,$01,$1f,$09,$00,$11,$1f,$11,$f7] ;character0 "I1" hserout [$f0,$7d,$11,$0d,$15,$17,$00,$11,$1f,$11,$f7] ;character1 "I2" hserout [$f0,$7d,$12,$0e,$15,$15,$00,$11,$1f,$11,$f7] ;character2 "I3" hserout [$f0,$7d,$13,$1f,$04,$1c,$00,$11,$1f,$11,$f7] ;character3 "I4" #ifdef cvs hserout [$f0,$7d,$14,$12,$15,$1d,$00,$11,$1f,$11,$f7] ;character4 "I5" hserout [$f0,$7d,$15,$02,$15,$0e,$00,$11,$1f,$11,$f7] ;character5 "I6" hserout [$f0,$7d,$16,$18,$17,$10,$00,$11,$1f,$11,$f7] ;character6 "I7" hserout [$f0,$7d,$17,$0a,$15,$0a,$00,$11,$1f,$11,$f7] ;character7 "I8" #endif return ; ;program output voltage characters prog_out_chars: hserout [$f0,$7d,$10,$01,$1f,$09,$00,$0e,$11,$0e,$f7] ;character0 "O1" hserout [$f0,$7d,$11,$0d,$15,$17,$00,$0e,$11,$0e,$f7] ;character1 "O2" hserout [$f0,$7d,$12,$0e,$15,$15,$00,$0e,$11,$0e,$f7] ;character2 "O3" hserout [$f0,$7d,$13,$1f,$04,$1c,$00,$0e,$11,$0e,$f7] ;character3 "O4" #ifdef cvs hserout [$f0,$7d,$14,$12,$15,$1d,$00,$0e,$11,$0e,$f7] ;character4 "I5" hserout [$f0,$7d,$15,$02,$15,$0e,$00,$0e,$11,$0e,$f7] ;character5 "I6" hserout [$f0,$7d,$16,$18,$17,$10,$00,$0e,$11,$0e,$f7] ;character6 "I7" hserout [$f0,$7d,$17,$0a,$15,$0a,$00,$0e,$11,$0e,$f7] ;character7 "I8" #endif return ; ;convert word num_data to five ascii digits ;updates tths, thos, huns, tens, ones variables ;use to generate leading zeros for fixed column display ;written by David J. Brown hex2ascii: let tempw=num_data ;use temp to save data let tths=(tempw/10000)+$30 ;get ten thousands and convert to ascii let tempw=tempw//10000 ;get thousands remainder let thos=(tempw/1000)+$30 ;get thousands and convert to ascii let tempw=tempw//1000 ;get hundreds remainder let huns=(tempw/100)+$30 ;get hundreds and convert to ascii let tempw=tempw//100 ;get tens remainder let tens=(tempw/10)+$30 ;get tens and convert to ascii let ones=(tempw//10)+$30 ;get ones remainder and convert to ascii return ; ;display input voltages in_jx ;range must be 0 - 1023 ;10 displays as "X" (e.g. X.0 volts) ;written by David J. Brown display_in: let tempw.highbyte=tens ;save tens let tempw.lowbyte=ones ;save ones ;(*33)/337 is divide by 10.23 to convert 1023 to 100 (10.0 volts) let tempb=(in_j1*33)/337 ;scale 0 to 100 if tempb=100 then ;check for 10.0 let ones=$58 ;set ones digit to X let tens=$30 ;set tenths digit to 0 else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$f0,$7d,$0d,$00,ones,".",tens] ;home1 and display in_j1 voltage let tempb=(in_j2*33)/337 ;scale 0 to 100 if tempb=100 then ;check for 10.0 let ones=$58 ;set ones digit to X let tens=$30 ;set tenths digit to 0 else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$01,ones,".",tens] ;display in_j2 voltage let tempb=(in_j3*33)/337 ;scale 0 to 100 if tempb=100 then ;check for 10.0 let ones=$58 ;set ones digit to X let tens=$30 ;set tenths digit to 0 else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$02,ones,".",tens] ;display in_j3 voltage let tempb=(in_j4*33)/337 ;scale 0 to 100 if tempb=100 then ;check for 10.0 let ones=$58 ;set ones digit to X let tens=$30 ;set tenths digit to 0 else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$03,ones,".",tens,$f7] ;display in_j4 voltage and terminate sysex #ifdef cvs let tempb=(in_j5*33)/337 ;scale 0 to 100 if tempb=100 then ;check for 10.0 let ones=$58 ;set ones digit to X let tens=$30 ;set tenths digit to 0 else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$f0,$7d,$0b,$04,ones,".",tens] ;home2 and display in_j5 voltage let tempb=(in_j6*33)/337 ;scale 0 to 100 if tempb=100 then ;check for 10.0 let ones=$58 ;set ones digit to X let tens=$30 ;set tenths digit to 0 else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$05,ones,".",tens] ;display in_j6 voltage let tempb=(in_j7*33)/337 ;scale 0 to 100 if tempb=100 then ;check for 10.0 let ones=$58 ;set ones digit to X let tens=$30 ;set tenths digit to 0 else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$06,ones,".",tens] ;display in_j7 voltage let tempb=(in_j8*33)/337 ;scale 0 to 100 if tempb=100 then ;check for 10.0 let ones=$58 ;set ones digit to X let tens=$30 ;set tenths digit to 0 else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$07,ones,".",tens,$f7] ;display in_j8 voltage and terminate sysex #endif let tens=tempw.highbyte ;restore tens let ones=tempw.lowbyte ;restore ones return ; ;display output voltages out_jx ;range must be 0 - 4095 ;10 displays as "X" (e.g. X.3 volts) ;written by David J. Brown display_out: let tempw.highbyte=tens ;save tens let tempw.lowbyte=ones ;save ones ;(/4)*25)/240 is divide by 38.4 to convert 4095 to 106 (10.6 volts) let tempb=((out_j1/4)*25)/240 ;scale 0 to 100 if tempb>99 then ;check for 10.0 to 10.6 let ones=$58 ;set ones digit to X let tens=(tempb-100)+$30 ;set tenths digit to remainder else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$f0,$7d,$0d,$00,ones,".",tens] ;home1 and display out_j1 voltage let tempb=((out_j2/4)*25)/240 ;scale 0 to 100 if tempb>99 then ;check for 10.0 to 10.6 let ones=$58 ;set ones digit to X let tens=(tempb-100)+$30 ;set tenths digit to remainder else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$01,ones,".",tens] ;display out_j2 voltage let tempb=((out_j3/4)*25)/240 ;scale 0 to 100 if tempb>99 then ;check for 10.0 to 10.6 let ones=$58 ;set ones digit to X let tens=(tempb-100)+$30 ;set tenths digit to remainder else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$02,ones,".",tens] ;display out_j2 voltage let tempb=((out_j4/4)*25)/240 ;scale 0 to 100 if tempb>99 then ;check for 10.0 to 10.6 let ones=$58 ;set ones digit to X let tens=(tempb-100)+$30 ;set tenths digit to remainder else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$03,ones,".",tens,$f7] ;display out_j4 voltage and terminate sysex #ifdef cvs let tempb=((out_j5/4)*25)/240 ;scale 0 to 100 if tempb>99 then ;check for 10.0 to 10.6 let ones=$58 ;set ones digit to X let tens=(tempb-100)+$30 ;set tenths digit to remainder else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$f0,$7d,$0b,$04,ones,".",tens] ;home2 and display out_j5 voltage let tempb=((out_j6/4)*25)/240 ;scale 0 to 100 if tempb>99 then ;check for 10.0 to 10.6 let ones=$58 ;set ones digit to X let tens=(tempb-100)+$30 ;set tenths digit to remainder else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$05,ones,".",tens] ;display out_j6 voltage let tempb=((out_j7/4)*25)/240 ;scale 0 to 100 if tempb>99 then ;check for 10.0 to 10.6 let ones=$58 ;set ones digit to X let tens=(tempb-100)+$30 ;set tenths digit to remainder else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$06,ones,".",tens] ;display out_j7 voltage let tempb=((out_j8/4)*25)/240 ;scale 0 to 100 if tempb>99 then ;check for 10.0 to 10.6 let ones=$58 ;set ones digit to X let tens=(tempb-100)+$30 ;set tenths digit to remainder else let tempb=bin2bcd tempb ;convert to two digits let ones=(tempb.nib1)+$30 ;get ones digit and convert to ascii let tens=(tempb.nib0)+$30 ;get tenths digit and convert to ascii endif hserout [$07,ones,".",tens,$f7] ;display out_j8 voltage and terminate sysex #endif let tens=tempw.highbyte ;restore tens let ones=tempw.lowbyte ;restore ones return ; ;-----------------------------------------------------------------------------------------------; ; Input and Output Subroutines ; ;-----------------------------------------------------------------------------------------------; ; ;sample in-1 to in-4 ;in_jx is input value (0 - 1023) ;150 uS execution time for PSIM ;300 uS execution time for CVS get_inputs: adin pin_j1,in_j1 adin pin_j2,in_j2 adin pin_j3,in_j3 adin pin_j4,in_j4 #ifdef cvs adin pin_j5,in_j5 adin pin_j6,in_j6 adin pin_j7,in_j7 adin pin_j8,in_j8 #endif return ; ;sample and average in-1 to in-x ;in_jx is input value averaged over last four samples (0 - 1023) ;in_jx_bfr(0) & in_jx_bfr(1) are last four word samples ;600 uS execution time for PSIM/CVS4 ;1.2 mS execution time for CVS ;written by David J. Brown get_inputs_avg: adin pin_j1,in_j1_bfr.word1(in_j1_ptr) ;get in-1 into buffer let in_j1_tmp=in_j1_bfr(0)+in_j1_bfr(1) ;add two high words together and low words together let in_j1=(in_j1_tmp.word1+in_j1_tmp.word0)/4 adin pin_j2,in_j2_bfr.word1(in_j1_ptr) ;get in-2 into buffer let in_j2_tmp=in_j2_bfr(0)+in_j2_bfr(1) ;add two high words together and low words together let in_j2=(in_j2_tmp.word1+in_j2_tmp.word0)/4 adin pin_j3,in_j3_bfr.word1(in_j1_ptr) ;get in-3 into buffer let in_j3_tmp=in_j3_bfr(0)+in_j3_bfr(1) ;add two high words together and low words together let in_j3=(in_j3_tmp.word1+in_j3_tmp.word0)/4 adin pin_j4,in_j4_bfr.word1(in_j1_ptr) ;get in-4 into buffer let in_j4_tmp=in_j4_bfr(0)+in_j4_bfr(1) ;add two high words together and low words together let in_j4=(in_j4_tmp.word1+in_j4_tmp.word0)/4 #ifdef cvs adin pin_j5,in_j5_bfr.word1(in_j1_ptr) ;get in-5 into buffer let in_j5_tmp=in_j5_bfr(0)+in_j5_bfr(1) ;add two high words together and low words together let in_j5=(in_j5_tmp.word1+in_j5_tmp.word0)/4 adin pin_j6,in_j6_bfr.word1(in_j1_ptr) ;get in-6 into buffer let in_j6_tmp=in_j6_bfr(0)+in_j6_bfr(1) ;add two high words together and low words together let in_j6=(in_j6_tmp.word1+in_j6_tmp.word0)/4 adin pin_j7,in_j7_bfr.word1(in_j1_ptr) ;get in-7 into buffer let in_j7_tmp=in_j7_bfr(0)+in_j7_bfr(1) ;add two high words together and low words together let in_j7=(in_j7_tmp.word1+in_j7_tmp.word0)/4 adin pin_j8,in_j8_bfr.word1(in_j1_ptr) ;get in-8 into buffer let in_j8_tmp=in_j8_bfr(0)+in_j8_bfr(1) ;add two high words together and low words together let in_j8=(in_j8_tmp.word1+in_j8_tmp.word0)/4 #endif let in_j1_ptr=(in_j1_ptr+1)&$03 ;increment pointer and wrap at 3 return ; ;sample in-1 to in-x with hysteresis ;in_jx is input value (0 - 1023) ;0.5 mS execution time for PSIM/CVS4 ;1 mS execution time for CVS ;written by David J. Brown get_inputs_hy: adin pin_j1,in_j1 let in_j1=in_j1+hys ;offset for compare at zero if in_j1>in_j1_low then ;check lower range if in_j1in_j2_low then ;check lower range if in_j2in_j3_low then ;check lower range if in_j3in_j4_low then ;check lower range if in_j4in_j5_low then ;check lower range if in_j5in_j6_low then ;check lower range if in_j6in_j7_low then ;check lower range if in_j7in_j8_low then ;check lower range if in_j8242 then let key_data=255 ;no keys down elseif key_temp>221 let key_data=10 ;* key elseif key_temp>201 let key_data=7 ;7 key elseif key_temp>180 let key_data=4 ;4 key elseif key_temp>158 let key_data=1 ;1 key elseif key_temp>137 let key_data=0 ;0 key elseif key_temp>116 let key_data=8 ;8 key elseif key_temp>95 let key_data=5 ;5 key elseif key_temp>74 let key_data=2 ;2 key elseif key_temp>54 let key_data=11 ;# key elseif key_temp>33 let key_data=9 ;9 key elseif key_temp>10 let key_data=6 ;6 key else let key_data=3 ;3 key endif if key_data=key_prev then ;check if state change return ;two scans same so have key value endif let key_prev=key_data ;save state pause 20 ;let keys settle goto get_keynum ;scan again ; ;get keypad entry 0 - 999 ;displays digits at current character position ;* or # terminates ;written by David J. Brown get_keyentry gosub get_keynum if key_data<>255 then get_keyentry ;wait for keys up get_key1: gosub get_keynum if key_data=255 then get_keyentry ;loop until key entry if key_data>9 then get_keyentry ;must be 0 - 9 let key_entry=key_data ;save digit hserout [$f0,$7d,key_data+$30,$f7] ;display digit get_key2: gosub get_keynum if key_data<>255 then get_key2 ;wait for key up get_key3: gosub get_keynum if key_data=255 then get_key3 ;loop until key entry if key_data>9 then get_keydone ;done with entry hserout [$f0,$7d,key_data+$30,$f7] ;display digit let key_entry=(key_entry*10)+key_data ;shift and save digit get_key4: gosub get_keynum if key_data<>255 then get_key4 ;wait for key up get_key5: gosub get_keynum if key_data=255 then get_key5 ;loop until key entry if key_data>9 then get_keydone ;done with entry hserout [$f0,$7d,key_data+$30,$f7] ;display digit let key_entry=(key_entry*10)+key_data ;shift and save digit get_key6: gosub get_keynum if key_data<>255 then get_key6 ;wait for keys up get_keydone: return #endif ; #ifndef psim ;set input normal voltage to 10 volts nmlv_10: let olat.bit0=1 ;set for input normal voltage to +10 i2cout i2c_data,i2c_clk,($20<<1),[$0a,olat] ;set olat return ; ;set input normal voltage to 0 nmlv_0: let olat.bit0=0 ;reset for input normal voltage to 0 i2cout i2c_data,i2c_clk,($20<<1),[$0a,olat] ;set olat return ; ;set input reference voltage to 10 volts refv_10: let olat.bit1=1 ;set to enable input reference voltage let olat.bit2=0 ;reset for input reference voltage to +10 i2cout i2c_data,i2c_clk,($20<<1),[$0a,olat] ;set olat return ; ;set input reference voltage to 5 volts refv_5: let olat.bit1=1 ;set to enable input reference voltage let olat.bit2=1 ;set for input reference voltage to +5 i2cout i2c_data,i2c_clk,($20<<1),[$0a,olat] ;set olat return ; ;set input reference voltage to 0 refv_0: let olat.bit1=0 ;reset for input reference voltage to 0 i2cout i2c_data,i2c_clk,($20<<1),[$0a,olat] ;set olat return #endif ; ;-----------------------------------------------------------------------------------------------; ; Interrupt Service Routines ; ;-----------------------------------------------------------------------------------------------; ; #ifdef aux_int_en ;interrupt service routine for aux input rising edge aux_isr: let aux_cnt=aux_cnt+1 ;count number of aux interrupts resume ;ignore overflow #endif ; #ifdef timer_int_en ;interrupt service routine for timer ;increments time_count value ;turn off stop led at turn_off value ;toggle run led at 512 mS intervals ;written by David J. Brown tm_isr: toggle aux_j let time_count=time_count+1 ;increment real time count if time_count=turn_off then ;value to turn off stop led low stop_led endif let run_led_out=time_count.bit9 ;toggle run led at 512 mS intervals #endif #ifdef edge_int_en ;check for trigger rising edge ;pulse width must be > 1 ms timer let edge_state=edge_state<<1 ;shift previous state left let edge_state.bit0=edge_in ;set low bit to current input state if edge_state=$01 then ;edge detect requires 7 previous lows and current high let edge_flg=1 ;set edge flag endif #endif #ifndef input_int_en resume ;resume if input polled mode #else ;sample in-1 - in-4 at specific intervals ;injx is input averaged over last 4 samples (0 - 1023) ;injx_bfr(0) & injx_bfr(1) are last 4 word samples ;written by David J. Brown let isr_cnt=isr_cnt+1 #endif #ifdef cvs ;change the following table to modify the scan rate for each CVS input ;175 uS execution time so maximum of one sample and average per interrupt ;currently set for: in-1 to 8 @ 8 mS branch isr_cnt, [avg1,avg2,avg3,avg4,avg5,avg6,avg7,avg8,avg1,avg2,avg3,avg4,avg5,avg6,avg7,avg8] #else ;change the following table to modify the scan rate for each PSIM input ;175 uS execution time so maximum of one sample and average per interrupt ;currently set for: in-1 @ 2 mS, in-2 @ 4 mS, in-3 @ 8 mS, in-4 @ 8 mS branch isr_cnt, [avg1,avg2,avg1,avg3,avg1,avg2,avg1,avg4,avg1,avg2,avg1,avg3,avg1,avg2,avg1,avg4] #endif ;sample in-1 avg1: #ifdef input_int_en adin pin_j1,in_j1_bfr.word1(in_j1_ptr) ;get in-1 into buffer let in_j1_tmp=in_j1_bfr(0)+in_j1_bfr(1) ;add two high words together and low words together let in_j1=(in_j1_tmp.word1+in_j1_tmp.word0)/4 let in_j1_ptr=(in_j1_ptr+1)&$03 ;increment pointer and wrap at 3 resume #endif ;sample in-2 avg2: #ifdef input_int_en adin pin_j2,in_j2_bfr.word1(in_j2_ptr) ;get in-2 into buffer let in_j2_tmp=in_j2_bfr(0)+in_j2_bfr(1) ;add two high words together and low words together let in_j2=(in_j2_tmp.word1+in_j2_tmp.word0)/4 let in_j2_ptr=(in_j2_ptr+1)&$03 ;increment pointer and wrap at 3 resume #endif ;sample in-3 avg3: #ifdef input_int_en adin pin_j3,in_j3_bfr.word1(in_j3_ptr) ;get in-3 into buffer let in_j3_tmp=in_j3_bfr(0)+in_j3_bfr(1) ;add two high words together and low words together let in_j3=(in_j3_tmp.word1+in_j3_tmp.word0)/4 let in_j3_ptr=(in_j3_ptr+1)&$03 ;increment pointer and wrap at 3 resume #endif ;sample in-4 avg4: #ifdef input_int_en adin pin_j4,in_j4_bfr.word1(in_j4_ptr) ;get in-4 into buffer let in_j4_tmp=in_j4_bfr(0)+in_j4_bfr(1) ;add two high words together and low words together let in_j4=(in_j4_tmp.word1+in_j4_tmp.word0)/4 let in_j4_ptr=(in_j4_ptr+1)&$03 ;increment pointer and wrap at 3 resume #endif ;sample in-5 avg5: #ifdef input_int_en adin pin_j5,in_j5_bfr.word1(in_j5_ptr) ;get in-5 into buffer let in_j5_tmp=in_j5_bfr(0)+in_j5_bfr(1) ;add two high words together and low words together let in_j5=(in_j5_tmp.word1+in_j5_tmp.word0)/4 let in_j5_ptr=(in_j5_ptr+1)&$03 ;increment pointer and wrap at 3 resume #endif ;sample in-6 avg6: #ifdef input_int_en adin pin_j6,in_j2_bfr.word1(in_j6_ptr) ;get in-6 into buffer let in_j6_tmp=in_j6_bfr(0)+in_j6_bfr(1) ;add two high words together and low words together let in_j6=(in_j2_tmp.word1+in_j6_tmp.word0)/4 let in_j6_ptr=(in_j6_ptr+1)&$03 ;increment pointer and wrap at 3 resume #endif ;sample in-7 avg7: #ifdef input_int_en adin pin_j7,in_j7_bfr.word1(in_j7_ptr) ;get in-7 into buffer let in_j7_tmp=in_j7_bfr(0)+in_j7_bfr(1) ;add two high words together and low words together let in_j7=(in_j7_tmp.word1+in_j7_tmp.word0)/4 let in_j7_ptr=(in_j7_ptr+1)&$03 ;increment pointer and wrap at 3 resume #endif ;sample in-8 avg8: #ifdef input_int_en adin pin_j8,in_j8_bfr.word1(in_j8_ptr) ;get in-8 into buffer let in_j8_tmp=in_j8_bfr(0)+in_j8_bfr(1) ;add two high words together and low words together let in_j8=(in_j8_tmp.word1+in_j8_tmp.word0)/4 let in_j8_ptr=(in_j8_ptr+1)&$03 ;increment pointer and wrap at 3 resume #endif ; ;-----------------------------------------------------------------------------------------------; ; End Of Program ; ;-----------------------------------------------------------------------------------------------;