Recent Changes - Search:
<^< More Efficient Macros | Course index | Strings and Memory >^>

Introduction to Microcontroller Programming * Course Index * Introduction * About the Author * About this Course * Feedback * Course Navigation * Quick Course Navigation * How to use this Course * Acronyms Used and Course Conventions

About PICmicro Chips * What is a PICmicro? * Microcontrollers * Digital versus Analogue * Inputs and Outputs * Memory * Programming * 16F1937 Architecture

Clocking Your PICmicro Devices * Introduction * The Clock Circuit * Clock Settings * Clock Confusion

E-Blocks * Introduction to E-blocks * Using E-blocks * E-blocks Boards

Flowcode Step By Step * Introduction to Flowcode * Basic Flowcode Functions * Digital Outputs * Digital Inputs * Basic Loops * The LCD Display * Binary Numbers * Decisions * Goto (Connection Point) * 7-Segment Displays * Software Macro ## Set up the Equipment ## Left or Right? ## Create New Macros ## More Efficient Macros ##

Other macro features * Strings and Memory * A Simple Hi-Fi

PICmicro Projects * Introduction to PICmicro Projects * Construction Methods * Choosing a Power Source * Adding Inputs * Input Conditioning * Adding Outputs * Adding Drivers

Labs * Introduction and Lesson Plan * 1. Output * 2. Delay * 3. Connection Point * 4. Calculations * 5. Loop * 6. Input * 7. Decision * 8. LCD * 9. Keypad * 10. Analogue + EEPROM * 11. Software Macro * 12. External Interrupt * 13. Timer Interrupt

(:Summary:Contains the 'action' links (like Browse, Edit, History, etc.), placed at the top of the page, see site page actions:) (:comment This page can be somewhat complex to figure out the first time you see it. Its contents are documented at PmWiki.SitePageActions if you need help. :) * Print (:comment (:if group Site,SiteAdmin,Cookbook,Profiles,PmWiki*:) (:comment delete if and ifend to enable backlinks:) * %item rel=nofollow class=backlinks accesskey='$[ak_backlinks]'% [[{*$Name}?action=search&q=link={*$FullName} | $[Backlinks] ]] (:ifend:) :) * Login

Other Macro Features

<^< More Efficient Macros | Course Index | Strings and Memory >^>(:nl:)

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! (:nl:)(:table style="clear:both":)

(:Summary: Website page footer:)

Print - (:comment (:if group Site,SiteAdmin,Cookbook,Profiles,PmWiki*:) (:comment delete if and ifend to enable backlinks:) %item rel=nofollow class=backlinks accesskey='$[ak_backlinks]'% [[{*$Name}?action=search&q=link={*$FullName} | $[Backlinks] ]] (:ifend:) :) Search - Login

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