典型应用: #ifndef <标识> #define <标识> …… …… #endif #ifdef _XXXX …程序段1… #else …程序段2… #endif #ifdef NUM printf(“之前NUM定义过!:) \n”); #else printf(“之前NUM没有定义!:( \n”); #endif 示例,第二个 #if defined嵌套 #if defined(__dsPIC33FJ128GP804__) defined(__PIC24HJ128GP504__) AD1PCFGL = 0xFFFF; RPOR9bits.RP18R = 11; // assign RP18 for SCK2 RPOR8bits.RP16R = 10; // assign RP16 for SDO2 RPINR22bits.SDI2R = 17; // assign RP17 for SDI2 #elif defined(__PIC24FJ256GB110__) defined(__PIC24FJ256GA110__) defined (__PIC24FJ256GB210__) __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS RPOR10bits.RP21R = 11; // assign RP21 for SCK2 RPOR9bits.RP19R = 10; // assign RP19 for SDO2 RPINR22bits.SDI2R = 26; // assign RP26 for SDI2 __builtin_write_OSCCONL(OSCCON 0x40); // lock PPS #elif defined(__PIC24FJ256DA210__) __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS #if defined (USE_SST25_SPI2) RPOR1bits.RP2R = 11; // assign RP2 for SCK2 RPOR0bits.RP1R = 10; // assign RP1 for SDO2 RPINR22bits.SDI2R = 0; // assign RP0 for SDI2 #elif defined (USE_SST25_SPI1) RPOR1bits.RP2R = 8; // assign RP2 for SCK1 RPOR0bits.RP1R = 7; // assign RP1 for SDO1 RPINR20bits.SDI1R = 0; // assign RP0 for SDI1 #endif __builtin_write_OSCCONL(OSCCON 0x40); // lock PPS #endif
本文目录
本文目录