MIDI Lab
MIDI or Musical Instrument Digital Interface is a protocol developed for communication between digital synthesizers and other digital music devices.
For this lab I used a sythesizer which was connected to my microcontroller. The program takes a value from an analog sensor and uses it ro generate the pitch of a note played once every quarter of a second.
‘ the sensor is on pin RA0 The MIDI is on pin RC6
‘ Make sure to select Configuration, Oscillator, HS
‘ in EPICWIN when programming:
DEFINE OSC 20
DEFINE ADC_BIT 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 15
‘ set up serial UART registers:
define HSER_RCSTA 90h
define HSER_TXSTA 20h
define HSER_BAUD 31250
TRISA = %11111111
‘ set up ADCON1
ADCON1 = %10000010
‘ declare an array of 12 word variables:
pitch var byte (12)
‘ declare other variables:
note var byte
ADCVar var word
‘ the 12 elements of the array called pitch are the 12 notes of a scale:
pitch (0) = 60 ‘ middle C
pitch (1) = 61 ‘ C#
pitch (2) = 62 ‘ D
pitch (3) = 63 ‘ D#
pitch (4) = 64 ‘ E
pitch (5) = 65 ‘ F
pitch (6) = 66 ‘ F#
pitch (7) = 67 ‘ G
pitch (8) = 68 ‘ G#
pitch (9) = 69 ‘ A
pitch (10) = 70 ‘ A#
pitch (11) = 71 ‘ B
main:
‘My potentiometer gave a range from 0 to 1023
ADCin 0. ADCVar
‘ connect to a range from 0 to 11:
Note = ADCVAR / 100
‘ play note:
hserout [$90. pitch(note), $40]
pause 250
‘ noteoff:
hserout [$80, pitch(note), $00]
goto main
