;-----------------------------------------------------------------------------------------------; ; Program: CVS Sequential Blink ; ; 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 blinks all the leds in sequence ; ; Inputs: ; Start = ; Stop = ; In-1 = ; In-2 = ; In-3 = ; In-4 = ; In-5 = ; In-6 = ; In-7 = ; In-8 = ; Aux = ; Midi-In = ; ; Outputs: ; Out-1 = blink ; Out-2 = blink ; Out-3 = blink ; Out-4 = blink ; Out-5 = blink ; Out-6 = blink ; Out-7 = blink ; Out-8 = blink ; Aux = ; Midi-Out= Active status to blink LED ; Speakjet= ; ; Display = displays LED that is on ; Run led = blink ; Stop led= blink ; ; Revision: 0.2S2 ; Date Sept 23, 2010 ; History: 0.2S2 changed serial for Studio 2 ; 0.2S changed i2cout and shiftout for Studio ; 0.2 added pin modifications for IDE8.0.1.7 ; 0.1 initial release of program ; Written: October 7, 2007 ; ;---------PSIM OR CVS CONDITIONAL COMPILE OPTION------------------------------------------------; ; ; ; COMMENT OUT NEXT LINE FOR PSIM CONFIGURATION ; ;cvs con 1 ;define for CVS configuration ; ;-----------------------------------------------------------------------------------------------; ; ;-----------------------------------------------------------------------------------------------; ; BasicMicro AtomPro2X PSIM / CVS ; ;-----------------------------------------------------------------------------------------------; ; P0 - digital in/out, analog in-1 ; ; P1 - digital in/out, analog in-2 ; ; P2 - digital in/out, analog in-3 ; ; P3 - digital in/out, analog in-4 ; ; P4 - start button (no input/default=0/low, pressed=1/hi) ; ; P5 - stop button (no input/default=0/low, pressed=1/hi) ; ; P6 - i2c data ; ; P7 - i2c clock ; ; P8 - aux in/out (no input/default=0/low) ; ; P9 - stop led (low=off, hi=on) ; ; P10 - run led (low=off hi=on) ; ; P11 - dac dac_load ; ; P12 - dac dac_sdata ; ; P13 - dac dac_clk ; ; P14 - midi-in ; ; P15 - midi-out ; ;-----------------------------------------------------------------------------------------------; ; BasicMicro AtomPro28 CVS pins ; ;-----------------------------------------------------------------------------------------------; ; P16 - digital in/out, analog in-7 ; ; P17 - digital in/out, analog in-6 ; ; P18 - digital in/out, analog in-5 ; ; P19 - digital in/out, analog in-4 ; ;-----------------------------------------------------------------------------------------------; ; DJB-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 - reserved ; ; $1d - reserved ; ; $1e - reserved ; ; $1f - writes new default message character 1, character 2 ... character 32 ; ;-----------------------------------------------------------------------------------------------; ; ;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 pin (used with high/low/toggle) aux_in var in8 ;aux jack (used for input) stop_led con p9 ;stop led (used with high/low/toggle) stop_led_out var out9 ;stop led alias (used with let) run_led con p10 ;run led (used with high/low/toggle) run_led_out var out10 ;run led alias (used with let) dac_load con p11 ;load dac pin dac_sdata con p12 ;dac serial data input pin dac_clk con p13 ;dac clock pin midi_sdata con p15 ;midi data serial output ;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 olat var byte ;output latch: load_outputs ; bit7=dacsel2 (active high) ; bit6=dacsel1 (active high) ; bit5=reserved ; bit4=reserved ; bit3=reserved ; bit2=reserved ; bit1=reserved ; bit0=reserved #endif temp var byte ;temp variable rate con 1000 ;blink pause in mS. Cannot be 0 ; ;-----------------------------------------------------------------------------------------------; ; Program ; ;-----------------------------------------------------------------------------------------------; ; ;initialize pins #ifdef cvs 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, clock, 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 cs can not advance low run_led ;reset run led low stop_led ;reset stop led 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 #ifdef cvs let olat=$ff ;set olat i2cout i2c_data,i2c_clk,($20<<1),[$0a,olat];set outputs high i2cout i2c_data,i2c_clk,($20<<1),[$00,$00] ;set iodir to output #endif ;enable midi interrupts sethserial1 h31200,h8databits,hnoparity,h1stopbits pause 250 ;let display initialize hserout [$f0,$7d,$0a,$18,"ComputerVoltSrceSequential Blink",$f7] ;clear, overwrite, name ; ;-----------------------------------------------------------------------------------------------; ; Main Program ; ;-----------------------------------------------------------------------------------------------; ; pause 4000 ;let program name show loop1: let out_j1=1000 gosub load_outputs hserout [$f0,$7d,$0a,$18,"Output 1 LED on",$f7] ;clear, overwrite pause rate let out_j1=0 let out_j2=1000 gosub load_outputs hserout [$f0,$7d,$1a,$07,"2",$f7] ;set absolute position and LED number pause rate let out_j2=0 let out_j3=1000 gosub load_outputs hserout [$f0,$7d,$08,"3",$f7] ;backspace and LED number pause rate let out_j3=0 let out_j4=1000 gosub load_outputs hserout [$f0,$7d,$08,"4",$f7] ;backspace and LED number pause rate let out_j4=0 #ifdef cvs let out_j5=1000 gosub load_outputs hserout [$f0,$7d,$08,"5",$f7] ;backspace and LED number pause rate let out_j5=0 let out_j6=1000 gosub load_outputs hserout [$f0,$7d,$08,"6",$f7] ;backspace and LED number pause rate let out_j6=0 let out_j7=1000 gosub load_outputs hserout [$f0,$7d,$08,"7",$f7] ;backspace and LED number pause rate let out_j7=0 let out_j8=1000 gosub load_outputs hserout [$f0,$7d,$08,"8",$f7] ;backspace and LED number pause rate let out_j8=0 #endif gosub load_outputs high run_led low stop_led hserout [$f0,$7d,$0a,$18,"Start LED on",$f7] ;clear, overwrite Start LED pause rate low run_led high stop_led hserout [$f0,$7d,$0a,$18,"Stop LED on",$f7] ;clear, overwrite Stop LED pause rate low run_led low stop_led hserout [$f0,$7d,$1a,$00,"MIDI",$f7] ;set absolute postion and MIDI LED for temp=1 to (rate/25)+1 ;rate / 25 mS MIDI status LED blink hserout [$fe] ;send active status to blink MIDI status led pause 25 next goto loop1 ; ;-----------------------------------------------------------------------------------------------; ; 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 ; ;output out_jx values to dacs ;750 uS execution time for PSIM ;2.6 mS execution time for CVS load_outputs: #ifdef cvs let olat.bit6=1 ;select dac1 let olat.bit7=0 ;deselect dac2 i2cout i2c_data,i2c_clk,($20<<1),[$0a,olat] ;set olat #endif ;add dac address to out_jx values and shift 16 bits using mode 4 shiftout dac_sdata,dac_clk,fastmsbpre,[(out_j1|$c000)\16] pulsout dac_load,1 ;clock loaddacs shiftout dac_sdata,dac_clk,fastmsbpre,[(out_j2|$8000)\16] pulsout dac_load,1 ;clock loaddacs shiftout dac_sdata,dac_clk,fastmsbpre,[(out_j3|$4000)\16] pulsout dac_load,1 ;clock loaddacs shiftout dac_sdata,dac_clk,fastmsbpre,[out_j4\16] pulsout dac_load,1 ;clock loaddacs #ifdef cvs let olat.bit6=0 ;deselect dac1 let olat.bit7=1 ;select dac2 i2cout i2c_data,i2c_clk,($20<<1),[$0a,olat] ;set olat shiftout dac_sdata,dac_clk,fastmsbpre,[(out_j5|$c000)\16] pulsout dac_load,1 ;clock loaddacs shiftout dac_sdata,dac_clk,fastmsbpre,[(out_j6|$8000)\16] pulsout dac_load,1 ;clock loaddacs shiftout dac_sdata,dac_clk,fastmsbpre,[(out_j7|$4000)\16] pulsout dac_load,1 ;clock loaddacs shiftout dac_sdata,dac_clk,fastmsbpre,[out_j8\16] pulsout dac_load,1 ;clock loaddacs #endif return ; #ifdef cvs ;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 ; ;-----------------------------------------------------------------------------------------------; ; End Of Program ; ;-----------------------------------------------------------------------------------------------;