- Published: Wednesday, 11 November 2009
- Written by Jon Chandler
- Hits: 5558
As you develop program code, you probably find that there are snippets you use again and again. Re-using code probably involves opening a program where it was used, find the section you want, copying and pasting and then finally editing as needed in the new application. It can be a hassle to find exactly what you're looking for.
Microchip has a nice piece of software for helping with this task - the Code Module Library, which can be downloaded free from their website.
The left side of the screen has a tree with all the saved files. Clicking on one of the saved files opens it on the right side of the screen. The top right-hand section has a description and comments about the file. It will scroll, so can be quite lengthy if a lot of explanation is needed.
The bottom section of the screen shows the saved file. Any text file can be copied and pasted here, such as a file from the Swordfish editor.
The center section is where the power of this library manager comes in. When a file is saved, some of the items can be designated as variable. In this case, the device, port pin, clock speed and LED name are variable. When I want to re-use this code, I can change the variable items in the "Replace With" field. For example, maybe I'm testing a board with a PIC 18F1320 with an LED tied to PORTD.3. I make the changes in the "Replace With" field but it doesn't change the original file. When I click the copy button, the file with my changes is copied to the clipboard. From there, I can paste it into the Swordfish or any other editor. Pretty slick.