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 Options | Setting | Jumper settings (EB006) | Jumper settings (HP488) |
Power supply | External, 14V | J29: PSU | J29: PSU |
PICmicro device | 16F1937 | | |
Programming method | USB | J12,13,14: USB | J20: USB |
Clocking method | XTAL | SW2: XTAL | S2: XTAL |
R/C clock speed | | | |
Xtal frequency | 19 660 800 Hz | | |
LVP Jumper selection | I/O Port | J11,16,17: I/O Port | J15,16,18: I/O |
Port A E-block | Sensor board | | |
Port B E-block | LED board | | |
Port C E-block | Switch board | | |
Port D E-block | LCD board | | |
Port E E-block | | | |
4. Flowcode and download settings
Build > Project Options... > General Options
| Build > Project Options... > Configure
|
Options | Setting |
Clock speed | 19 660 800 Hz |
Simulation speed | 10 |
|
Options | Setting |
Device | 16F1937 |
RC/XT | XTAL |
Watchdog timer | Off |
|
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
|
- L11-B1
- 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.
- L11-I2
- 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.
- L11-E3
- 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.
- L11-I4
- 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.