ME Labs, Inc. 719-520-5323 |
Specifying configuration bit settings in PICBASIC PRO™ programs (for PBP 2.60C and earlier).The following information is not applicable to PBP 3.0 and later. For these newer versions, see the directives "#CONFIG"/"#ENDCONFIG" in the PBP user guide. It is possible to add a line to your PICBASIC PRO™ program that will place configuration bit settings in the generated hex file. The method used depends on the assembler that you are using in conjunction with PBP. If you are compiling for 18C or 18F PICs, you must use the Microchip assembler, MPASMWIN.EXE. Some Windows interface software will specify MPASMWIN as the default assembler for all the PICs. The easiest way to know what assembler is in use is to do a compile. If you see the MPASM window pop up momentarily and display a green progress bar, or if you see a black command window momentarily, you are using MPASMWIN and should follow the appropriate procedure below. If no popup window appears, you are using PM. If you add a configuration directive to your program file, you are actually replacing the default configuration that the compiler would otherwise include. The easiest way to determine the correct syntax is to get examples from the compiler and assembler's built-in resource files. To that end, it's best to understand how the compiler determines the config defaults. When PICBASIC PRO is invoked, whether through a Windows interface or DOS command line, it is given a set of parameters that tell it how to proceed. To determine the configuration defaults, it needs to know which PICmicro® is being used and which assembler to use. The first thing the compiler looks for is a file in the PBP folder that matches the targeted PIC®. If you tell it to compile for a 16F84A, it reads the file "16F84A.INC". The contents of this file are divided into 2 sections, one for each assembler. An internal variable, "PM_USED", tells the compiler which section of the file to use. In the following example, you will see that the top section ("ifdef" to "else") is meant for the PM assembler and the bottom section ("else" to "endif") is meant for the MPASM assembler.
For each assembler, PBP is given a header file and a set of defaults. The header file is important because it holds the definitions of the labels used to set the configuration. Keep in mind that the labels in MPASMWIN are case-sensitive, in PM they are not. Procedure for MPASMWIN.EXE: A note about deprecation of the __CONFIG directive Let's look at an example using the 18F452 and setting the oscillator configuration to HS. Assuming the compiler is installed at C:\PBP, we view the file C:\PBP\18F452.INC . Only the critical settings are listed in the file. Any bits not listed are left in their default states, which can be found in the Special Features section of the Microchip datasheet for the PICmicro. Here we find that the MPASM configuration directive reads:
To find the correct labels that set the configuration bits as we need them, view the MPASM header file found in C:\Program Files\Microchip\MPASM Suite\P18F452.INC. Here we find the label we need:
Replacing the appropriate labels and putting the "@" at the beginning of the line to signify inline assembly, the configuration line in our PICBASIC PRO source file becomes:
To avoid an error caused by multiple configuration lines, the original line must be commented in the file 18F452.INC. A semicolon (;) is used for comments in Assembly language:
Procedure for PM.EXE: Let's go through an example. Let's say we want to compile for the 16F877 using PM and we want to set the oscillator configuration to HS and enable code protection. Assuming the compiler is installed at C:\PBP, we view the file C:\PBP\16F877.INC . Only the critical settings are listed in the file. Any bits not listed are left in their default states, which can be found in the Special Features section of the Microchip datasheet for the PICmicro. Here we find that the PM configuration directive reads:
To find the correct labels that set the configuration bits as we need them, view the PM header file at C:\PBP\INC\M16F87x.INC. Here we find the labels we need:
Replacing the appropriate labels and putting the "@" at the beginning of the line to signify inline assembly, the configuration line in our PICBASIC PRO source file becomes:
Some of the newer PIC16 MCUs have multiple configuration words. An example is the PIC16F88. When you open the .INC file for these devices, you will see a section of labels denoted with the "DEVICE2" heading:
When using configuration labels from this section, a special directive "device2" must be used, as follows:
PM will always take the configuration that is placed in the program source code. There is no need to comment or remove the line in the .INC file. |
Copyright 2022 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|