This chapter gives a basic overview of programming in C for an embedded system. We will introduce some basic terms so that you get a basic feel for the language. Since this is just the first of many chapters it is not important yet that you understand fully the example programs. The examples are included to illustrate particular features of the language. | Chapter 1 Program Structure -- Valvano Page 1 of 15 Chapter 1 Program Structure What s in Chapter 1 A sample program introduces C C is a free field language Precedence of the operator determines the order of operation Comments are used to document the software Prepreocessor directives are special operations that occur first Global declarations provide modular building blocks Declarations are the basic operations Function declarations allow for one routine to call another Compound statements are the more complex operations Global variables are permanent and can be shared Local variables are temporary and are private Source files make it easier to maintain large projects This chapter gives a basic overview of programming in C for an embedded system. We will introduce some basic terms so that you get a basic feel for the language. Since this is just the first of many chapters it is not important yet that you understand fully the example programs. The examples are included to illustrate particular features of the language. Case Study 1 Microcomputer-Based Lock To illustrate the software development process we will implement a simple digital lock. The lock system has 7 toggle switches and a solenoid as shown in the following figure. If the 7-bit binary pattern on Port A bits 6-0 becomes 0100011 for at least 10 ms then the solenoid will activate. The 10 ms delay will compensate for the switch bounce. For information on switches and solenoids see Chapter 8 of Embedded Microcomputer Systems Real Time Interfacing by Jonathan W. Valvano. For now what we need to understand is that Port A bits 6-0 are input signals to the computer and Port A bit 7 is an output signal. Before we write C code we need to develop a software plan. Software development is an iterative process. Even though we list steps the development process in a 1 2 3. order in reality we iterative these steps over and over. 1 We begin with a list of the inputs and outputs. We specify the range of values and their