diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 50 |
1 files changed, 39 insertions, 11 deletions
@@ -14,8 +14,8 @@ // 'C' source line config statements // CONFIG1H -#pragma config FOSC = ECHPIO6 // Oscillator Selection bits (EC oscillator (high power, >16 MHz)) -#pragma config PLLCFG = OFF // 4X PLL Enable (Oscillator used directly) +#pragma config FOSC = INTIO7 // 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) #pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled) @@ -46,6 +46,8 @@ // CONFIG5L #pragma config CP0 = OFF // Code Protection Block 0 (Block 0 (000800-001FFFh) not code-protected) #pragma config CP1 = OFF // Code Protection Block 1 (Block 1 (002000-003FFFh) not code-protected) +#pragma config CP2 = OFF // Code Protection Block 2 (Block 2 (004000-005FFFh) not code-protected) +#pragma config CP3 = OFF // Code Protection Block 3 (Block 3 (006000-007FFFh) not code-protected) // CONFIG5H #pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected) @@ -54,6 +56,8 @@ // CONFIG6L #pragma config WRT0 = OFF // Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected) #pragma config WRT1 = OFF // Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected) +#pragma config WRT2 = OFF // Write Protection Block 2 (Block 2 (004000-005FFFh) not write-protected) +#pragma config WRT3 = OFF // Write Protection Block 3 (Block 3 (006000-007FFFh) not write-protected) // CONFIG6H #pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected) @@ -63,6 +67,8 @@ // CONFIG7L #pragma config EBTR0 = OFF // Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks) #pragma config EBTR1 = OFF // Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks) +#pragma config EBTR2 = OFF // Table Read Protection Block 2 (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks) +#pragma config EBTR3 = OFF // Table Read Protection Block 3 (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks) // CONFIG7H #pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks) @@ -70,6 +76,8 @@ // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. +#define _XTAL_FREQ 64000000 + #include "rs232.h" #include "midi.h" @@ -87,12 +95,8 @@ int eusart_write_midi(const midi_message_t *pkt) return -1; } - if (pkt->data == NULL) { - return -2; - } - length = pkt->data_size; - data = pkt->data; + data = (uint8_t *) pkt->data; putch((char)((pkt->status << 4) | pkt->channel)); @@ -105,13 +109,37 @@ int eusart_write_midi(const midi_message_t *pkt) /* main program */ -void main(void) { - +void main(void) +{ midi_message_t sample_message; - midi_note_on(&sample_message, 0x0, 0x3C, 0x7F); - eusart_init(); + /* PLL / FOSC configuration */ + // enable PLL + OSCTUNEbits.PLLEN = 1; + // set FOSC to HFINTOSC (max frequency) + OSCTUNEbits.TUN = 0b011111; + // set 16 MHz oscillator, datasheet p.30 + OSCCONbits.IRCF = 0b111; + // select primary clock (with PLL) + OSCCONbits.SCS = 0b00; + + /* i/o initializazion */ + // disable all ADCs + ANSELA = 0x00; + ANSELB = 0x00; + ANSELC = 0x00; + ANSELD = 0x00; + + + /* serial configuration */ + eusart1_init(); + /* demo code */ + midi_note_on(&sample_message, 0x0, 0x3C, 0x7F); + + TRISDbits.TRISD1 = 0; + PORTDbits.RD1 = 0; + /* main loop */ while (1) { eusart_write_midi(&sample_message); |