Skip to main content
main-content

Über dieses Buch

The aim of this chapter is to get you started in writing C++ programs. We will develop a number of simple C++ programs and learn the syntax and typography associated with writing a program. One of the basic building blocks of any C++ program is the so-called function. This chapter will explain the basic concepts behind C++ functions and their use. The C++ language has built-in fundamental data types that can be used to develop complex user-written data types. Some of the fundamental data types will be explained in this chapter. Towards the end of the chapter we will step through the complete program development process; starting from planning a small program down to using the elements of program development software needed to generate a program that can be run on your computer. We will commence with the use of non-object-oriented programming methods because these programs are simpler to understand at this early stage. Object-oriented programming concepts will be explained in Chapter 4 and then used extensively through the remainder of the text.

Inhaltsverzeichnis

Frontmatter

1. Getting Started

Without Abstract

2. Parallel Port Basics and Interfacing

2.5 Summary
This chapter explained the configuration of the parallel port and the digital logic concepts involved when using the port with external circuitry. These concepts include binary notation, digital logic levels, noise margins and different types of logic families such as CMOS and TTL.
The PC parallel port uses three I/O addresses to transfer data through the port’s interface. Each address controls one byte of data, however, for two I/O addresses, several data bits are unused and a few other bits are inverted internally by the port circuitry. The first I/O address is used to output data only, the second address is used to input data through the port and the last address can be used to both input and output data. Furthermore, representation of data using decimal, hexadecimal and binary number systems has been explained. This knowledge will be used when developing programs in the chapters ahead.

3. Testing the Parallel Port

3.7 Summary
In this chapter we have explained the operation of the interface board power supply, port interface, and LED Driver circuits. These circuits allow the parallel port of the PC to interface with the interface board and test operation of programs.
We learned how to develop C++ programs for sending and receiving bytes of data through the three addresses associated with the parallel port of the PC. These programs printed their results to the screen using either the cout object (as we did in Chapter 1), or using the functions of the printf() family. We also explained a small subset of the format specifiers that the printf() function uses.
The Exclusive OR bitwise operator was used to toggle some of the data bits we transmitted through the parallel port. Bitwise operators are a very useful part of the C and C++ languages and allow us to manipulate specific bits within a byte.

4. The Object-Oriented Approach

Without Abstract

5. Object-Oriented Programming

5.8 Summary
At the start of this chapter we developed an object class with the name ParallelPort. This class contained only sufficient data members and member functions to give us basic use of the port. We applied particular access attributes to the class members and explained the importance of making proper use of these access attributes.
Several programs were used to explain the relationship between multiple constructors and the default constructor. The ParallelPort class was then expanded to include use of the BASE+1 and BASE+2 addresses. The operation of objects instantiated from this expanded class was demonstrated using a program which transferred data to and from the interface board. Now that we have a fully functioning ParallelPort class, we will be able to use it extensively in future chapters.

6. Digital-to-Analog Conversion

6.6 Summary
The operational amplifier, discussed in this chapter, is the building block for many analog electronic systems. This device is used in conjunction with the interface board DAC0800 IC to form a complete digital-to-analog voltage converter system. Basic principles of two types of DAC circuits have been discussed including DAC characteristics and specifications.
In this chapter the important concepts of inheritance and polymorphism have been explained. How various access attributes interact with each other, and how various access specifiers affect the access attributes has also been described. We also learned how to use the scope resolution operator to call a polymorphic function from a base class. The DAC object created at the end of the chapter has all the functionality to drive the Digital-to-Analog Converter, and protects the member data of both the base class and the derived class at private level.

7. Driving LEDs

Without Abstract

8. Driving Motors - DC & Stepper

8.8 Summary
This chapter presented the construction and operation of DC Motors and Stepper Motors. Various means of controlling these motors has also been described.
A class hierarchy was developed to represent all types of motor discussed at the beginning of the chapter. This was followed by a conceptual explanation of abstract classes and pure virtual functions. Class hierarchy’s and multiple inheritance were also explained. The need for a set of virtual destructors in a class hierarchy was also demonstrated. Unlike constructors, destructors can be virtual. These destructors are used to free an object’s dynamically allocated memory once the program no longer needs the object.
A generic program for all real motor classes of the hierarchy was developed and integrated into a main() function to demonstrate the concept and advantages of late binding. Keyboard controls were then incorporated into the program to improve control of motors when using the interface board.

9. Program Development Techniques

Without Abstract

10. Voltage and Temperature Measurement

10.8 Summary
In this chapter we have described the operating principle of the Voltage-controlled Oscillator (VCO). The VCO produces a pulse-train having a frequency that is proportional to the voltage applied to its input. By measuring the frequency (or period as we did) the voltage/frequency relationship can be used to generate a measurement of voltage. In this way the VCO can be used as a simple and inexpensive alternative to an analog-to-digital converter.
A new object class named VCO was developed using the ParallelPort as the base class. Software methods have been described to continuously check the level of an incoming digital signal while incrementing a counter, and thereby measure the period of the waveform. Graphics programming was introduced to display the resulting waveform, followed by the development of a program that uses the thermistor on the interface board with the VCO to measure the actual temperature.

11. Analog-to-Digital Conversion

11.8 Summary
This chapter described the principles of operation and use of an analog-to-digital converter. The more popular types of analog-to-digital converters and their various methods of conversion have been explained. This was followed by a discussion of the importance of a sample and hold circuit and the effects of aliasing that occurs when signals are sampled too slowly.
We used our now familiar object-oriented approach to develop software for interfacing the parallel port of the PC with the ADC. We developed a new object class named ADC using an approach consistent with that of Chapter 10 when the VCO class was developed. This object-oriented approach has allowed us to develop the voltage and temperature measuring programs that used the ADC by making minor changes to the programs written for the VCO.

12. Data Acquisition with Operator Overloading

Without Abstract

13. The PC Timer

13.9 Summary
In this chapter we learned how the built-in timer of the PC operates and how it can be used. The object class PCTimer has been developed with the capability to measure very long time periods. It has member functions to mark a time reference, accurately read the elapsed time, and also generate specific delays.
The PCTimer class operates without disabling the PC’s interrupts. As such, the interrupt service routines will generate short interruptions that can contribute to minor inaccuracies when measuring time. This was demonstrated when one of our example programs made repeated measurements of a ‘fixed-time’ event with interrupts enabled, and later with interrupts disabled. Other programs were presented in this chapter that measured a person’s reflex reaction time, generated a waveform plot using an accurate time-base, and used regular and accurate timing to digitise the electrical waveform produced by the interface board’s Charge/Discharge circuit.

Backmatter

Weitere Informationen