A program is to be designed to meet the specification given in Appendix A, which describes how to develop the hardware design for this application. The specification was as follows: When a button is pressed, the system generates an 8-bit binary count, starting at 0, on a bar graph display. The output frequency at the least significant bit is 50 Hz, giving an overall cycle time of 2.56 sec.
The general form of a real-time application is represented by the flowchart in Figure B.1, which shows two main phases: initialization and main loop. The initialization is executed once, and the main loop repeats.
The program must be written to the syntax requirements of standard C, with reference in this case to the CCS C User Manual (Version 4), downloadable from as a PDF from www.ccsinfo.com. The dialect of C developed by CCS Inc. is tailored specifically to the features of the PIC microcontroller. CCS supplies different complier variants for low-, middle-, and high-performance PICs; the mid-range compiler PCM is used for the PIC 16F877A.
The initialization phase typically contains statements that include the MCU-specific header and library files specific to the target device. The main program is contained in a function main(). Variables and data structures defined at this point are global in scope (recognized and unique throughout the whole program). The endless loop can be started with while(1) or for(;;), both of which mean to run an endless loop (unconditionally).
The main loop contains various conditional sequences and loops, comprising data operations and function calls. These functions may be built into the compiler, included as additional libraries with the use directive, or written by the user. They process input or stored data and return results to be used by later functions, for example, as system output. A general outline of a C program is shown in Listing B.1
Listing B.1. C Program General Outline
.Header comment block
Include resource files
Other preprocessor commands
Function blocks
Function name(plus received parameters)
Local variable & data structure declarations
Unconditional sequences
Conditional sequences
Loop sequences
Function calls
Return to calling block with results
Main block
Variable declarations
Data structure definitions
Loop
Unconditional Sequences
Conditional Sequences
Loop Sequences
Function Calls
Endlessly
18.225.55.151