'**************************************************************** '* Name : midiExperiment.BAS * '* Author : Rob Seward * '* Notice : Copyright (c) 2004 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 10/29/2004 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** 'midiDemo.bas define OSC 20 'setup hardware serial port: define HSER_RXSTA 90h define HSER_TXSTA 20h define HSER_BAUD 31250 'midi data rate 'set ADC parameters: DEFINE ADC_BITS 10 define ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 adcon1 = %10000010 'standard configuration 'constants: serialMode con 16468 'for LCD serial data noteOnChan1 con 144 'midi status byte for "noteOn, channel 1" noteOffChan1 con $80 controlChan1 con 176 'midi status byte for "continuous controller, chan 1" 'name all pins: statusLed var portb.7 LCDserial var portc.4 'midi will occur on hardware portc.6 pot1Input con 0 'analog channel for first pot pot2Input con 1 'and second pot switch1 var portd.0 'declare variables: potValue var word v1 var byte v1Prev var byte v2 var byte v2Prev var byte 'setup i/o: output statusled output LCDserial TRISA = %11111111 'all analog channels set to input 'and set initial states input switch1 high statusled pause 500 low statusLED serout2 lcdserial, serialmode, [12, 1] 'clear the LCD sequence var byte[7] i var byte i = 0 temp var word clock var word clock = 0 gosub randomize main: adcin pot1input, potValue v1 = potValue/8 ' 10 bits -> 7 bits adcin pot2input, potValue v2 = potValue/8 ' 10 bits -> 7 bits if i >= 6 then i = 0 endif hserout [noteonchan1, sequence[i] + 60, 127] 'noteOn message pause 250 ' noteoff channel 1, middle A hserout [noteOffChan1, sequence[i] + 60, $00] 'noteOff i = i + 1 if switch1 = 1 then gosub randomize endif if clock >= $FF then clock = 0 endif clock = clock + 1 goto main randomize: for i = 0 to 6 random temp sequence[i] = temp + clock; sequence[i] = sequence[i] // 12 if i > 0 then gosub checkSequence endif next i return 'this function assures that no pitch is repeated in the sequence j var byte checkSequence: for j = 0 to i - 1 if sequence[j] = sequence[i] then i = i-1 return endif next j return