Beginnings
Desktops and laptops form a minority of the computers in the real world. In the main most computers exist in the innards of items like cars, toasters, microwaves etc. These are embedded systems. All these systems require software programs.
The two principal programming models are:
- Procedural - Drives the user. Program controls order of output and input. This control is exerted by the program design.
- Event Driven - User is in charge as in a Windows environment. Program does nothing until user clicks an icon.
This course looks at procedural programming first. This is followed later by event driven programming and the introduction of objects.
Software
Binary numbers were originally used to produce Machine Code Programming. Difficult to read and maintain. Modern, easier to read and use languages and tools were developed. These allow:
- The production of source code written in a text-editor tailored for writing computer programs.
- Translating the program source code into machine readable code by a compiler.
- Testing of the program by debugging.
- Use of a linker to enable the reuse of other programmers code.
- Libraries of code for common tasks.
- Facilities for programming for Windows.
This course uses C++ Builder from Borland International Inc.
Builder
The following lines:
- #include <vcl.h>
- #include <stdio.h>
tell Builder to incorporate library code.
The line - #pragma hdrstop tells builder how to deal with library files.
This line is a comment:
- //---------------------------------------------------------------------------
Or at least the slashes are. The dashed line is a visual aid to that comment in this instance.
The line - #pragma argsused prevents warning messages regarding argc, * argv[] from the line that follows it.
The complete code listing is shown below.
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
puts("Hello World.");
puts("Press enter to close the program.");
getchar();
puts("Not finished yet. Press enter again!");
getchar();
return 0;
}
//---------------------------------------------------------------------------
puts("Hello World."); puts the string to the screen.
getchar holds the program until a key is pressed (get character) in response to the program output.
The above two (puts and getchar) are from a code library called stdio, accessed via the header file by the command #include <stdio.h> .
VAT Program
//---------------------------------------------------------------------------
#include <vcl.h>
#include "MT262io.h";
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
float Price;
float VatRate;
float Vat;
Price = 6.20;
VatRate = 0.175;
Vat = Price * VatRate;
Price = Price + Vat;
WriteString("Price including VAT is ");
WriteFloat(Price);
getchar();
return 0;
}
//---------------------------------------------------------------------------
Now we have included the MT262 library. We have established some variables:
- Price
- VatRate
- Vat
Variables have labels called identifiers. Good practice is the use of illustative words, running multiple words together using capitals at the start of each word e.g. VatRate.
These variables will use float numbers and values have been set for the variables.
Calculations are performed and the result returned by the program.
Using Computers
All computers have:
- Storage
- Input Device(s)
- Processor
- Output Device(s)
Embedded Systems
Input comes from the user and the appliance. Output can go to user via display or to the appliance. Programming can be procedural or event driven. In a procedural program the program would continually interrogate (aka polling in an embedded system) the sensor. In an event driven model, (termed interrupt driven in embedded systems) the sensor reports to the program and the program reacts (to the event/interruption)
In an embedded system events have to be prioritised.
Non-Embedded Systems
Here we are thinking about the PC/MAC's of the world.
Interaction between the computer user and application programs is via the Operating System (OS). The user may appear to be working with his/her spreadsheet, but it is the OS that controls how the program behaves and what the user sees on his screen.
Although Windows is event driven, there are times when the program is in charge e.g. a dialog box that a user must respond to before the program allows the user to proceed.
In the main programs of the Windows type are event driven. In addition these programs rely on code re-use. Most will have the familiar File - Open menu options. The code does not have to be written afresh for each program. Re-usable code is also in use in procedural programs.
What code does is the specification. How it does it is the implementation. A programmer needs to know this specification before he can re-use it with confidence. C++ separates these two. Comments in the header file should contain the information for the specification. The code file contains the C++ code for the implementation.
Re-usable code and project management promotes the development of small modules with proper specification. These are easier to test and maintain.
Computer Hardware
Computers must have the following features:
- Receive information through Input.
- keyboard
- mouse
- scanner
- microphone
- camera
- cable
- modem
- Display information through Output.
- monitor
- printer
- plotter
- loudspeakers (through sound cards)
- cable
- modem
- industrial tools
- Storage
- ROM
- RAM
- CD-ROM
- Hard Disk
- Magnetic Tape
- Floppy Disk
- Processing Information
- CPU
- additional microprocessors for specific tasks
- Embedded systems may have only one processor
Comments, suggestions, ideas to
Stuart Banner
