Actually, they where not just typos, the first two where legitimate mistakes, but I caught them myself (that's what happens when you do this stuff at 1:00am) on the last one I was using a return at the end of each subroutine, but as Darrel and Bruce pointed out, I needed to use Gosub instead of a Goto, so I fixed all the mistakes, but it still does not work, so then I tried Steve's suggestion and changed the DEFINE HSER_BAUD to DEFINE HSER_SPBRG 39, but it still made no difference, incidentally, DEFINE HSER_BAUD 31250 works fine on the 16F628, so I would think it should work on the 16F688 also.
Here is the revised code, any other suggestions would be appreciated.
Code:' PicBasic file for midi footpedal interface using a Pic16F688 ' set osc to HS when programming DEFINE OSC 20 ' tell program we are using a 20mhz oscillator DEFINE HSER_RCSTA 90h ' enable hardware serial port DEFINE HSER_TXSTA 24h ' enable high speed transmit DEFINE HSER_BAUD 31250 ' set the baud rate for MIDI communications DEFINE ADC_BITS 10 ' set the number of bits in the sample DEFINE ADC_SAMPLEUS 50 ' set the sample time TRISA = %00111111 ' Set PORTA to inputs TRISC = %00101111 ' set PORTC to inputs ANSEL = %11110000 ' enable analog 4,5,6,7 the rest as digital ADCON0 = %10000001 ' set VREF to VDD and right justify result ADCON1 = %00100000 ' set conversion clock FOSC/32 CMCON0 = 7 ' turn off comparitors OPTION_REG.7 = 0 ' enable internal pull-ups on porta WPUA = %00000111 ' enable individual pull-ups on porta 0,1,2 C0 Var word ' create C0 to store result from Volume pot C1 Var word ' create C1 to store result from Expression pot C2 Var word ' create C2 to store result from Foot Controller pot C3 Var word ' create C3 to store result from Portamanto Time pot vol Var byte ' create variable for volume exp Var byte ' create variable for expression foo Var byte ' create variable for foot controller por Var byte ' create variable for portamento time volout Var byte ' create variable for volume output expout Var byte ' create variable for expression output fooout Var byte ' create variable for foot controller output porout Var byte ' create variable for portamento time output sw1 Var byte ' create variable to hold switch1 value (sustain on/off) sw2 Var byte ' create variable to hold switch2 value (portamento on/off) loop: ADCIN 4,C0 ' read Volume pot and place value in C0 vol = C0 / 8 ' convert reading to a midi value from 1-127 If vol <> volout Then ' check to see if the value has changed volout = vol HSEROUT [176,7,volout] ' send Volume out serial port as midi information Endif ADCIN 5,C1 ' read expression pot and place value in C1 exp = C1 / 8 ' convert reading to a midi value from 0-127 If exp <> expout Then ' check to see if the value has changed exp = C1 HSEROUT [176,11,expout] ' send exptession out serial port as midi information Endif ADCIN 6,C2 ' read foot controller pot and place value in C2 foo = C2 / 8 ' convert reading to a midi value from 0-127 If foo <> fooout Then ' check to see if the value has changed fooout = foo HSEROUT [176,4,fooout] ' send foot controller out serial port as midi information Endif ADCIN 7,C3 ' read portamento time pot and place value in C3 por = C3 / 8 ' convert reading to a midi value from 0-127 If por <> porout Then ' check to see if the value has changed porout = por HSEROUT [176,5,porout] ' send portamento time out serial port as midi information Endif If porta.0 = 0 Then gosub sw1on ' check sustain pedal If porta.0 = 1 Then gosub sw1off If porta.1 = 0 Then gosub sw2on ' check portamento pedal If porta.1 = 1 Then gosub sw2off If porta.2 = 0 Then Hserout [255] ' reset all controllers Endif Goto Loop ' go back to continuous monitoring sw1on: If sw1 = 0 Then ' check to see if sustain is off sw1 = 127 Hserout [176,64,sw1] ' turn on sustain Endif return sw1off: If sw1 = 127 Then ' check to see if sustain is on sw1 = 0 Hserout [176,64,sw1] ' turn off sustain Endif return sw2on: If sw2 = 0 Then ' check to see if portamento is off sw2 = 127 Hserout [176,65,sw2] ' turn on portamento Endif return sw2off: If sw2 = 127 Then ' check to see if portamento is on sw2 = 0 Hserout [176,65,sw2] ' turn off portamento Endif return




Bookmarks