Recent Changes - Search:

Introduction to Microcontroller Programming

About PICmicro Chips

Clocking Your PICmicro Devices

E-Blocks

Flowcode Step By Step

PICmicro Projects

Labs

Other Macro Features

<^< More Efficient Macros | Course Index | Strings and Memory >^>

Whilst you were entering the 'FLASH' macro you may have noticed that the macro dialogue window has some other features.

Local variables

All of the variables you have used so far are 'Global' variables. The word 'Global' here refers to the fact that these variables are available at all points in your program. With small programs like the ones in this course this is not a problem: there are over 500 separate bytes of RAM we can use in the 16F1937 and it is unlikely that we will run out of variable space.

However with larger programs - particularly those using strings - there is a chance that we will run out of variable space. Because of this Flowcode has a feature that allows you to declare a number of variables that are only available whilst the macro is running. These are called 'Local' variables. Flowcode will create these variables in RAM at the start of the Macro and it will delete them at the end of the macro: freeing up RAM space for other parts of the program.

You should not have any real problems using 'Local' variables so we will not look at an example here.

Return values

Macros have another useful feature that makes your program neater and which saves you allocating a further variable - the return value. If you have a macro that is carrying out mathematical operations then it is often useful to have the macro return a value directly to the point in the program that called the macro. You could implement this by having a 'Global Variable', assigning the calculated value to the global variable, and then picking up the result in your main program. However returning the value in the macro is a neater option and it means that, you save RAM space!

<^< More Efficient Macros | Course index | Strings and Memory >^>

Print - Search - Login

Page last modified on May 01, 2013, at 02:53 PM