![]() |
![]() |
||
Content |
PPMacros
/ FAQ
>
|
||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
FAQGeneralPPMacros, what is it?Is it open source? What does open standard in this respect mean? Are PPMacros bug-free? Which PIC controllers are supported? Will there be future versions? Can I contribute? Who are you and why are you involved with PPMacros? InstallationHow do you install PPMacros?How do I use PPMacros? PPMacrosWhat macros are included?Ehhh..., lots of macros... Can you explain a little? Do you have examples? GeneralPPMacros, what is it?PPMacros are macros which make programming PIC controllers made by Microchip easier. PPMacros should be used with the assembler MPASM or MPLAB. The macros introduce 8, 16 and 32 bits variables, mathematical macros (add, subtract, multiply, divide and remainder) for these variables, if-else-endif blocks, and for-next, do-while and repeat-until loops. Is it open source? Yes. It is open source under the GNU-license. This also means that you may enhance the software using the way these macros work. You can download the macros from this website: www.c4gen.com. What does open standard in this respect mean? In PPMacros, the names of the macros follow a certain standard. If you enhance the software, you are allow (and encouraged) to use the same naming convention. Examples: if you define a 32 bits floating point variable type, you can name it fp32 and introduce macros like load_fp32_lp32. If you want to introduce the square root macro, it can be named: sqrt_f_f, sqrt_f16_f16 and sqrt_f32_f32. Are PPMacros bug-free? I hope so, but probably it isn't completely. The first (internal) version of PPMacros was programmed in 2004. Macros (or variants) were added when a project needed them and therefore tested at the same time. In 2006, it was decided to program the complete set with all the variants. Also bank- and page-switching was added. At the end, almost all code was re-written or at least altered. Although most code was tested during programming with cases, some bugs may have slipped through. If you detect a bug or have fixed one, please contact me. See the contact page on www.c4gen.com for contacting details. Which PIC controllers are supported? All the 14-bits PIC controllers are supported. This includes the complete 16-serie (with as the most known PIC16C54, PIC16F84, PIC16F877 and PIC16F88) and some controllers from the 12-serie, like the PIC12F629 / 675 / 683 controllers. In principle it should be possible to use the macros for the 16-bits controllers (PIC18xxx) with a few small changes. This is not tested yet and maybe will be part of future versions. Will there be future versions? Can I contribute? Yes. In any case, bugs will be fixed. Also, new functionality will be added when a project needs this functionality. The website www.c4gen.com will give the status of the work in progress and the updates. You are encouraged to contribute to PPMacros. See the contact page for contacting details. The project will be coordinated by me, so feel free to contact me. Who are you and why are you involved with PPMacros? I am E.J. van Veldhuizen, living in the Netherlands. PPMacros were created while working on projects involving PIC controllers, since alternatives were not sufficient for the purpose. Free C-compilers were too limited, commercial C-compilers too expensive, and other macros had too many limitations (too few commands and no possibilities to nest commands). InstallationHow do you install PPMacros?Download the zip-file from www.c4gen.com. Unzip ppmacros.zip into the MPSUITE-directory, the directory which contains the project or another directory. How do I use PPMacros? Add in the source file: include "ppmacros.inc". In case the file is not in the MPSUITE-directory or the project-directory, the complete path or relative path should be given: include "path\ppmacros.inc". Some macros require some variables. They are called _PPMCRx_, with x a number starting from 1. Some macros need up to 13 of those variables. The macros should be declared sequentially and in bank zero, with e.g. the CBLOCK command. In the macro list, you can see the variables needed. An easier way is that you will get a compiler error if you didn't declare the variables needed, so you can use the trial-and-error method. Now you can use the macros. PPMacrosWhat macros are included?See the macro list for a complete list. Ehhh..., lots of macros... Can you explain a little? First of all, the macros include variable types, expressions and commands. In the Quick Guide, a short overview is given. Variable types: Basically, there are three variable types, 8 bits, 16 bits and 32 bits. The 16 and 32 bit variables have the Least Significant Byte at the lowest address. The 8 bits variable is denoted f or f8. The 16 and 32 bit variables are denoted f16 and f32 respectively. A literal is denoted l, l8, l16 or l32, depending on the size (l = l8). So the macro "load_f16_l16, loads a 16 bit literal into a 16 bit variable. Example: "load_f16_l16 VAR1,.34853". Also indirect addressing is possible: "load_f16_i8 VAR1, VAR2" loads the 16 bits variable with the address which is in VAR2, into VAR1. "load_f16_x8_o8 VAR1, VAR2, ARR" loads the element-number (indeX) which is in VAR2 of an array starting at ARR into VAR1". For bit operations f_b exist: "load_f_b_f_b VAR1, 6, VAR2, 3" loads bit 3 of VAR2 into bit 6 of VAR1. The macros take care of the data-banks in the PIC controller and set the bank-bits accordingly. The macros are programmed in such a way that after the macro, bank zero is selected. The expressions are based on the FORTRAN language: eq means equal to, ne means not equal to, gt means greater than, ge means greater equal to, lt means less than, and le means less than opr equal to. So the macro "if_f16_gt_l16 VAR1,.6825" means if VAR1 is larger than 6825 then ... For bit operations f_b_c (clear) and f_b_s (set) exist. "if_f_b_s VAR1,3" means that if bit 3 of VAR1 is set then ... There are a few basic commands. "load_a_b loads a with b (see examples above). The if_a_ex_b starts an if-block (see example above). The block may have any length and only ends at an else_if or an end_if macro. The for_a_b_c macro (e.g. for_f16_l16_l16 VAR1, .0, .12345) starts a for-next loop up to and including the higher limit (.12345). The ford_a_b_c variant counts down from b down to a. The loop is ended with the next macro. Also, a repeat macro exists which is ended with the until_a_ex_b macro. The while_a_ex_b macro is ended with a end_while macro. There are 6 mathematical macro-types: a_b_add_c (a = b + c), a_b_sub_c (a = b - c), a_b_mul_c (a = b * c), a_b_div_c (a = b / c), a_b_rem_c (a = b % c, remainder), a_b_c_divr_d (a = c / d, b = c % d). These macros work on the 8, 16 and 32 bit variables and literals. All these macros also exist with load_ in front of it (as logical name, but rather long): load_a_b_add_c, load_a_b_sub_c, load_a_b_mul_c, load_a_b_div_c, load_a_b_rem_c and load_a_b_c_divr_d. Notice that in the move and the math macros, the data flows from right to left. With load the last variable (at the right-hand side) goes to the first variable (at the left-hand side). The same applies to the math macros. This follows higher level languages (a=b;). The mnemonics of the PIC processors move data from left to right. If one prefers that notation, other macros exist. The opposite of the load macro is the is the move command: move_a_b moves a to b. The mul_a_b_c macro move (a*b) to c. One can use both forms in the same program, but it is wise to choose one of them to avoid confusion. Also other internal macros can be useful (goto_if_a_ex_b, gotop, callp, clrfb, etc.) These macros also take care of the bank or page bits and can be used in any program. Do you have examples? Of course. See an example or download a collection of examples from the download page which even can be useful in your project. You can find a routine that converts a 32-bits number to 10 digital digits, or a program which can interpolate from a list of data points. |
||