Interfacing with C plus plus-programing communication with microcontrolers (K. Bentley, 2006)
.pdf9.1 Introduction
So far we have learned how to develop efficient object-oriented programs where the emphasis has been on the program statements (source code). In this chapter we will learn how to plan a program using pseudo-code, organise its structure, and write the program so typographical errors can be kept to a minimum. The development process to produce modular programs will also be explained.
A modular program can be made by separating a lengthy single file program into a number of logical modules and then placing each module into its own dedicated file. This process greatly improves our ability to maintain our programs. Furthermore, it allows us to carry out modifications with greater ease and also promotes more efficient debugging of programs. An inevitable consequence of this modular approach is the multi-file program. We will learn how to create a multifile program from a number of source files and then generate a final executable file.
9.2 Efficient Coding Techniques
The word coding is used is used in this chapter and refers to the writing of programming statements. No coding should commence until a detailed plan for the program is established. This plan is written as a general worded discription known as pseudo-code. If we are writing an object-oriented program, the first step should be creating the object classes and the associated class hierarchy. Using an objectoriented approach tends to result in a program with good structure. Program development should be carried out in a number of manageable steps. At each of these steps the program (or the part of the program) coded to that point can be compiled and verified for errors.
Most editors used for programming provide cutting and pasting facilities for text editing. We can minimise typographical errors during the coding process by using text cutting and pasting operations. These typographical errors tend to be the cause of most compilation errors.
Pseudo-code
Using pseudo-code to outline the basic operation of an application can assist in its development. The following example demonstrates how pseudo-code is developed and used to generate program code.
Program description:
A crane is used to lift a weight from point A and move it to another point B. It is assumed that the crane uses three DC motors; one to lift/lower the load, another to move the load in the x direction, and the third motor to move the load in the y direction.