Hardware Reference
In-Depth Information
Figure 7.10 Output produced by the example comparison program
#include <iostream.h>
int main()
{
int number;
cout << "Please enter a number between 1 and 20: ");
cin >> number;
// Compare input number with 10 and display results
if (number < 10)
{
cout << "The number you entered is less than 10\n";
}
if (number > 10)
{
cout << "The number you entered is greater than 10\n";
}
if (number == 10)
{
cout << "The number you entered is 10\n";
}
return 0;
}
Port I/O in C and C ++
Finally, the example programs that follow show how easy it is to read and write
data to/from I/O ports in C. Note, however, that the restrictions apply to these
programs when run from within a Protected Mode environment (see page 215).
The first example reads the state of three ports and displays the input data
in decimal whilst the second example output bit-field data to a port. The third
example shows how it is possible to include assembly language code within a
C/C ++ program. All three examples are written using Borland C ++ 4.5.
Example 1 :
/* Name:
readin1.c
*/
/* Language: Borland C++ 4.5
*/
/* Output:
Reads input ports and displays in decimal
*/
Search WWH ::




Custom Search