/* timer 2 interrupt service routine */
/* write next byte of data to MCP41010 on SPI1 */
void __attribute__((__interrupt__)) _T2Interrupt(void)
{
WriteTimer2(0); // reset timer counter to 0
IFS0bits.T2IF = 0; /* Clear Timer interrupt flag */
PORTDbits.RD8 = 1; // set EABLE high to execute last command
PORTDbits.RD8 = 0; // reset EABLE low to load next command
WriteSPI1(((WRITE+POT1)<< 8 ) + txSinx[txSinxIndex]); // write the data value
if (++txSinxIndex==TXDATA)txSinxIndex=0; // check array bounds - reset if required
}