Example #1
0
void gyroSetup(void) {

    // setup I2C port
    gyroSetupPeripheral();

    // external interrupt configuration.
    // it is NOT USED at this moment.
    ConfigINT1(RISING_EDGE_INT & EXT_INT_DISABLE & EXT_INT_PRI_3);

    dead_zone = DEFAULT_DEAD_ZONE;

    delay_ms(25);   // power up delay, may not need...
    gyroReset();
    delay_ms(10);
    //gyroWrite(REG_DLPF_FS, 0x1A);  // 2000 deg/sec, 1 kHz Sampling rate, 98Hz LPF
    gyroWrite(REG_DLPF_FS, 0x19);  // 2000 deg/sec, 1 kHz Sampling rate, 196Hz LPF
    gyroWrite(REG_INT_CFG, 0x00);  // interrupt disabled
    gyroWrite(REG_PWR_MGM, 0x03);  // Set power management?
    delay_ms(1);   // PLL Settling time

    is_ready = 1;

    delay_ms(6); //From datasheet, standard settling time
    gyroRunCalib(INITIAL_CALIB_NUM);  // quick calibration

}
Example #2
0
void gyroSetup(void) {
    
    // setup I2C port
    gyroSetupPeripheral();

    // external interrupt configuration. 
    // it is NOT USED at this moment.
    ConfigINT1(RISING_EDGE_INT & EXT_INT_DISABLE & EXT_INT_PRI_3); 

    delay_ms(25);   // power up delay, may not need...
    //gyroWrite(0x16, 0x1A);  // 2000 deg/sec, 1 kHz Sampling rate, 98Hz LPF
    gyroWrite(0x16, 0x19);  // 2000 deg/sec, 1 kHz Sampling rate, 196Hz LPF
    gyroWrite(0x17, 0x00);  // interrupt disabled
    gyroWrite(0x3e, 0x03);
    delay_ms(1);   // PLL Settling time

    gyroRunCalib(100);  // quick calibration. better to run this with > 1000.

}
Example #3
0
/**
 * Record a trace, this is a blocking function.
 * Use the ext interupt 0 and 1.
 * Use the timer 1.
 */
