IFDEF Example

MPASM Assembler

IFDEF Example

Directives highlighted in this example are:

  • #define
  • ifdef
  • else
  • endif
  • Program Functional Description

    This program uses the control directive #define, along with the ifdef, else and endif directives to seletively assemble code for use with either an emulator or an acutal part. The list directives title and list p= are used to set the title and processor and display this information in the list file. The control directive #include is used to include the standard header file for the selected device.

    Commented Code Listing

    title "PICmicro with Flash EE data memory Interface"

    list p=12ce518

    #include <p12ce518.inc>

    ;#define EMULATED

    .

    .

    .

    ; Emulation Requires:

    ; MPLAB-ICE

    ; PCM16XA0 processor module

    ; DVA12XP80 Device Adapter

    ; Define EMULATOR at the top of this file

    ; (#define EMULATOR)

    ; This will set the I2C_PORT, SDA and SCL lines

    ; to communicate over Port A, pins 0 and 1. It

    ; also assembles in the necessary TRIS

    ; instructions to allow reading from the SDA line.

    ;

    ; To convert the code for the actual part, simply comment

    ; out the #define EMULATOR line and reassemble.

    .

    .

    .

    #ifdef EMULATED

    I2C_PORT EQU 5 ; Port A control register,

    ; used for I2C

    SCL EQU 01H ; EEPROM Clock, SCL (I/O bit 7)

    SDA EQU 00H ; EEPROM Data, SDA (I/O bit 6)

    #else

    I2C_PORT EQU GPIO ; Port B control register,

    ; used for I2C

    SCL EQU 07H ; EEPROM Clock, SCL (I/O bit 7)

    SDA EQU 06H ; EEPROM Data, SDA (I/O bit 6)

    #endif

    .

    .

    .

    START_BIT

    BCF I2C_PORT,SDA ; Start bit, SDA and SCL

    ; preset to "1"


    Microchip Technology Inc.
    Microchip's Web Site
    Voice: (480) 792-7200
    Fax: (480) 899-9210
    Microchip's E-mail Address
    PreviousNext