#include "Config.h"
unsigned short COMND, RAMP_SHAPE, LOP, FRQ_JMPN, SLP_CMP;
float FTHETA, DELTHETA;
volatile bit ACCDCC, ROT_DIR, REV, FRT_LOP, JMP_LOP, JMP_OC;
int* EXAM;
far unsigned int BUFF1A [4], BUFF1B[4], BUFF[2], BUFF2A[4], BUFF2B[4];
int* pv1;
unsigned int ReadWordArr[64];
unsigned int WriteWordArr[64];
void SPI4_INT() iv IVT_ADDR_SPI4INTERRUPT {
LATD=SPI4BUF; //
IFS7bits.SPI4IF=0;
}
void SPI4EER() iv IVT_ADDR_SPI4ERRINTERRUPT {
SPI4STATbits.SPIEN = 0; // Disable SPI module
SPI4STATbits.SPIROV=0; //Clear the Receive Overflow Flag
IFS7bits.SPI4EIF = 0; // Clear the SPI2 Error Interrupt Flag
SPI4STATbits.SPIEN = 1; // Enable SPI module
}
void CHNG() iv IVT_ADDR_CNINTERRUPT ics ICS_AUTO {
IFS1bits.CNIF = 0;
//LATD^=0xFFFF;
}
void main() {
IPC4=0x2000 |IPC4;
Osc_Config(140);
//////////////////////////////////////////////////////
ANSELB=0x0030;
TRISB=0x003C;
ANSELD= 0x0000;
TRISD = 0x0000;
ANSELG = 0x0000;
TRISG = 0x1000;
OSCCON=OSCCON & 0xFFDF; //Unlock I/O
RPINR31 = 0x227C; //RPI34=SCK, RPI124=SDI,
RPINR32= 0x0023; // RPI35=SS
RPOR15=0x0022; //RP126=SDO
OSCCON=OSCCON | 0x0020; //LOck I/O
CNENG.b12=1;
IFS1.b3=0;
IEC1.b3=1;
///////////////////////////////////////////////////////////////
SPI4BUF=0;
IFS7bits.SPI4EIF = 0; // Clear the Error Interrupt flag
IEC7bits.SPI4EIE = 0; // Enable the error interrupt
SPI4CON1=0x0500;
SPI4STATbits.SPIROV=0;
SPI4STAT=0x8000;
IFS7bits.SPI4EIF = 0;
IEC7bits.SPI4EIE = 1;
PMD3.b10=1;
////////////////////////////////////////////////////////////////
while (1) {
LATD=SPI4BUF;
Delay_us(10);
}}