uchar* recordTrace(int *size) {
    uchar charIndex = 0;
    uchar charBuffer;

    uint state = STATE_BEGINING;

    uchar i = 0;
    uchar t0 = (uchar) 0x00;
    uint tmpEtu = NO_ETU_CHANGE;
    uchar protocol;
    uchar convention;

    convention = CONVENTION_DIRECTE;
    protocol = PROTOCOL_T0;

    initialiseInterupt();

    if(!waitForIO())
    {
        reInit();
        return NULL;
    }

    /* Configure the interupt on IO to answer on each falling edge*/
    ConfigINT2(EXT_INT_ENABLE | FALLING_EDGE_INT | EXT_INT_PRI_1);

    /* Configure the warm reset to trigger on falling edge*/
    ConfigINT1(EXT_INT_ENABLE | FALLING_EDGE_INT | EXT_INT_PRI_1);

    while( (STATE_TERMINATED != state))
    {
        state = getState();
        if( (isData() > 0) && dataIndex < DATA_SIZE)
        {
            charBuffer = 0x00;
            for(charIndex = 0 ; charIndex < 8 ; charIndex++ )
            {
                if(CONVENTION_INVERSE == convention)
                {
                    charBuffer ^= (getAcq() << (7-charIndex));
                }
                else if(CONVENTION_DIRECTE == convention)
                {
                    charBuffer ^= (getAcq() << charIndex);
                }
            }
            if(CONVENTION_INVERSE == convention)
            {
                charBuffer = 0xff ^ charBuffer;
            }
            dataArray[dataIndex] = charBuffer;

            dataIndex++;
            clearFlag();

            if(STATE_TS == state)
            {
                if((uchar) 0x3b == charBuffer)
                {
                    convention = CONVENTION_DIRECTE;
                }

                /* 0x03 is the way the byte 3f will be read with the tool
                 * For information, by default the Direct convention is used
                 * so we don't see directly the byte 3F but the byte 3f coded
                 * in direct convention = 0x03 */
                if((uchar) 0x03 == charBuffer)
                {
                    convention = CONVENTION_INVERSE;
                    dataArray[dataIndex-1] = 0x3f;
                }

                setState(STATE_T0);
            }
            else if(STATE_T0 == state)
            {
                t0 = charBuffer;
                setState(STATE_ATR);
            } /*Then we treats TAx, TBx, TCx, TDx,... and finaly hist bytes */
            else if(0 < (t0 & 0x10) )
            {
                t0 = t0 ^ 0x10;
                /* It's a TAx */
                if(0 == i) /* It's Ta1*/
                {
                    /*Configuring the new ATR value*/
                    tmpEtu = computeEtu(charBuffer);
                }
            }
            else if(0 < (t0 & 0x20) )
            {
                /*It's a TBx*/
                t0 = t0 ^ 0x20;
            }
            else if(0 < (t0 & 0x40) )
            {
                /*It's a TCx*/
                t0 = t0 ^ 0x40;
            }
            else if(0 < (t0 & 0x80) )
            {
                /*It's a TDx*/
                t0 = t0 ^ 0x80;
                /* t0 is only compose of the historical bytes We verify if
                 the TD bytes implies other bytes*/
                t0 ^= (charBuffer & 0xf0);
                i++;

                /* We also verify if it's a T=1 protocol */
                if( ((uchar) 0x01) == ((uchar) charBuffer ^ 0x01) )
                {
                    /*It's a t=1 card set the value to T=1*/
                    protocol = PROTOCOL_T1;
                }

            }
            else if(0 < (t0 & 0x0F))
            {
                /* This is historical bytes */
                t0--;
                if(t0 == 0)
                {
                    if(PROTOCOL_T1 == protocol)
                    {
                        setState(STATE_ATR_CRC);
                    }
                    else
                    {
                        setState(STATE_PROCESSING);
                        fixEtu(tmpEtu);
                    }
                }
            }
            else if(STATE_ATR_CRC == state) {
                setState(STATE_PROCESSING);
                fixEtu(tmpEtu);
            }
        }/*end of if(isData() > 0 )*/
        else if(STATE_RESET == getState()) {
            charIndex = 0;
            convention = CONVENTION_DIRECTE;
            warmAtrOffset = dataIndex;
            t0 = 0x00;
            setState(STATE_BEGINING);
        }
        if( !isData() && !PIN_VCC )
        {
            setState(STATE_TERMINATED);
        }
        if(dataIndex >= DATA_SIZE )
        {
#ifdef DEBUG
            sendDataBuffer("Array overflow\n");
#endif
            setState(STATE_TERMINATED);
        }
    }//End of while

    /* Stop the interupt on IO */
    ConfigINT0(EXT_INT_DISABLE);

    /* Stop the warm reset */
    ConfigINT1(EXT_INT_DISABLE);

#ifdef DEBUG
    sendDataBuffer("Trace recorded : \n");
#endif

    /* End of debug information */
    *size = dataIndex;
    reInit();
    return dataArray;
}
Example #4
0
void ClearExternalIO(void) {
	int i;

//	GS I2C Start
	i2c_disable();
	i2c_slave_disable();
//	GS I2C End

	if (SerialConsole != 1) SerialClose(1);
	if (SerialConsole != 2) SerialClose(2);
	if (SerialConsole != 3) SerialClose(3);
	if (SerialConsole != 4) SerialClose(4);

	// stop the sound
	SoundPlay = 0;
	CloseTimer2();
#ifdef OLIMEX
	CloseOC1();
#else
	CloseOC2();
#endif
	inttbl[NBRPINS + 2].intp = NULL;					// disable the tick interrupt
	for (i = 1; i < NBRPINS + 1; i++) {
		inttbl[i].intp = NULL;						// disable all interrupts
#ifdef OLIMEX
    #ifdef  OLIMEX_DUINOMITE_EMEGA
		if (ExtCurrentConfig[i] != EXT_CONSOLE_RESERVED && i != 35 ) {	// don't reset the serial console
    #else
		if (ExtCurrentConfig[i] != EXT_CONSOLE_RESERVED && i != 21 ) {	// don't reset the serial console
    #endif
#else
		if (ExtCurrentConfig[i] != EXT_CONSOLE_RESERVED) {              // don't reset the serial console
#endif
			ExtCfg(i, EXT_NOT_CONFIG);                              // all set to unconfigured
			ExtSet(i, 0);						// all outputs (when set) default to low
		}
	}
        InterruptReturn = NULL;
}


/****************************************************************************************************************************
Initialise the I/O pins
*****************************************************************************************************************************/
void initExtIO(void) {
	int i;

	for (i = 1; i < NBRPINS + 1; i++) {
		ExtCfg(i, EXT_NOT_CONFIG);                                      // all set to unconfigured
		ExtSet(i, 0);							// all outputs (when set) default to low
	}
#ifndef OLIMEX
 	CNCONbits.ON = 1;       						// turn on Change Notification module
 	CNPUEbits.CNPUE1 = 1;							// turn on the pullup for pin C13 also called CN1
#endif
	ExtCurrentConfig[0] = EXT_DIG_IN;                                       // and show that we can read from it
	P_LED_TRIS = P_OUTPUT; 							// make the LED pin an output
	ExtSet(0, 0);								// and turn it off
#ifdef OLIMEX
    #ifdef OLIMEX_DUINOMITE_EMEGA
	ExtCurrentConfig[35] = EXT_ANA_IN;
    #else
	ExtCurrentConfig[21] = EXT_ANA_IN;
    #endif
#endif

	// setup the analog (ADC) function
	AD1CON1 = 0x00E0;       						// automatic conversion after sampling
 	AD1CSSL = 0;       							// no scanning required
	AD1CON2 = 0;       							// use MUXA, use AVdd   &   AVss as Vref+/-
	AD1CON3 = 0x203; //0x1F3F;  							// Tsamp = 32 x Tad;
	AD1CON1bits.ADON = 1; 							// turn on the ADC

}


/****************************************************************************************************************************
Configure an I/O pin
Returns true if all is OK
*****************************************************************************************************************************/
int ExtCfg(int pin, int cfg) {
	int tris, ana, oc;

	if (pin < 0 || pin > NBRPINS) return false;						// initial sanity check

	// make sure that interrupts are disabled in case we are changing from an interrupt input
#ifdef OLIMEX
//	if (pin == 5) ConfigINT2(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_DISABLE);
//	if (pin == 6) ConfigINT3(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_DISABLE);
        #ifdef  OLIMEX_DUINOMITE_EMEGA
        #else
                if (pin == 7) ConfigINT4(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_DISABLE);
        #endif
#else
	if (pin == 11) ConfigINT1(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_DISABLE);
	if (pin == 12) ConfigINT2(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_DISABLE);
	if (pin == 13) ConfigINT3(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_DISABLE);
	if (pin == 14) ConfigINT4(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_DISABLE);
#endif

	inttbl[pin].intp = NULL;		// also disable a software interrupt on this pin

	switch (cfg) {
		case EXT_NOT_CONFIG:
//	#ifdef OLIMEX
//			if (pin == 5) {P_E5_TRIS = 1; P_E5_OC = 1;}
//			if (pin == 6) {P_E6_TRIS = 1; P_E6_OC = 1;}
//			if (pin == 11) {P_E11_TRIS = 1; P_E11_OC = 1;}
//			if (pin == 12) {P_E12_TRIS = 1; P_E12_OC = 1;}
//	#endif
			tris = 1; ana = 1; oc = 1;
			break;

		case EXT_ANA_IN:
//	#ifdef OLIMEX
			if (pin > 6 && pin < 19) return false;
//			if (pin == 5) {P_E5_TRIS = 1; P_E5_OC = 1;}
//			if (pin == 6) {P_E6_TRIS = 1; P_E6_OC = 1;}
//	#else
//			if (pin > 10) return false;
//	#endif
			tris = 1; ana = 0; oc = 1;
			break;

		case EXT_FREQ_IN:											// same as counting, so fall through
		case EXT_PER_IN:											// same as counting, so fall through
		case EXT_CNT_IN:
//	#ifdef OLIMEX
//	#else
//			if (pin == 11) {
//				INT1Count = INT1Value = 0;
//				ConfigINT1(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_ENABLE);
//				tris = 1; ana = 1; oc = 1;
//				break;
//			}
//	#endif
//	#ifdef OLIMEX
//			if (pin == 5) {
//				P_E5_TRIS = 1;
//				P_E5_OC = 1;
//	#else
//			if (pin == 12) {
//	#endif
//				INT2Count = INT2Value = 0;
//				ConfigINT2(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_ENABLE);
//				tris = 1; ana = 1; oc = 1;
//				break;
//			}
//	#ifdef OLIMEX
//			if (pin == 6) {
//				P_E6_TRIS = 1;
//				P_E6_OC = 1;
//	#else
//			if (pin == 13) {
//	#endif
//				INT3Count = INT3Value = 0;
//				ConfigINT3(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_ENABLE);
//				tris = 1; ana = 1; oc = 1;
//				break;
//			}
#ifdef  OLIMEX_DUINOMITE_EMEGA
                    break;
#else
	#ifdef OLIMEX
			if (pin == 7) {
	#else
			if (pin == 14) {
	#endif
				INT4Count = INT4Value = 0;
				ConfigINT4(EXT_INT_PRI_2 | RISING_EDGE_INT | EXT_INT_ENABLE);
				tris = 1; ana = 1; oc = 1;
				break;
			}
			return false;							// not an interrupt enabled pin
#endif

		case EXT_INT_LO:											// same as digital input, so fall through
		case EXT_INT_HI:											// same as digital input, so fall through
		case EXT_DIG_IN:
	#ifdef OLIMEX
//                        if (pin == 5) {P_E5_TRIS = 1; P_E5_OC = 1;}
//			if (pin == 6) {P_E6_TRIS = 1; P_E6_OC = 1;}
//			if (pin == 11) {P_E11_TRIS = 1; P_E11_OC = 1;}
//			if (pin == 12) {P_E12_TRIS = 1; P_E12_OC = 1;}
	#endif
			tris = 1; ana = 1; oc = 1;
			break;

		case EXT_DIG_OUT:
	#ifdef OLIMEX
//			if (pin == 11) {P_E11_TRIS = 1; P_E11_OC = 1;} //return false;
//			if (pin == 5) {P_E5_TRIS = 1; P_E5_OC = 1;}
//			if (pin == 6) {P_E6_TRIS = 1; P_E6_OC = 1;}
//			if (pin == 12) {P_E12_TRIS = 1; P_E12_OC = 1;}
	#endif
			tris = 0; ana = 1; oc = 0;
			break;

		case EXT_OC_OUT:
	#ifdef OLIMEX
//			if (pin == 11) {P_E11_TRIS = 1; P_E11_OC = 1;} //return false;
//			if (pin == 5) {P_E5_TRIS = 1; P_E5_OC = 1;}
//			if (pin == 6) {P_E6_TRIS = 1; P_E6_OC = 1;}
//			if (pin == 12) {P_E12_TRIS = 1; P_E12_OC = 1;}
	#else
			if (pin < 11) return false;
	#endif
			tris = 0; ana = 1; oc = 1;
			break;

		case EXT_COM_RESERVED:
		case EXT_CONSOLE_RESERVED:
			ExtCurrentConfig[pin] = cfg;		// don't do anything except set the config type
		#ifdef OLIMEX
//			if (pin == 5) {P_E5_TRIS = 1; P_E5_OC = 1; P_E5_ANALOG = 1;}
//			if (pin == 6) {P_E6_TRIS = 1; P_E6_OC = 1; P_E6_ANALOG = 1;}
//			if (pin == 11) {P_E11_TRIS = 1; P_E11_OC = 1;}
//			if (pin == 12) {P_E12_TRIS = 1; P_E12_OC = 1;}
		#endif
			return true;

		default:
			return false;
	}

	ExtCurrentConfig[pin] = cfg;

	// set the TRIS and analog characteristics
	switch (pin) {
		case 1:  P_E1_TRIS = tris;   P_E1_OC = oc;   P_E1_ANALOG = ana;		break;
		case 2:  P_E2_TRIS = tris;   P_E2_OC = oc;   P_E2_ANALOG = ana;		break;
		case 3:  P_E3_TRIS = tris;   P_E3_OC = oc;   P_E3_ANALOG = ana;		break;
		case 4:  P_E4_TRIS = tris;   P_E4_OC = oc;   P_E4_ANALOG = ana;		break;
		case 5:  P_E5_TRIS = tris;   P_E5_OC = oc;   P_E5_ANALOG = ana;		break;
		case 6:  P_E6_TRIS = tris;   P_E6_OC = oc;   P_E6_ANALOG = ana;		break;
	#ifdef OLIMEX
            #ifdef  OLIMEX_DUINOMITE_EMEGA
		case 7:  P_E7_TRIS = tris;   P_E7_OC = oc;   P_E7_ANALOG = ana;		break;
		case 8:  P_E8_TRIS = tris;   P_E8_OC = oc;   break;
		case 9:  P_E9_TRIS = tris;   P_E9_OC = oc;   break;
		case 10: P_E10_TRIS = tris;  P_E10_OC = oc;  break;
            #else
		case 7:  P_E7_TRIS = tris;   P_E7_OC = oc;	              break;
 		case 8:  if (!S.SDEnable) { P_E8_TRIS = tris; P_E8_OC = oc;}  break;
		case 9:  if (!S.SDEnable) { P_E9_TRIS = tris; P_E9_OC = oc;}  break;
		case 10: if (!S.SDEnable) { P_E10_TRIS = tris; P_E10_OC = oc;} break;
            #endif
	#else
		case 7:  P_E7_TRIS = tris;   P_E7_OC = oc;   P_E7_ANALOG = ana;		break;
		case 8:  P_E8_TRIS = tris;   P_E8_OC = oc;   P_E8_ANALOG = ana;		break;
		case 9:  P_E9_TRIS = tris;   P_E9_OC = oc;   P_E9_ANALOG = ana;		break;
		case 10: P_E10_TRIS = tris;  P_E10_OC = oc;  P_E10_ANALOG = ana;	break;
	#endif
		case 11: P_E11_TRIS = tris;  P_E11_OC = oc;			break;
		case 12: P_E12_TRIS = tris;  P_E12_OC = oc;			break;
		case 13: P_E13_TRIS = tris;  P_E13_OC = oc;			break;
		case 14: P_E14_TRIS = tris;  P_E14_OC = oc;			break;
		case 15: P_E15_TRIS = tris;  P_E15_OC = oc;			break;
		case 16: P_E16_TRIS = tris;  P_E16_OC = oc;			break;
		case 17: P_E17_TRIS = tris;  P_E17_OC = oc;			break;
		case 18: P_E18_TRIS = tris;  P_E18_OC = oc;			break;
	#ifdef OLIMEX
            // SPP +
            #ifdef	OLIMEX_DUINOMITE_EMEGA		// edit for DuinoMite eMega
		case 19: P_E19_TRIS = tris;  P_E19_OC = oc;			break;
		case 20: P_E20_TRIS = tris;  P_E20_OC = oc;                     break;
                case 21: P_E21_TRIS = tris;  P_E21_OC = oc;			break;
		case 22: P_E22_TRIS = tris;  P_E22_OC = oc;			break;
		case 23: P_E23_TRIS = tris;  P_E23_OC = oc;			break;
		case 24: P_E24_TRIS = tris;  P_E24_OC = oc;			break;
		case 25: P_E25_TRIS = tris;  P_E25_OC = oc;			break;
		case 26: P_E26_TRIS = tris;  P_E26_OC = oc;			break;
		case 27: P_E27_TRIS = tris;  P_E27_OC = oc;			break;
		case 28: P_E28_TRIS = tris;  P_E28_OC = oc;			break;
		case 29: P_E29_TRIS = tris;  P_E29_OC = oc;			break;
		case 30: P_E30_TRIS = tris;  P_E30_OC = oc;			break;
		case 31: P_E31_TRIS = tris;  P_E31_OC = oc; P_E31_ANALOG = ana;	break;
		case 32: P_E32_TRIS = tris;  P_E32_OC = oc; P_E31_ANALOG = ana;	break;
		case 33: P_E33_TRIS = tris;  P_E33_OC = oc;			break;
		case 34: P_E34_TRIS = tris;  P_E34_OC = oc;			break;
		case 35: P_E35_TRIS = tris;  P_E35_OC = oc; P_E31_ANALOG = ana; break;
		case 36: P_E36_TRIS = tris;  P_E36_OC = oc;			break;
		case 37: P_E37_TRIS = tris;  P_E37_OC = oc;			break;
		case 38: P_E38_TRIS = tris;  P_E38_OC = oc;			break;
		case 39: P_E39_TRIS = tris;  P_E39_OC = oc;			break;
            #else	// original by Geoff Graham for DuinoMite Mega
		case 19: //if (!S.VideoMode) {
                    P_E19_TRIS = tris; P_E19_OC = oc; P_E19_ANALOG = ana;//}
                break;
		case 20: if (!S.VideoMode || P_VGA_COMP) {P_E20_TRIS = tris; P_E20_OC = oc; P_E20_ANALOG = ana;} break;
		case 21: P_E21_TRIS = tris;  P_E21_OC = oc;  P_E21_ANALOG = ana;		break;
                case 22: P_E22_TRIS = tris;  P_E22_OC = oc; break;
                case 23: P_E23_TRIS = tris;  P_E23_OC = oc; break;
            #endif
            // SPP -
	#else
		case 19: P_E19_TRIS = tris;  P_E19_OC = oc;			break;
		case 20: P_E20_TRIS = tris;  P_E20_OC = oc;			break;
	#endif
	#ifdef UBW32
                case 21: P_E21_TRIS = tris;  P_E21_OC = oc;			break;
		case 22: P_E22_TRIS = tris;  P_E22_OC = oc;			break;
		case 23: P_E23_TRIS = tris;  P_E23_OC = oc;			break;
		case 24: P_E24_TRIS = tris;  P_E24_OC = oc;			break;
		case 25: P_E25_TRIS = tris;  P_E25_OC = oc;			break;
		case 26: P_E26_TRIS = tris;  P_E26_OC = oc;			break;
		case 27: P_E27_TRIS = tris;  P_E27_OC = oc;			break;
		case 28: P_E28_TRIS = tris;  P_E28_OC = oc;			break;
		case 29: P_E29_TRIS = tris;  P_E29_OC = oc;			break;
		case 30: P_E30_TRIS = tris;  P_E30_OC = oc;			break;
		case 31: P_E31_TRIS = tris;  P_E31_OC = oc;			break;
		case 32: P_E32_TRIS = tris;  P_E32_OC = oc;			break;
		case 33: P_E33_TRIS = tris;  P_E33_OC = oc;			break;
		case 34: P_E34_TRIS = tris;  P_E34_OC = oc;			break;
		case 35: P_E35_TRIS = tris;  P_E35_OC = oc;			break;
		case 36: P_E36_TRIS = tris;  P_E36_OC = oc;			break;
		case 37: P_E37_TRIS = tris;  P_E37_OC = oc;			break;
		case 38: P_E38_TRIS = tris;  P_E38_OC = oc;			break;
		case 39: P_E39_TRIS = tris;  P_E39_OC = oc;			break;
		case 40: P_E40_TRIS = tris;  P_E40_OC = oc;			break;
		case 41: P_E41_TRIS = tris;  P_E41_OC = oc;			break;
		case 42: P_E42_TRIS = tris;  P_E42_OC = oc;			break;
		case 43: P_E43_TRIS = tris;  P_E43_OC = oc;			break;
		case 44: P_E44_TRIS = tris;  P_E44_OC = oc;			break;
		case 45: P_E45_TRIS = tris;  P_E45_OC = oc;			break;
		case 46: P_E46_TRIS = tris;  P_E46_OC = oc;			break;
		case 47: P_E47_TRIS = tris;  P_E47_OC = oc;			break;
		case 48: P_E48_TRIS = tris;  P_E48_OC = oc;			break;
		case 49: P_E49_TRIS = tris;  P_E49_OC = oc;			break;
		case 50: P_E50_TRIS = tris;  P_E50_OC = oc;			break;
	#endif
	}

	if (cfg == EXT_NOT_CONFIG) ExtSet(pin, 0);						// set the default output to low
	return true;
}


/****************************************************************************************************************************
Set the output of a digital I/O pin
Returns true if all is OK
*****************************************************************************************************************************/
int ExtSet(int pin, int val){
	val = (val != 0);							// non zero is on
	INTDisableInterrupts();				// setting an output bit is NOT atomic and a bit set operation
																// in an interrupt could result in this set corrupting the output
	switch (pin) {
	#ifdef UBW32
		case 0:  P_LED_OUT = !val;  break;		// this is the LED - the UBW32 wired them upside down !!
	#else
		case 0:  P_LED_OUT = val;  break;			// this is the LED
	#endif
		case 1:  P_E1_OUT = val;   break;
		case 2:  P_E2_OUT = val;   break;
		case 3:  P_E3_OUT = val;   break;
		case 4:	 P_E4_OUT = val;   break;
		case 5:	 P_E5_OUT = val;   break;
		case 6:	 P_E6_OUT = val;   break;
		case 7:	 P_E7_OUT = val;   break;
	#ifdef OLIMEX
            #ifdef  OLIMEX_DUINOMITE_EMEGA
		case 8:	 P_E8_OUT = val;   break;
		case 9:	 P_E9_OUT = val;   break;
		case 10: P_E10_OUT = val;  break;
            #else
		case 8:	 if (!S.SDEnable) P_E8_OUT = val;   break;
		case 9:	 if (!S.SDEnable) P_E9_OUT = val;   break;
		case 10: if (!S.SDEnable) P_E10_OUT = val;  break;
            #endif
	#else
		case 8:	 P_E8_OUT = val;   break;
		case 9:	 P_E9_OUT = val;   break;
		case 10: P_E10_OUT = val;  break;
	#endif
		case 11: P_E11_OUT = val;  break;
		case 12: P_E12_OUT = val;  break;
		case 13: P_E13_OUT = val;  break;
		case 14: P_E14_OUT = val;  break;
		case 15: P_E15_OUT = val;  break;
		case 16: P_E16_OUT = val;  break;
		case 17: P_E17_OUT = val;  break;
		case 18: P_E18_OUT = val;  break;
	#ifdef OLIMEX
            #ifdef  OLIMEX_DUINOMITE_EMEGA
                case 19: P_E19_OUT = val; break;
                case 20: P_E20_OUT = val; break;
            #else
		case 19: P_E19_OUT = val;  break;
		case 20: if (!S.VideoMode || P_VGA_COMP) P_E20_OUT = val;  break;
                case 22: P_E22_OUT = val ; break;
                case 23: P_E23_OUT = val ; break;
            #endif
        #else
		case 19: P_E19_OUT = val;  break;
		case 20: P_E20_OUT = val;  break;
	#endif
        #if defined UBW32 || defined OLIMEX_DUINOMITE_EMEGA
		case 21: P_E21_OUT = val;	break;
		case 22: P_E22_OUT = val;	break;
		case 23: P_E23_OUT = val;	break;
		case 24: P_E24_OUT = val;	break;
		case 25: P_E25_OUT = val;	break;
		case 26: P_E26_OUT = val;	break;
		case 27: P_E27_OUT = val;	break;
		case 28: P_E28_OUT = val;	break;
		case 29: P_E29_OUT = val;	break;
		case 30: P_E30_OUT = val;	break;
		case 31: P_E31_OUT = val;	break;
		case 32: P_E32_OUT = val;	break;
		case 33: P_E33_OUT = val;	break;
		case 34: P_E34_OUT = val;	break;
		case 35: P_E35_OUT = val;	break;
		case 36: P_E36_OUT = val;	break;
		case 37: P_E37_OUT = val;	break;
		case 38: P_E38_OUT = val;	break;
		case 39: P_E39_OUT = val;	break;
        #endif
        #ifdef UBW32
		case 40: P_E40_OUT = val;	break;
		case 41: P_E41_OUT = val;	break;
		case 42: P_E42_OUT = val;	break;
		case 43: P_E43_OUT = val;	break;
		case 44: P_E44_OUT = val;	break;
		case 45: P_E45_OUT = val;	break;
		case 46: P_E46_OUT = val;	break;
		case 47: P_E47_OUT = val;	break;
		case 48: P_E48_OUT = val;	break;
		case 49: P_E49_OUT = val;	break;
		case 50: P_E50_OUT = val;	break;
	#endif
		default:
			INTEnableInterrupts();
			return false;
	}
	INTEnableInterrupts();
	return true;
}