summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index 9a53169..9b5fd28 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,7 +14,7 @@
// 'C' source line config statements
// CONFIG1H
-#pragma config FOSC = INTIO7 // Oscillator Selection bits (Internal oscillator block)
+#pragma config FOSC = INTIO67 // Oscillator Selection bits (Internal oscillator block)
#pragma config PLLCFG = ON // 4X PLL Enable (Oscillator multiplied by 4)
#pragma config PRICLKEN = ON // Primary clock enable bit (Primary clock is always enabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
@@ -26,7 +26,7 @@
#pragma config BORV = 190 // Brown Out Reset Voltage bits (VBOR set to 1.90 V nominal)
// CONFIG2H
-#pragma config WDTEN = ON // Watchdog Timer Enable bits (WDT is always enabled. SWDTEN bit has no effect)
+#pragma config WDTEN = OFF // Watchdog Timer Enable bits (WDT is always enabled. SWDTEN bit has no effect)
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
// CONFIG3H
@@ -93,13 +93,16 @@
#define NOTES 16
-#define MIDI_CHANNEL 0x0
-#define MIDI_SCALE_START 0x34 // note C3, C4 is 0x3C
-#define MIDI_NOTE_SPEED 0x0F // max is 0x7F
+// note: when selecting an instrument, subtract 1 (1 - 128 => 0 - 127)
+// see https://www.midi.org/specifications/item/gm-level-1-sound-set
+#define MIDI_INSTRUMENT 9
+// note: when selecting a channel, subtract 1 (1 - 128 => 0 - 127)
+#define MIDI_CHANNEL 0
+#define MIDI_NOTE_SPEED 127 // max is 0x7F
-#define DEBUG
+//#define DEBUG
/* global variables */
@@ -115,11 +118,14 @@ interrupt void isr(void)
{
unsigned char i, data_a, data_b;
+#ifdef DEBUG
PORTDbits.RD3 = 0;
+#endif
if (PIR1bits.TMR2IF) {
data_a = PORTA;
data_b = PORTB;
+
i = 7;
do {
// read the data and append it at the end of keys_data[i]
@@ -143,8 +149,10 @@ interrupt void isr(void)
// reset interrupt flag
PIR1bits.TMR2IF = 0;
}
-
+
+#ifdef DEBUG
PORTDbits.RD3 = 1;
+#endif
}
/* hardware configuration (inlined) */
@@ -216,7 +224,7 @@ inline void init_hw(void)
void main(void)
{
unsigned i;
- midi_message_t message;
+ midi_message_t conf_message, message;
/* setup hardware */
init_hw();
@@ -229,8 +237,17 @@ void main(void)
#ifdef DEBUG
PORTDbits.RD1 = 0;
#endif
+
+ /* midi device configuration */
+ conf_message.status = PROGRAM_CHANGE;
+ conf_message.channel = MIDI_CHANNEL;
+ conf_message.data[0] = MIDI_INSTRUMENT;
+ conf_message.data_size = 1;
+
+ midi_note_on(&message, MIDI_CHANNEL, midi_notes_steps_table[0], MIDI_NOTE_SPEED);
- midi_note_on(&message, MIDI_CHANNEL, MIDI_SCALE_START, MIDI_NOTE_SPEED);
+ __delay_ms(500);
+ eusart_write_midi(&conf_message);
/* main loop */
while (1) {
@@ -239,9 +256,9 @@ void main(void)
if (keypresses & (1<<i)) {
// dirty hack to avoid the slow call stack, correct version commented below
- message.data[0] = MIDI_SCALE_START + i;
- // midi_note_on(&message, MIDI_CHANNEL, MIDI_SCALE_START + i, 0x7F);
-
+ message.data[0] = midi_notes_steps_table[i];
+ //midi_note_on(&message, MIDI_CHANNEL, MIDI_SCALE_START + i, MIDI_NOTE_SPEED);
+
eusart_write_midi(&message);
// wait for the minimum note length