-
6
pages
-
English
-
Documents
Description
MPLAB MCC18 C-PROGRAMMING TUTORIAL M.F. van Lieshout TU/e, fac. ID Or. 14-09-2005 Transl. 17-05-2006 Basic rules for programming in C There are some basic rules when programming in C: - Comments for only 1 line of code start with 2 slashes: // //This is a comment Add many comments to your code, otherwise it is very hard to remember how your program works after a few weeks! - Comments for more than 1 line start with /* en end with */ /* This is a comment. This is another comment. */ - At the end of each line with some instruction, a semi-colon (;) has to be placed. a=a+3; - Parts of the program that belong together (functions, statements, etc.), are between { and }. void main(void) //Function { //Add code } The structure of the program The structure of a program in C is as follows: - Add libraries with functions. This is done with the following line of code: #include - Declare (global) variables. The different types of variables will be discussed later in this document. - Making prototypes of the functions. A prototype of a function ensures that the function can be called anywhere in the program. Without a prototype, only functions can be called if they are already declared above of the current function. - Functions. Functions are very useful to make it easy to repeat tasks. They can have input and output variables. The output ...
-
Publié par
-
Langue
English