Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
308 Chapter 13 only the sequence of characters. Nevertheless, the statements must be all on one line; line returns are not allowed within a statement. Each complete statement is terminated with a semicolon. Note that some are not complete in themselves, and do not have a semicolon. For example, `while(1)' is not complete without the loop statements, or at least the pair of braces. The close brace terminates the `while' statement. The whole of the main loop, and any functional subblock, must be enclosed between braces. 13.3.3. Advantages of C Programming The C compiler converts the program into PIC 16-bit machine code. Most of these C statements translate into more than one machine code instruction. This can be confirmed by studying the list file, which is produced by disassembling the machine code. The pseudocode for the temperature controller above (Program 13.2) can probably be more easily translated into C than assembly language. For example, the conditional control operations defined using IF.THEN statements will translate directly, whereas, in assembler, they have to be implemented by suitable combinations of `Bit Test and Skip' with `Goto' or `Call'. The comparison of the `average temperature' with the set values can be done in one statement in C, but in assembler needs a subtract or compare prior to a bit test, which is much more complicated. On the other hand, checking bit inputs is not as easy in C as in assembler, as ANSI C contains no individual bit operations. Bit status in a register has to be checked by using a logical or numerical range check. There are many references on C programming. To program a microcontroller in C, only the basic set of statements and simple data structures will probably be needed, so if the reader has some knowledge of C already, using it to develop PIC applications should not be too difficult. For further details, see Programming 8-Bit PIC Microcontrollers in C with Interactive Hardware Simulation by this author (Newnes 2008). This uses the CCS C compiler, which has a complete set of ready-made functions that simplify the C code, especially I/O handling and mathematical functions. Questions 13 1. (a) What interfacing modifications are recommended for the LM35 temperature sensor if the connections are over 1 m long? (4) (b) For the TEMCON2 system, calculate the output of the LM35 sensor at 25 C, and the decimal value that would be found in the ADRESL on completion of an A/D conversion of this input, if the result is right justified. (4) 2. State one advantage of (a) the relay output and (b) the FET output as used in the temperature controller. (4)