PIC Program Development:Program Structure

Program Structure

Structured programming means constructing the program, as far as possible, from discrete blocks. This makes the program easier to write and understand, more reliable and easier to modify at a later date. Program BIN3 is unstructured, in that the program instructions are essentially executed in the order given in the source code. An equivalent ‘structured’ program, BIN4, is listed as Program 4.2.

The main difference between BIN3 and BIN4 is that the program now has the delay sequence as a ‘subroutine’. The subroutine is inserted before the main program block, and assembled first. It is then ‘called’ from the main program by label. The subroutine can be created as a self-contained program block, and reused in the program as necessary. It can be called as many times as required, which means that the block of code needs to be written only once. It can also be converted to a separate file and reused in another program. In addition, the delay time is loaded before the subroutine execution, so the same delay routine could be used to provide different delay times.

A program flowchart has been given for BIN3 (Figure 4.2). The same flowchart describes BIN4, but the delay routine can now be expanded as a separate subroutine flowchart

(Figure 4.3). The use of flowcharts in program design will be more fully examined in Chapter 8.

Leave a comment

Your email address will not be published. Required fields are marked *