#include "Vejlupek_CAR4_dsPIC33_ACU44_MainBoard_direct.h"
#include "Vejlupek_CAR4_dsPIC33_ACU44_MainBoard_direct_private.h"

volatile uint16_T SPI1Buffer_Receive[7];
volatile uint16_T SPI1Buffer_Send[7];
volatile uint16_T SPI1InterruptIdx;
void _ISR _SPI1Interrupt(void)         /* SPI ISR */
{
  _SPI1IF = 0;
  switch (SPI1InterruptIdx) {
   case 0:
    LATBbits.LATB9 = 1;
    asm ("nop");
    asm ("nop");
    asm ("nop");
    LATBbits.LATB9 = 0;
    SPI1Buffer_Receive[0] = SPI1BUF;
    _SPI1IF = 0;
    SPI1BUF = SPI1Buffer_Send[0];
    break;

   case 1:
    LATBbits.LATB9 = 1;
    asm ("nop");
    asm ("nop");
    asm ("nop");
    LATBbits.LATB9 = 0;
    SPI1Buffer_Receive[1] = SPI1BUF;
    _SPI1IF = 0;
    SPI1BUF = SPI1Buffer_Send[1];
    break;

   case 2:
    LATBbits.LATB9 = 1;
    asm ("nop");
    asm ("nop");
    asm ("nop");
    LATBbits.LATB9 = 0;
    SPI1Buffer_Receive[2] = SPI1BUF;
    _SPI1IF = 0;
    SPI1BUF = SPI1Buffer_Send[2];
    break;

   case 3:
    LATBbits.LATB9 = 1;
    asm ("nop");
    asm ("nop");
    asm ("nop");
    LATBbits.LATB9 = 0;
    SPI1Buffer_Receive[3] = SPI1BUF;
    _SPI1IF = 0;
    SPI1BUF = SPI1Buffer_Send[3];
    break;

   case 4:
    LATBbits.LATB9 = 1;
    asm ("nop");
    asm ("nop");
    asm ("nop");
    LATBbits.LATB9 = 0;
    SPI1Buffer_Receive[4] = SPI1BUF;
    _SPI1IF = 0;
    SPI1BUF = SPI1Buffer_Send[4];
    break;

   case 5:
    LATBbits.LATB9 = 1;
    asm ("nop");
    asm ("nop");
    asm ("nop");
    LATBbits.LATB9 = 0;
    SPI1Buffer_Receive[5] = SPI1BUF;
    _SPI1IF = 0;
    SPI1BUF = SPI1Buffer_Send[5];
    break;

   case 6:
    LATBbits.LATB9 = 1;
    asm ("nop");
    asm ("nop");
    asm ("nop");
    LATBbits.LATB9 = 0;
    SPI1Buffer_Receive[6] = SPI1BUF;
    _SPI1IF = 0;
    SPI1BUF = SPI1Buffer_Send[6];
    break;

   default:
    break;
  }                                    // end switch case

  SPI1InterruptIdx++;
  if (SPI1InterruptIdx > 6)
    SPI1InterruptIdx = 0;
}
