Recent Changes - Search:
<^< Create New Macros | Course index | Other macro features >^>

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

More Efficient Macros

<^< Create New Macros | Course Index | Other macro features >^>(:nl:)

# If you run the program you will find out that it has much the same effect as before. However now we have created two macros that we could use at other places in our program. However it is possible to use another technique so that we can cut the number of macros down to just one that would also be even more flexible.

# Create a new macro called "FLASH". Hover over 'Parameters' a button will appear, click on it then 'Add new'. Add a variable called 'whichone', keep it as a 'Byte' and select OK. You should have a Macro dialogue window that looks like this:

# First, create an Output icon in your newly created 'FLASH' macro, double-click this Output icon to access the properties. First we need to change the output to Port B, next we need to add our newly created local variable, Flowcode knows that the new macro 'FLASH' takes one parameter that is passed to it, you can see this demonstrated when you click on the button and then click on the 'Locals' button. Double-click the 'whichone' parameter to insert it.

# Next insert a 200ms Delay, an Output icon which sends 0 to Port B, and another 200ms Delay. You should end up with this:

# On the main flowchart double-click on the Macro icon that calls the 'LEFT' macro. In the 'Macro:' dialogue box select FLASH. below the 'Macro:' dialogue box you will see that Flowcode has recognised that this needs a parameter and the 'parameters:' dialogue box is enabled to allow you to enter the parameter. Enter the number '1':

# Similarly for the 'RIGHT' Macro icon call the 'FLASH' macro with a parameter of '2'. Your whole flowchart should now look like the one below. You now have the same functionality as the previous program but you have only used one macro. That's not too important in a small program like this, but in later programs you will appreciate the efficiency of this method of writing programs.

(: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 14, 2013, at 01:10 PM