#include "dsPIC_main_22_4_2018.h"
#include "dsPIC_main_22_4_2018_private.h"

/* Implement SPI 1 Interrupts */
void __attribute__((__interrupt__,__auto_psv__)) _SPI1Interrupt(void) /* SPI1 ISR */
{
  _SPI1IF = 0;

  /* Declaration of Variables */
  uint16_T tmp;
  switch (MCHP_SPI1_State)
  {
   case 0:                             /* Idle */
    break;

   case 1:                             /* Start a new SPI Sequence */
    /* Delay */
    __delay32(70);                     /* Delay  */
    LATDbits.LATD11 = 1;               /* switch RD11 to 1 */

    /* Delay */
    __delay32(616);                    /* Delay  */
    LATDbits.LATD11 = 0;               /* switch RD11 to 0 */

    /* Delay */
    __delay32(70);                     /* Delay  */

    /* Read only Sequence */
    SPI1BUF = 0x00;

    /* Read only Sequence */
    SPI1BUF = 0x00;

    /* Delay */
    MCHP_SPI1_State++;
    break;

   case 2:
    __delay32(70);                     /* Delay  */
    SPI1_Buff8[0] = SPI1BUF;
    SPI1_Buff8[1] = SPI1BUF;
    MCHP_SPI1_State = 0;               /* End of SPI Sequence. SPI is available for a new sequence */
    break;

   default:                            /* Sequence finished */
    MCHP_SPI1_State = 0;               /* Should never happend */
    break;
  }                                    /* End of switch case sequence*/
}                                      /* Enf of interrupt */
