'**************************************************************** '* Name : Fa_Valves.BAS * '* Author : Godfried-Willem RAES * '* Notice : Copyleft (c) 2012 Logosoft Public Domain * '* Date : 20-01-2012 * '* Version : 1.7 * '* Notes : first code for the 18F4620 * '**************************************************************** ' 22.04.2011: start code setup ' all five ports are required for the valve lookups ' 23.04.2011: First version of firmware ready for testing V1.0 ' for the fingered vibrato we will have to introduce a second task ' implemented here: note-on/off, with time out for valve release ' power on/off ctrl ' fingering controllers ' 24.04.2011: range bug removed ' start coding for fingered vibrato, using channel aftertouch ' 25.04.2011: cnthw overflows when reaching 00FF. Can this cause trouble? ' valve release seems not working. ' Portb.5 masked. ' Seems working now, though the lookups can be improved. ' fingered vibrato needs to be tested. ' 27.04.2011: first empirical tests with fingered vibrato. Firmware version 1.2 ' some code optimized for speed ' 28.04.2011: Code improvement for speed. rsi arrays removed. ' further improvement possible by introducing a scheduler ' we still do not get the fingered vibrato to work... ' Try using a periodic timer: CntLw.11, gives ca. 8 Hz ' Still problems with getting even this to work... ' 29.04.2011: release mechanism works. Vibrato fails. ' trying to use timer3 ' 30.04.2011: Finally got timer3 working on the low interrupt ' This version works fine, but the mechanism to change vibrato speed ' seems to fail... ' solved: we have to reload timer3 after each overflow in the interrupt. ' Version 1.4. ' 01.05.2011: Postscaler :4 added in timer3 interrupt. Now we can have slow vibrato as well! ' Timer macro's include file no longer required. ' 24.05.2011: IRQ coding improved. Basic Toggle exchanged with faster btg assembler instructions ' Version 1.5 ' lowest octave vibrato valve mapping modified after in place tests. ' Now any valve can be used to perform the vibrato. ' 25.05.2011: Further tuning of the vibrato lookup table. Version 1.6 now ' 20.01.2012: Bug in TRISE setting removed: Bit 4 must be cleared in TRISE For port D To work normally!!! ' discovered in debugging the code for - finger PIC. ' Version 1.7 now. Include "18F4620.inc" ' for the Fa-Valves processor (40MHz) ' Mapping defines for midi-events on pin outputs and inputs: ' valves $define Valve1 PORTA.2 $define Valve2 PORTA.1 $define Valve3 PORTA.0 $define Valve4 PORTA.3 $define Valve5 PORTA.4 $define Valve6 PORTA.5 $define Valve7 PORTE.0 ' seems to give problems... $define Valve8 PORTE.1 $define Valve9 PORTE.2 $define Valve10 PORTB.4 $define Valve11 PORTB.3 $define Valve12 PORTB.2 $define Valve13 PORTB.1 $define Valve14 PORTB.0 $define Valve15 PORTD.7 $define Valve16 PORTD.6 $define Valve17 PORTD.5 $define Valve18 PORTD.4 $define Valve19 PORTC.5 ' green LED, pin 24 $define Valve20 PORTC.4 ' green LED, pin 23 $define Valve21 PORTD.3 ' yellow LED, pin 22 $define Valve22 PORTD.2 ' yellow LED, pin 21 $define Valve23 PORTC.0 ' nc green LED, pin 15 $define Valve24 PORTC.1 ' nc greem LED, pin 16 $define Valve25 PORTC.2 ' nc green LED, pin 17 $define Valve26 PORTC.3 ' nc green LED, pin 18 $define Valve27 PORTD.0 ' nc yellow led on test board, pin 19 $define Valve28 PORTD.1 ' nc yellow led on test board, pin 20 'red LED for debug: $define Debug_Led PORTB.5 ' for testing - red led - watchdog Declare All_Digital = True ' makes all analog pins, digital for I/O Clear SSPCON1.5 ' make sure RC3 is free for use. ' configure the input and output pins: TRISA = %11000000 'bits set to 0 are output, 1 = input - bits 6 and 7 are the clock! TRISB = %11100000 'bits 6 and 7 are for the ICP, bit 5 is the red LED TRISC = %11000000 'RC6 en RC7 zijn USART I/O and must be set to input TRISD = %00000000 'all bits can be used TRISE = %11101000 'low nibble only, bit3 (RE3) is MCLR ' bit 4 must be cleared for port D to work normally!!! 'constant definitions: 'initialisations for the midi input parser: Symbol Midichannel = 15 ' Fa_Channel Symbol NoteOff_Status = 128 + Midichannel ' 2 bytes follow Symbol NoteOn_Status = 144 + Midichannel Symbol Keypres_Status = 160 + Midichannel Symbol Control_Status = 176 + Midichannel Symbol ProgChange_Status = 192 + Midichannel ' 1 byte message Symbol Aftertouch_Status = 208 + Midichannel ' 1 byte follows Symbol Pitchbend_Status = 224 + Midichannel ' lsb msb follow ' Setup the USART Declare Hserial_Baud = 31250 ' Set baud rate for the USART to MIDI specs. Declare Hserial_TXSTA = 0x24 ' instead of the normal 0x20 - ?? 0x24 ' Declare Hserial_Clear = On ' should clear on errors. Bytes get lost of course... This must be 31250 for MIDI ' Create variables: Dim Cnt As Dword System '32 bit counter Dim CntHw As Cnt.Word1 ' Word System 'used in the timer0 interrupt, where it is incremented Dim CntLw As TMR0L.Word 'this is the trick to read both TMR0L and TMR0H 'it makes Cntlw the low word of cnt, when we use cnt.word0=CntLw Dim Tim1 As TMR1L.Word Dim Tim2 As TMR2 Dim Cnt3 As Dword System Dim Cnt3Hw As Cnt3.Word1 Dim Tim3 As TMR3L.Word ' same trick for timer3 ' Dim Sr as TMR0L.7 '512 S/s - this works but these DO NOT WORK!!!: ' Dim Sr as CntLw.Byte1 does not ' Dim Sr As TMR0H.0 'sampling rate bit, 256 S/s ' DIM Sr as CntLw.8 ' As TMR0H.1 would be 128 S/s ' As TMR0H.2 would be 64 S/s ' As TMR0H.3 would be 32 S/s ' As TMR0H.4 would be 16 S/s Dim Bytein As Byte System ' midi byte read from buffer Dim StBit As Bytein.7 ' highest bit of ByteIn Dim i As Byte System ' general purpose counter ' midi variables Dim statusbyte As Byte System Dim noteUit As Byte System ' note off + release value Dim release As Byte System Dim noteAan As Byte System ' note on + release value Dim velo As Byte System Dim notePres As Byte System ' note pressure + pressure value Dim pres As Byte System Dim Ctrl As Byte System ' continuous controller + value Dim value As Byte System Dim prog As Byte System ' program change + program-byte Dim aft As Byte System ' channel aftertouch Dim pblsb As Byte System ' pitch bend lsb Dim pbmsb As Byte System ' pitch bend msb ' Dim veltim As Dword System ' 32 bit velo Dim veltim0 As Dword System ' faster, replaces the arrays ' Dim veltim1 As Dword System Dim VelFlags0 As Byte System ' so we can have only 8 tasks Dim CC66 As Byte System ' global on/off switch Dim PowerOn As CC66.0 Dim st As Byte System Dim b1 As Byte System Dim b2 As Byte System Dim Idx As Byte System Dim Playingnote As Byte System Dim CC30 As Byte System ' valve hold down time, midi value Dim ReleaseTime As Word System ' calculated from CC30 Dim VibratoPeriod As Word System ' was: Task_rsi[1] Dim VibratoValve As Byte System ' calculated from CC31 Dim CC31 As Byte System ' vibrato controller, midi value Dim FingersA[46] As Byte ' 0 to 45 Dim FingersB[46] As Byte Dim FingersC[46] As Byte Dim FingersD[46] As Byte Dim FingersE[46] As Byte ' for the extended range 80-91 we use a section of the same lookup) Dim Vib[59] As Byte ' valve to use for fingered vibrato, this runs from 34 to 91 in notes '----------------------------------------------------------------------------------------- ' Load the USART Interrupt handler and buffer read subroutines into memory Include "Fa_Valves_Midi_Irq.inc" ' our own version for UART,Timer0, Timer3 Interrupt 'Include "Fa_Valves_Timers.inc" ' required for velo support with timed pulses and periods. 'Include "DwordArrays.inc" ' support for dword arrays. 'Include "ADC.inc" ' Load the ADC macros into the program 'DeclareDwordArray(TimeVals , NrTasks) 'alternative using the macro's. [not yet used] ' assigning values syntax: DwordArray Timvals,[i], value ' reading values syntax: value = DwordArray TimVals,[i] 'Clear ' clear all RAM '----------------------------------------------------------------------------------------- ' Main program starts here MAIN: High Debug_Led DelayMS 10 ' wait for stability Low Debug_Led GoSub PowerDown GoSub Valve_Table ' read the fingerings lookup table Clear CC66 CC30 = 120 ' default ReleaseTime = CC30 <<9 Clear CC31 Init_Usart_Interrupt ' Initiate the USART serial buffer interrupt ' this procedure is in the include file Clear_Serial_Buffer ' Clear the serial buffer and reset its pointers ' in the include as well ' following only required for pulse outputs: ' Note that we can only use timer0 since the other timers ' are used by the PWM subsystem ' Configure Timer0 for: ' Clear TMR0L and TMR0H registers ' Interrupt on Timer0 overflow ' 16-bit operation ' Internal clock source 40MHz ' 1:256 Prescaler : thus 40MHz / 256 = 156.250kHz ' 6.4 us per clock-tick ' Opentimer0 (Timer_INT_On & T0_16BIT & T0_SOURCE_INT & T0_PS_1_256) ' replacing above macro with in-line coding: Clear T1CON Clear IntConBits_T0IF ' clear interrupt flag Set INTCONBITS_T0IE ' enable interrupt on overflow T0CON = %10000111 ' bit 7 = enable/disable ' bit 6 = 1=8 bot, 0=16 bit ' bit 5 = 1 pin input, 0= Internal Clk0 ' bit 4 = HL or LH transition when bit5 =1 ' bit 3 = 1= bypass prescaler, 0= input from prescaler ' bit 2-0 = prescaler select: 111= 1:256 ' Setup the High priorities for the interrupts ' TIMER1: if enabled, all midi-in is blocked, so it must interfere with the UART ' Configure Timer1 for: ' Clear TMR1L and TMR1H registers ' Interrupt on Timer1 overflow ' 16-bit read/write mode ' Internal clock source ' 1:8 Prescaler ' ' OpenTimer1(TIMER_INT_ON & T1_16BIT_RW & T1_SOURCE_INT & T1_PS_1_8) ' dit kompileert o.k. ' TIMER2: if enabled, the UART stops working... ' Opentimer2 (Timer_Int_On & T2_POST_1_16 & T2_PS_1_16) ' dit lukt... maar de timer is nodig voor de UART... ' TIMER3: ' Configure Timer3 for: ' ' Interrupt on Timer3 overflow ' 16-bit read/write mode ' Internal clock source ' 1:8 Prescaler ' Don’t sync external clock input ' T3_OSC1En_On () ' macro ' OpenTimer3(TIMER_INT_ON & T3_16BIT_RW & T3_SOURCE_INT & T3_PS_1_8 & T3_SYNC_EXT_OFF) ' fout, but == voorbeeld??? ' Opentimer3 (Timer_Int_On & T3_16BIT_RW & T3_SOURCE_INT & T3_PS_1_8 & T3_SYNC_EXT_OFF & T3_SOURCE_CCP) ' fout ' OpenTimer3 (Timer_INT_ON & T3_16BIT_RW & T3_PS_1_8 & T3_SYNC_EXT_OFF) ' fout ' OpenTimer3 (0xFFFF & Timer_INT_On & T3_16BIT_RW) ' OpenTimer3(T3_8BIT_RW & T3_SOURCE_EXT & T3_PS_1_1 & T3_SYNC_EXT_OFF) ' copied from manual, fout!!! ' OpenTimer3(TIMER_INT_OFF & T3_16BIT_RW & T3_SOURCE_INT & T3_PS_1_8) ' doing it this way seems to work: Clear T3CON Clear PIR2BITS_TMR3IF ' clear IRQ flag Set PIE2BITS_TMR3IE ' irq on 'T3_OSC1En_On () ' macro - sets T3CON Clear Tim3 ' Clear TMR3L And TMR3H registers Set RCONbits_IPEN ' Enable priority interrupts Clear IPR2bits_TMR3IP ' Set Timer3 as a low priority interrupt source ' we can also set T3Con in one instruction as: T3CON = %10110001 ' oef, now it works... ' bit 7 = 16 bit mode ' bit 6,3 = 0, 0 ' bit 5,4 = 1:8 prescale ' bit 2 = 0 ' bit 1 = 0 Internal clock = Fosc/4 ' bit 0 : 1= enable timer 3, 0= disable ' maximum count = 52.42ms, 1 tick =0.8uS, freq.=19Hz ' Set up priority interrupts. ' IPR1bits_TMR1IP = 0 ' Set Timer1 as a low priority interrupt source ' INTCONbits_PEIE = 1 ' Enable peripheral interrupts ' INTCONbits_GIE = 1 ' Enable global interrupts ' Open the ADC: ' not used on this board. ' Fosc/32 ' Right justified for 10-bit operation ' Tad value of 0 ' Vref+ at Vcc : Vref- at Gnd ' Make AN0 an analogue input ' ' OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_0_TAD, ADC_REF_VDD_VSS, ADC_1ANA) ' start the main program loop: LOOP: ' Create an infinite loop 'PortD.1 = TMR0H.5 ' dit werkt 'PortD.1 = CntLw.12 ' werkt ook ' If CC31 > 0 Then Valve28 = Tim3.5 'CntLw.11 ' werkt ook (ca 8Hz) - stopt wanneer PortE.0 hoog is?????????? 'PORTD.1 = CntLw.11 ' Valve28 = CntHw.1 ' werkt ook - de timers lopen dus goed 'Valve28 = Cnt.17 ' werkt ok 'Cnt.Word1 = CntHw ' read highword also, to complete cnt even when no timers are running ' no longer required, since CntHw is now defined as Cnt.Word1 Bytein = HRSIn ' Read data from the serial buffer, with no timeout ' Start the midi parser. Midi_Parse: If Bytein > Control_Status Then ' here higher statusses are not implemented. If Bytein > 253 Then '254 = midiclock, 255= reset 'midiclock can interrupt all other msg's... '255 had to be intercepted since thats what we 'get when no new byte flows in (?) GoTo Check_Timers 'throw away... Else Clear statusbyte 'reset the status byte GoTo Check_Timers 'throw away End If EndIf If StBit =1 Then 'should be faster than If Bytein > 127 Then 'status byte received, bit 7 is set Clear statusbyte 'if on another channel, the statusbyte needs a reset Select Bytein 'eqv to Select case ByteIn Case NoteOff_Status statusbyte = Bytein Set noteUit 'reset value. Cannot be 0 !!! Set release '0 is a valid midi note! Case NoteOn_Status statusbyte = Bytein Set noteAan '= 255 Set velo '= 255 ' Case Keypres_Status 'not used for fingered vibrato ' statusbyte = Bytein ' notePres = 255 ' pres = 255 Case Control_Status ' for fingerings statusbyte = Bytein Set Ctrl Set value ' Case ProgChange_Status ' could be used for different lookup tables ' statusbyte = Bytein ' prog = 255 Case Aftertouch_Status ' for fingered vibrato statusbyte = Bytein Set aft ' Case Pitchbend_Status ' statusbyte = Bytein ' pblsb = 255 ' pbmsb = 255 End Select Else 'midi byte is 7 bits Select statusbyte Case 0 'not a message for this channel GoTo Check_Timers 'disregard Case NoteOff_Status If noteUit = 255 Then noteUit = Bytein Else release = Bytein 'message complete, so we can do the action... Select noteUit Case 34 To 91 ' here we should start a timer. ' when the timer runs out, we release the valves. Set VelFlags0.0 'set the timer Clear T3CONBITS_TMR3ON 'stop timer 3 Clear Playingnote 'no note anymore Clear VelFlags0.1 'no fingered vibrato Cnt.Word0 = CntLw 'read counter veltim0 = Cnt + ReleaseTime 'add the period duration (CC30) End Select Set noteUit '= 255 'reset EndIf 'GoTo Check_Timers Case NoteOn_Status If noteAan = 255 Then noteAan = Bytein Else velo = Bytein If velo = 0 Then Select noteAan Case 34 To 91 ' equivalent to noteoff ' so we start a timer for valve releases. Set VelFlags0.0 'set the timer Clear T3CONBITS_TMR3ON ' stop timer 3 Clear VelFlags0.1 ' vibrato off Clear Playingnote Cnt.Word0 = CntLw veltim0 = Cnt + ReleaseTime 'add the timeout duration End Select Else Select noteAan Case 34 To 79 Idx = noteAan - 34 Clear VelFlags0.0 ' start release timer only after note-off PORTA = FingersA[Idx] '| %11000000 'PORTB = FingersB[Idx] ' interferes with Portb.5, red LED !!! ' hence we do this trick: i = FingersB[Idx] i.5 = PORTB.5 ' read the red_led port 'FingersB[Idx].5 = PORTB.5 gaat niet met de syntax 'FingersB.5[Idx] = PortB.5 dit evenmin 'PortB = FingersB[Idx] PORTB = i '| %11000000 PORTC = FingersC[Idx] '| %11000000 'i = FingersD[Idx] 'i.0 = PORTD.0 'PORTD = i PORTD = FingersD[Idx] ' i = FingersE[Idx] ' i.3 = PORTE.3 ' mask MCLR ' PORTE = i ' FingersE[Idx] '| %11111000 ' PortE.0 seems to be blocking timers PORTE= FingersE[Idx] Playingnote = noteAan If CC31 > 0 Then VibratoValve = Vib[Idx] ' 1-12 Set VelFlags0.1 Set T3CONBITS_TMR3ON ' start timer End If Case 80 To 91 Idx = noteAan - 46 Clear VelFlags0.0 PORTA = FingersA[Idx] i = FingersB[Idx] i.5 = PORTB.5 PORTB = i PORTC = FingersC[Idx] 'i = FingersD[Idx] 'i.0 = PORTD.0 'PORTD = i PORTD = FingersD[Idx] 'i = FingersE[Idx] 'i.3 = PORTE.3 PORTE = FingersE[Idx] Playingnote = noteAan If CC31 > 0 Then VibratoValve = Vib[Idx+12] ' correct Set VelFlags0.1 Set T3CONBITS_TMR3ON EndIf End Select Set noteAan '= 255 'reset !!! EndIf EndIf 'GoTo Check_Timers ' Case Keypres_Status 'used for lite flashing on Fa-Hub ' 'in used by PIC2 for fingerings !!! ' 'here we could use it for fingered vibrato ' If notePres = 255 Then ' notePres = Bytein ' Else ' pres = Bytein ' 'GoSub KeyPres ' EndIf ' GoTo Check_Timers Case Control_Status 'this is where the action takes place for controllers If Ctrl = 255 Then Ctrl = Bytein Else value = Bytein GoSub Controller ' fingerings implemented here EndIf 'GoTo Check_Timers ' Case ProgChange_Status ' could be used to select alternative fingering lookups ' If prog = 255 Then 'single byte message ' prog = Bytein 'weak coding... ' GoSub ProgChange ' EndIf Case Aftertouch_Status If aft = 255 Then aft = Bytein GoSub Aftertouch EndIf ' GoTo Check_Timers End Select EndIf Check_Timers: ' here we check the Task counters and compare them with the 32 bit cnt value ' using the Velflags dword variable: 'If VelFlags0 > 0 Then 'if any bit is set here, there is a timer running ' to speed up things, we could first check for the smallest of the veltim's ' and only compare that one with the counter. If VelFlags0.0 = 1 Then ' on this board we use this timer for release Cnt.Word0 = CntLw ' read counter If Cnt >= veltim0 Then GoSub Valves_Down Clear VelFlags0.0 ' one shot EndIf EndIf GoTo LOOP ' end of the main loop 'KeyPres: ' ' not implemented on this board for ' notePres = 255 'Return 'ProgChange: ' prog = 255 'this is not realy required 'Return 'Pitchbend: ' 'only implemented on dsPIC based robots, irrelevant here ' set pblsb '= 255 'Return Aftertouch: ' 'this is the channel aftertouch, affecting any playing note ' 'used for fingered vibrato ' 'the value of aft is used to set the vibrato speed. Minimum freq=19Hz/2 = 9.54Hz ' coding using timer3: If aft > 0 Then Clear T3CONBITS_TMR3ON ' stop timer CC31 = aft VibratoPeriod = CC31 << 9 '* CC31 Tim3 = VibratoPeriod Set T3CONBITS_TMR3ON ' restart timer Else Clear CC31 Clear VibratoPeriod Clear T3CONBITS_TMR3ON ' stop timer EndIf Set aft ' reset Return Controller: ' here we implement 4 controllers for alternate fingering 4 x 7 = 28 Select Ctrl Case 30 ' valve release time controller CC30 = value If CC30 = 0 Then Clear VelFlags0.0 Else ReleaseTime = CC30 << 9 ' shift to the high word End If Case 31 If value <> CC31 Then If value > 0 Then Clear T3CONBITS_TMR3ON ' stop timer CC31 = value ' used as vibrato switch for debugging VibratoPeriod = CC31 << 9 '* CC31 ' same as aftertouch Tim3 = VibratoPeriod Set T3CONBITS_TMR3ON ' start timer Else Clear T3CONBITS_TMR3ON Clear CC31 Clear VibratoPeriod EndIf EndIf Case 66 'on/off for the robot If value = 0 Then Clear PowerOn 'CC66.0 =0 GoSub PowerDown Else Set PowerOn 'CC66.0 =1 EndIf Case 100 Valve1 = value.0 Valve2 = value.1 Valve3 = value.2 Valve4 = value.3 Valve5 = value.4 Valve6 = value.5 Valve7 = value.6 Case 101 Valve8 = value.0 Valve9 = value.1 Valve10 = value.2 Valve11 = value.3 Valve12 = value.4 Valve13 = value.5 Valve14 = value.6 Case 102 Valve15 = value.0 Valve16 = value.1 Valve17 = value.2 Valve18 = value.3 Valve19 = value.4 Valve20 = value.5 Valve21 = value.6 Case 103 Valve22 = value.0 Valve23 = value.1 Valve24 = value.2 Valve25 = value.3 Valve26 = value.4 Valve27 = value.5 Valve28 = value.6 Case 123 GoSub PowerDown End Select Set Ctrl 'mandatory reset Return PowerDown: 'should switch off all valves activated Clear VelFlags0 'stop all running timers Clear CntHw ' reset timer 'Low Debug_Led ' Low Valvex is no good, as it affects the TRIS settings Clear Valve1 Clear Valve2 ' = 0 Clear Valve3 ' = 0 Clear Valve4 ' = 0 Clear Valve5 ' = 0 Clear Valve6 ' = 0 Clear Valve7 ' = 0 Clear Valve8 ' = 0 Clear Valve9 ' = 0 Clear Valve10 ' = 0 Clear Valve11 ' = 0 Clear Valve12 ' = 0 Clear Valve13 ' = 0 Clear Valve14 ' = 0 Clear Valve15 ' = 0 Clear Valve16 ' = 0 Clear Valve17 ' = 0 Clear Valve18 ' = 0 Clear Valve19 ' = 0 Clear Valve20 ' = 0 Clear Valve21 ' = 0 Clear Valve22 ' = 0 Clear Valve23 ' = 0 Clear Valve24 ' = 0 Clear Valve25 ' = 0 Clear Valve26 ' = 0 Clear Valve27 ' = 0 Clear Valve28 ' = 0 Return Valves_Down: ' only bits really connected to valves Clear Valve1 Clear Valve2 Clear Valve3 Clear Valve4 Clear Valve5 Clear Valve6 Clear Valve7 Clear Valve8 Clear Valve9 Clear Valve10 Clear Valve11 Clear Valve12 Clear Valve13 Clear Valve14 Clear Valve15 Clear Valve16 Clear Valve17 Clear Valve18 Clear Valve19 Clear Valve20 Clear Valve21 Clear Valve22 Return Valve_Table: ' index = midinoot - 34 FingersA[0] = %00000000 FingersB[0] = %00000000 ' portB FingersC[0] = %00000000 ' portC FingersD[0] = %00000000 FingersE[0] = %0000 ' portE FingersA[1] = %00000100 ' 35, port A FingersB[1] = %00000000 FingersC[1] = %00000000 FingersD[1] = %00000000 FingersE[1] = %0000 FingersA[2] = %00000110 ' 36 FingersB[2] = %00000000 FingersC[2] = %00000000 FingersD[2] = %00000000 FingersE[2] = %0000 FingersA[3] = %00000111 ' 37 FingersB[3] = %00000000 FingersC[3] = %00000000 FingersD[3] = %00000000 FingersE[3] = %0000 FingersA[4] = %00001110 ' 38 FingersB[4] = %00000000 FingersC[4] = %00000000 FingersD[4] = %00000000 FingersE[4] = %0000 FingersA[5] = %00011110 ' 39 FingersB[5] = %00000000 FingersC[5] = %00000000 FingersD[5] = %00000000 FingersE[5] = %0000 FingersA[6] = %00101110 ' 40 FingersB[6] = %00000000 FingersC[6] = %00000000 FingersD[6] = %00000000 FingersE[6] = %0000 FingersA[7] = %00101110 ' 41 FingersB[7] = %00000000 FingersC[7] = %00000000 FingersD[7] = %00000000 FingersE[7] = %00000001 FingersA[8] = %00101110 ' 42 FingersB[8] = %00000000 FingersC[8] = %00000000 FingersD[8] = %00000000 FingersE[8] = %00000101 FingersA[9] = %00101110 ' 43 FingersB[9] = %00000000 FingersC[9] = %00000000 FingersD[9] = %00000000 FingersE[9] = %00000011 FingersA[10] = %00101110 ' 44 FingersB[10] = %00000100 FingersC[10] = %00000000 FingersD[10] = %00000000 FingersE[10] = %00000011 FingersA[11] = %00101110 ' 45 FingersB[11] = %00001000 FingersC[11] = %00000000 FingersD[11] = %00000000 FingersE[11] = %00000011 FingersA[12] = %00101110 ' 46 FingersB[12] = %00001001 FingersC[12] = %00000000 FingersD[12] = %00000000 FingersE[12] = %00000011 FingersA[13] = %00101110 ' 47 FingersB[13] = %00001010 FingersC[13] = %00000000 FingersD[13] = %00000000 FingersE[13] = %00000011 FingersA[14] = %00101110 ' 48 FingersB[14] = %00001010 FingersC[14] = %00000000 FingersD[14] = %10000000 FingersE[14] = %00000011 FingersA[15] = %00001110 ' 49 FingersB[15] = %00001010 FingersC[15] = %00000000 FingersD[15] = %10100000 FingersE[15] = %00000011 FingersA[16] = %00101110 ' 50 FingersB[16] = %00001010 FingersC[16] = %00000000 FingersD[16] = %11000000 FingersE[16] = %00000011 FingersA[17] = %00111110 ' 51 FingersB[17] = %00001010 FingersC[17] = %00000000 FingersD[17] = %10010000 FingersE[17] = %00000011 FingersA[18] = %00101110 ' 52 FingersB[18] = %00001010 FingersC[18] = %00000000 FingersD[18] = %11010000 FingersE[18] = %00000011 FingersA[19] = %00101110 ' 53 FingersB[19] = %00001010 FingersC[19] = %00100000 FingersD[19] = %11010000 FingersE[19] = %00000011 FingersA[20] = %00001110 ' 54 FingersB[20] = %00000000 FingersC[20] = %00100000 FingersD[20] = %00000000 FingersE[20] = %00000101 FingersA[21] = %00111110 ' 55 FingersB[21] = %00000000 FingersC[21] = %00100000 FingersD[21] = %00000000 FingersE[21] = %00000011 FingersA[22] = %00101110 ' 56 FingersB[22] = %00000100 FingersC[22] = %00100000 FingersD[22] = %00000000 FingersE[22] = %00000011 FingersA[23] = %00101110 ' 57 FingersB[23] = %00001000 FingersC[23] = %00010000 FingersD[23] = %00000000 FingersE[23] = %00000011 FingersA[24] = %00101110 ' 58 FingersB[24] = %00001001 FingersC[24] = %00010000 FingersD[24] = %00000000 FingersE[24] = %00000011 FingersA[25] = %00101110 ' 59 FingersB[25] = %00001010 FingersC[25] = %00000000 FingersD[25] = %00001000 FingersE[25] = %00000011 FingersA[26] = %00101110 ' 60 FingersB[26] = %00001010 FingersC[26] = %00000000 FingersD[26] = %10000000 FingersE[26] = %00000011 FingersA[27] = %00001110 ' 61 FingersB[27] = %00001010 FingersC[27] = %00000000 FingersD[27] = %10100000 FingersE[27] = %00000011 FingersA[28] = %00101110 ' 62 FingersB[28] = %00001010 FingersC[28] = %00000000 FingersD[28] = %11000000 FingersE[28] = %00000011 FingersA[29] = %00101110 ' 63 FingersB[29] = %00000000 FingersC[29] = %00000000 FingersD[29] = %01000000 FingersE[29] = %00000011 FingersA[30] = %00111110 ' 64 FingersB[30] = %00000000 FingersC[30] = %00000000 FingersD[30] = %00010000 FingersE[30] = %00000011 FingersA[31] = %00111110 ' 65 FingersB[31] = %00001000 FingersC[31] = %00000000 FingersD[31] = %00010000 FingersE[31] = %00000011 FingersA[32] = %00111110 ' 66 FingersB[32] = %00001000 FingersC[32] = %00100000 FingersD[32] = %00000000 FingersE[32] = %00000001 FingersA[33] = %00111110 ' 67 FingersB[33] = %00001010 FingersC[33] = %00100000 FingersD[33] = %00000000 FingersE[33] = %00000001 FingersA[34] = %00111110 ' 68 FingersB[34] = %00000010 FingersC[34] = %00100000 FingersD[34] = %10000000 FingersE[34] = %00000011 FingersA[35] = %00111110 ' 69 FingersB[35] = %00000010 FingersC[35] = %00010000 FingersD[35] = %10100000 FingersE[35] = %00000011 FingersA[36] = %00111110 ' 70 FingersB[36] = %00001000 FingersC[36] = %00010000 FingersD[36] = %00100000 FingersE[36] = %00000001 FingersA[37] = %00111110 ' 71 FingersB[37] = %00001001 FingersC[37] = %00000001 FingersD[37] = %01001000 FingersE[37] = %00000001 FingersA[38] = %00111110 ' 72 FingersB[38] = %00001001 FingersC[38] = %00000001 FingersD[38] = %01011000 FingersE[38] = %00000001 FingersA[39] = %00111110 ' 73 FingersB[39] = %00000111 FingersC[39] = %00000000 FingersD[39] = %00011000 FingersE[39] = %00000011 FingersA[40] = %00111110 ' 74 FingersB[40] = %00000111 FingersC[40] = %00100000 FingersD[40] = %10011000 FingersE[40] = %00000011 FingersA[41] = %00001110 ' 75 FingersB[41] = %00001010 FingersC[41] = %00100000 ' RC5 should be 1/2 hole... FingersD[41] = %10100000 FingersE[41] = %00000011 FingersA[42] = %00001110 ' 76 FingersB[42] = %00000000 FingersC[42] = %00000000 ' FingersD[42] = %00100000 FingersE[42] = %00000011 FingersA[43] = %00101110 ' 77 FingersB[43] = %00000101 FingersC[43] = %00100000 ' FingersD[43] = %10100000 FingersE[43] = %00000011 FingersA[44] = %00111110 ' 78, we use same as 66 FingersB[44] = %00001000 FingersC[44] = %00100000 FingersD[44] = %00000000 FingersE[44] = %00000001 FingersA[45] = %00101110 ' 79 FingersB[45] = %00001010 FingersC[45] = %00010000 ' FingersD[45] = %11010000 FingersE[45] = %00000011 'TRISA = %11000000 'bits set to 0 are output, 1 = input - bits 6 and 7 are the clock! 'TRISB = %11100000 'bits 6 and 7 are for the ICP, bit 5 is the red LED 'TRISC = %11000000 'RC6 en RC7 zijn USART I/O and must be set to input 'TRISD = %00000000 'all bits can be used 'TRISE = %11111000 'low nibble only, bit3 (RE3) is MCLR 'For i = 0 To 45 ' FingersA[i] = FingersA[i] | %11000000 ' boolean OR ' FingersB[i] = FingersB[i] | %11100000 ' FingersC[i] = FingersC[i] | %11000000 ' 'FingersD[i] = FingersD[i] | %00000000 ' FingersE[i] = FingersE[i] | %11111000 'Next i ' array with assignment of valve numbers to use for vibrato ' this list has to be empirically verified. ' as implemented first we could only use valves 1-12 for vibrato ' 24.05: extended such that we can use all valves for vibrato Vib[0] = 8 '12 '10 - changed 25.05 gwr - note 34 Vib[1] = 11 '9 - changed 24.05 gwr Vib[2] = 8 '9 - changed 24.05 gwr Vib[3] = 11 '5 - changed 24.05 gwr Vib[4] = 12 '6 - changed 24.05 gwr Vib[5] = 11 '9 '8 - changed 25.05 gwr - note 39 Vib[6] = 8 '7 - changed 24.05 gwr Vib[7] = 6 Vib[8] = 14 '10 - changed and range adapted in IRQ handler branch lookup Vib[9] = 11 '10 - changed 24.05 gwr Vib[10] = 17 '1 - vhanged 25.05 gwr - note 44 Vib[11] = 14 '18 '12 - changed 25.05 gwr - note 45 - 18 did'nt work Vib[12] = 11 '7 - changed 24.05 gwr Vib[13] = 8 Vib[14] = 8 '7 - changed 25.05 gwr note 48 Vib[15] = 10 Vib[16] = 8 Vib[17] = 12 Vib[18] = 1 Vib[19] = 10 Vib[20] = 6 Vib[21] = 11 ' 10 changed 25.05 gwr note 55 Vib[22] = 1 Vib[23] = 12 Vib[24] = 9 ' 7 changed 25.05 gwr note 58 Vib[25] = 8 Vib[26] = 7 Vib[27] = 5 Vib[28] = 8 Vib[29] = 8 Vib[30] = 1 Vib[31] = 10 Vib[32] = 6 Vib[33] = 10 ' 7 changed 25.05 gwr note 67 Vib[34] = 8 Vib[35] = 11 ' 9 changed 25.05 gwrt note 69 Vib[36] = 10 Vib[37] = 12 ' 9 changed 25.05 gwr note 71 Vib[38] = 5 Vib[39] = 5 Vib[40] = 8 Vib[41] = 9 ' 12 changed 25.05 gwr note 75 Vib[42] = 10 ' 1 changed 25.05.gwr note 76 Vib[43] = 10 Vib[44] = 6 Vib[45] = 7 Vib[46] = 8 Vib[47] = 12 ' 9 changed 25.05 gwr note 81 Vib[48] = 10 Vib[49] = 12 ' 9 changed 25.05 gwr note 83 Vib[50] = 5 ' note 84 Vib[51] = 5 ' note 85 Vib[52] = 8 ' note 86 Vib[53] = 12 ' note 87 Vib[54] = 1 ' note 88 Vib[55] = 10 ' note 89 Vib[56] = 6 ' note 90 Vib[57] = 7 ' note 91 Return '[EOF]