Esempio n. 1
0
void setup_spi() {
    // TODO move it out of here
    INTDisableInterrupts();
    mCNOpen(CN_ON | CN_IDLE_CON, CN1_ENABLE, CN1_PULLUP_ENABLE);
    mPORTCRead();
    mCNSetIntPriority(6); // same as below
    mCNClearIntFlag();
    mCNIntEnable(1);
    INTEnableInterrupts();
}
/************ PROCEDURES ********************/
void step (unsigned char data, unsigned char motorNumber) {
	data = data & 0x0F; // make sure only the LS-nibble will be overwritten
	unsigned int lectura;

	switch (motorNumber) {
		case 1:
			lectura = mPORTDRead() & (~(0xF << 4));
			mPORTDWrite(lectura | (data << 4));
			break;
		case 2:
			lectura = mPORTCRead() & (~(0xF << 1));
			mPORTCWrite(lectura | (data << 1));
			break;
		case 3:
		case 4:
			motorNumber -= 3;
			lectura = mPORTERead() & (~(0xF << motorNumber*4));
			mPORTEWrite(lectura | (data << motorNumber*4));
			break;
	}
}
Esempio n. 3
0
// Initialize LEDs on G12 and G13 as output and the switch on G6 as input
// G6 has an internal pullup resistor enabled by the bootloader
void initLEDs(void) {
  TRISBCLR = 0xDFFF;
  LATBCLR = 0xDFFF;
  TRISCCLR = 0x2000;
  LATCCLR = 0x2000;
  TRISDCLR = 0x09F0;
  LATDCLR = 0x09F0;
  TRISECLR = 0x0DFF;
  LATDCLR = 0x0DFF;
  TRISFCLR = 0x000B;
  LATFCLR = 0x000B;
  TRISGCLR = 0x038C;
  LATGCLR = 0x038C;
  TRISDCLR = 0x000F;
  
  TRISBCLR = 0x2000; 
  TRISGSET = 0x0040;
  AD1PCFG=0xFFFF;
  TRISCSET = 0x4000;
  mPORTCRead();
}
void __ISR(_EXTERNAL_2_VECTOR, ipl1) _Interrupt_XY_Limit(void)
{
    unsigned int temp;

    temp = mPORTCRead();
    
    if(temp & xLimitInput.pin)
    {
        xLimitDetected = TRUE;
        BSP_AxisDisable(X_AXIS);
        //BSP_Timer2Stop();
    }
    if(temp & yLimitInput.pin)
    {
        yLimitDetected = TRUE;
        BSP_AxisDisable(Y_AXIS);
        //BSP_Timer2Stop();
    }

    /* Clear the interrupt flag */
    mINT2ClearIntFlag();


}