MPASM source file (for PIC 10, 12, 16, 17, and 18). Default output file name is <name>.asm.
MPASM include file. Default output filename is <name>.inc.
ASM30 source file (for the 16 bit PICs like the 24, 30, and 33). Default output file name is <name>.S.
ASM30 include file. Default output file name is <name>.inc.
The command line options are:
The first command line option that does not start with a dash (-) will be taken as the input file name if no input file name was previously set. A input file name is mandatory.
The file name suffixes may be omitted on the command line. In that case file names with each of the valid suffixes ".ins.aspic", ".aspic", ".ins.dspic", and ".dspic" will be tried in that order. The first file found will be used.
Explicitly set the input file name. This is the only way to indicate an input file name that starts with a dash (-).
The first command line argument that does not start with a dash after the input file name is specified, but no output file name has yet been specified, will be taken as the output file name. The default output file name for each input file type is listed above.
Explicitly set the output file name. This is the only way to indicate an output file name that starts with a dash (-).
Create a BOOL variable of name NAME and set it to TRUE before the input file is processed.
Create a BOOL variable of name NAME and set it to FALSE before the input file is processed.
Create a INTEGER variable of name NAME and set it to VAL before the input file is processed.
Create a REAL (floating point) variable of name NAME and set it to VAL before the input file is processed.
Create a STRING variable of name NAME and set it to VAL before the input file is processed. VAL must be enclosed in quotes ("") or apostrophies ('') if it contains any spaces.
The PREPIC program is based on the Embed Scripting System used in pre-processor mode. All of the functions of the ESCR system are available, plus a few custom features added by PREPIC.
Specifically, the customizations to the ESCR system are:
The PREPIC data types are the same as the ESCR data types.
Declares an I/O pin as a digital input.
Name is the private name being defined for the I/O pin, and will be used to generate unique assembler symbols associated with this pin, shown below.
Port is the name of the I/O port containing the input bit. It must be of the form PORT followed by a single letter indicating the particular port. The port argument is case-insensitive. Examples are PORTA, PortB, and portc. Some processors have a single I/O port called GPIO. The GPIO port must be referred to as PORTA.
Bit is the bit number within the port register. It must be 0-7 on 8 bit PICs (PIC 12, 16, 17, 18) and 0-15 on 16 bit PICs (PIC 24, 30, 33).
Pup is an optional keyword indicating that the internal passive pullup should be initially enabled for this I/O pin. An error will be generated when the standard PORT module is assembled if the requested combination of passive pullups requested by all INBIT commands is not attainable on this specific processor.
This command only creates or modifies preprocessor and assembler state. It generates no executable code. It is assumed that the assembler state has been properly initialized prior to this INBIT command, as is done if the standard include files STD_DEF.INS.ASPIC and STD.INS.ASPIC (or STD_DEF.INS.DSPIC and STD.INS.DSPIC) are used as directed. The actual runtime initialization code that uses the assembler state is in the PORT_INIT subroutine in the standard PORT module.
Assembler constant equal to the address of the PORTx register containing the direct I/O pin value.
Assembler constant equal to the address of TRISx register controlling the I/O pin in/out direction.
Assembler constant equal to the address of LATx register containing the output latch bit for this I/O pin. This constant is only defined if the machine has a port latch register. For example, the original 16 family PICs do not have these, although 18 and 30 family PICs do.
Assembler constant equal to the bit number for this I/O pin within the PORTx, TRISx, and other possible port-specific registers.
String substitution macro that expands to the port register followed by the bit number within that register for this I/O pin. The string substitution macro is defined:
#define name_pin PortRegister, bit
This string substitution macro can be used to supply both arguments to bit manipulation instructions as shown in the example below.
NOTE: This string substitution macro is not implemented for dsPIC processors.
String substitution macro that expands to the latch register followed by the bit number within that register for this I/O pin. This is like the name_pin macro (above), except that it refers to the bit in the latch instead of the port register. This macro is only defined when the latch register exists.
NOTE: This string substitution macro is not implemented for dsPIC processors.
Assembler variable containing the initial value for the TRISx register (where X is the port name, like A) controlling the direction of this I/O bit. The bit for this I/O pin will be set, which will cause the pin to be initialized as an input by the standard PORT_INIT subroutine.
Assembler variable indicating the desired initial state of the passive pullups for the port containing the I/O bit. The X in the variable name is the port name, like B or C, for example. A bit in this variable is set to indicate the associated passive pullup is to be initially enabled. Illegal requests for passive pullups will generate an error message when the standard PORT module is assembled.
Assembler variable indicating which pins of port X are analog. 1 bits indicates analog, 0 digital.
Each of these assembler variables contains 32 bits indicating used analog channels. ANALOGUSED0 contains the bits for AN0 to AN31, and ANALOGUSED1 for AN32 to AN63. Within each variable, the analog channel numbers correspond to bits in least to most significant order.
For example, ANALOGUSED1 of 5 indicates that analog channels AN32 and AN34 are used, and that AN33 and AN35-AN63 are unused.
/inbit button portb 3 pup ;low when user button is pressed
btfsc button_pin ;is the button pressed ? goto done_button ;no, done handling user button ; ; The user button is pressed. ; ... done_button unbank ;done handling the user button
btsc button_reg, #button_bit ;is the button pressed ? bra done_button ;no, done handling user button ; ; The user button is pressed. ; ... done_button: ;done handling the user button
Some preprocessor state is created for each INBIT, INANA, and OUTBIT command. The following constants are created:
Port is the single lower case letter of the I/O port, and bit is the 0-N number of the bit within the port. For example, if RB5 is defined as a named pin with INBIT, the preprocessor constant Portdata_b5 will be created.
This constant is of type STRING, and contains individual tokens separated by spaces. The tokens are:
name IN|OUT POS|NEG DIG|ANA [ANx]
Name is the name assigned to this pin, which is the first parameter to the INBIT, INANA, or OUTBIT command.
IN or OUT indicate the direction the pin is configured in, from the processor's point of view.
POS or NEG indicate positive or negative logic. In positive logic, the on state is high and the off state is low. This is reversed for negative logic.
DIG or ANA indicate whether the pin is configured as digital or analog.
ANx is only present for analog pins. X is the analog channel number.
For example:
/INBIT level porta 3 -->
Portdata_a3 = "level IN POS DIG"
/INANA temp portc 1 an7 -->
Portdata_c1 = "temp IN POS ANA AN7"
/OUTBIT pump portb 5 -->
Portdata_b5 = "pump OUT POS DIG"
String constant for the upper case letter of the port containing the pin. Name is the symbolic name given to that input or output bit. For example:
/INBIT level porta 3 -->
Inbit_level_port = "A"
/OUTBIT pump portb 5 -->
Outbit_pump_port = "B"
Integer constant for the number of the bit within the port. Name is the symbolic name given to that input or output bit. For example:
/INBIT level porta 3 -->
Inbit_level_bit = 3
/OUTBIT pump portb 5 -->
Outbit_pump_bit = 5
Like INBIT except that it declares a analog input instead of a digital input.
X is the analog channel number. The analog channel numbers are mapped in unpredictable ways to the I/O ports. These are often referred to as "ANx" in the documentation. For example, "AN3" refers to analog input channel 3.
Like INBIT except that it declares the I/O bit to be an output instead of an input. This means the VAL_TRISx assembler variable will be updated to indicate this bit is an output.
In addition to the symbols and string substitution macros created by INBIT, OUTBIT also creates the macros set_name_on and set_name_off. These set the bank for access to the appropriate register, then use a bit set or bit clear instruction to turn the output pin on or off. On PICs with LATx registers, the bit instruction operates on them. Otherwise the bit instruction operates on the PORTx register.
Polarity defines the polarity of the "on" and "off" states of the pin. The polarity parameter must be either P for positive or N for negative. The default is P. Positive polarity means that high is on and low is off, and negative polarity the opposite. For example, this may be useful if a LED is connected in series with a resistor between the I/O pin and the positive supply. Setting the pin low turns the LED on and setting it high turns the LED off. In this case the polarity should be indicated as N instead of P:
/OUTBIT led portb 5 n
The polarity is taken into account by the set_name_on and set_name_off macros. For the example above, set_led_on would cause the RB5 pin to be driven low, and set_led_off would cause RB5 to be driven high.
Init indicates how the I/O pin should be set when the I/O ports are initialized. Init may be either 0 or 1 to explicitly set the pin low or high, respectively. Or, it may be ON or OFF, which will set it high or low depending on how the pin polarity is defined. The default is OFF.
Undefined I/O pins default to outputs driven low.
The GFLn variables are native words in size. That means they are 8-bit on 8 bit PICs (PIC 16, PIC 18, etc), and 16-bit on 16 bit PICs (PIC 24, dsPIC 33, etc).
The following assembler constants will be defined:
Number of the GFLn variable containing the flag bit. In other words, this constant will be 0 if the flag is in GFL0, 1 if it is in GFL1, etc.
Address of the GFLn variable containing the flag bit.
Number of the flag bit within the GFLn variable. The least significant bit is numbered 0, and the most significant is 7 on 8 bit PICs and 15 on 16 bit PICs.
#define flag_name n, bit
Example MPASM code:
/flag t100 ;set every 100 ms . . . dbankif gbankadr btfss flag_t100 ;time to do 100 ms processing ? goto done_100ms ;no, skip this section bcf flag_t100 ;reset to 100 ms proc not pending ;perform 100 ms processing here done_100ms unbank ;done with the 100 ms processing
/flag t100 ;set every 100mS . . . btss flag_t100_reg, #flag_t100_bit ;100 ms tick ? bra done_100ms ;no, skip this section bclr flag_t100_reg, #flag_t100_bit ;reset the flag ;perform 100 ms processing here done_100ms: ;done with the 100 ms processing
Integer, the total number of flags created.
Integer, the total number of GFLn words required for all the flags.
String. One of these constants exists for each flag. N is the 1 thru Flagdata_nflags sequential number of the flag. The value is a string with three tokens:
Name WordNumber BitNumber
Name is the name as given in the FLAG command.
WordNumber is a integer string of the 0-N number of the GFLn word this flag is contained in.
BitNumber is the 0-N number of the bit within the word. Flags are allocated within GFLn words in low to high bit order. The first flag in a word therefore has a bit number of 0.
All the ESCR functions are available, plus the following:
Converts the numeric value val to Embed Inc PIC 24-bit floating point and returns the result as a 6 character hex integer in native MPASM format. For example:
[FP24I 3.14159] --> h'419220'
This function does not return a string data byte, but the raw characters of a hexadecimal value in native assembler format.
Returns the integer value of the 24 bits resulting from val expressed in Embed Inc PIC 24-bit floating point. For example:
[FP24_INT 3.14159] --> 4297248
Converts the numeric value val to Embed Inc dsPIC 32-bit fast floating point, and returns the result as a 8 character hex integer in native ASM30 format. For example:
[FP32F -7.5] --> 0xC002E000
This function does not return a string data byte, but the raw characters of a hexadecimal value in native assembler format.
Returns the integer value of the 32 bits resulting from val expressed in Embed Inc dsPIC 32-bit fast floating point. For example:
[FP32F_INT -7.5] --> -1073553408