Recent Changes - Search:

Introduction to Microcontroller Programming

About PICmicro Chips

Clocking Your PICmicro Devices


Flowcode Step By Step

PICmicro Projects


Lab 11 - Software Macro

1. Introduction

In code based programming like C and BASIC, this software macro would be called a ‘subroutine’ or even a ‘function’ or a ‘procedure’. As your programs get bigger you will experience that you are using certain combinations of instructions over and over again and that your programs are getting harder to understand and read. You can put routines you use several times into a software macro and use it when ever you want in your main program by just referring to it with the name of the software macro. Make use of these software macro’s where ever you can. This lightens up your main program and makes it much easier to read.

2. Setting up the equipment
3. Hardware settings
EB006 OptionsSettingJumper settings (EB006)Jumper settings (HP488)
Power supplyExternal, 14VJ29: PSUJ29: PSU
PICmicro device16F1937  
Programming methodUSBJ12,13,14: USBJ20: USB
Clocking methodXTALSW2: XTALS2: XTAL
R/C clock speed   
Xtal frequency19 660 800 Hz  
LVP Jumper selectionI/O PortJ11,16,17: I/O PortJ15,16,18: I/O
Port A E-blockSensor board  
Port B E-blockLED board  
Port C E-blockSwitch board  
Port D E-blockLCD board  
Port E E-block   
4. Flowcode and download settings
Build > Project Options... > General Options Build > Project Options... > Configure
Clock speed19 660 800 Hz
Simulation speed10
Watchdog timerOff
5. Software learning objectives

Input, output, binary code training, using software macro’s.

6. Hardware learning objectives

Closed loop control (semi), PWM output for dimming lights.

7. Instructions

Construct the system shown from E-blocks.

In the course navigate to the ‘Flowcode step-by-step’ and review the section on Software Macro (step 10). The descriptions of the multiprogrammer board , the switch board, the LCD and the led board are in the E-blocks section.

Look into the 'Help' menu and function in Flowcode to get the info you need.

Software macro’s are extremely useful when programs get bigger. Efficient programming is all about using software macro’s wherever you can.

8. Labs
Letter Meaning
L Lab x
B Basic complexity
I Intermediate complexity
E Expert complexity
Develop a program that gives the user the possibility of activating one of three different programs by using just 2 switches. SW0 should be used to select one of the 3 programs (The LCD displays a text message that represents the currently chosen program) and SW1 activates the chosen program when pressed. The 3 programs that need to be placed in one of the 3 software macro’s are:
  • Program 1: An 8-bit binary up counter, visualized on the LEDs. Same as [L5-B1] (250msec intervals)
  • Program 2: An 8-bit binary down counter, visualized on the LEDs. (250msec intervals)
  • Program 3: An 8-bit bidirectional running light, visualized on the LEDs. Same as [L5-I6] (250msec intervals)
Download this program to the PIC and test it.
Variation on the program above. When SW0 is pressed while the program is executing one of the 3 software macro’s, the execution should stop immediately and return back to the main loop, waiting for the selection and activation of another software macro. Download this program to the PIC and test it.
Variation on the program above. The difference here should be that when the program returns to the main loop, it takes the variable value of the binary number that was on the LEDs at the time the specific software macro was stopped with it. When another software macro starts, it should start from the same binary combination on the LEDs when the last macro was terminated. This makes the transition between the 3 different software macro’s fluent. Download this program to the PIC and test it.
Variation on the program above. If SW2 is pressed, the currently running software macro should be stopped and the variable value should be reset to 0. All the functions of the programs above stay active. Download this program to the PIC and test it.

Print - Search - Login

Page last modified on May 13, 2013, at 04:38 PM