If you want a number of variables of the same type in a list, the simplest way to do this is with an array. To create an array, you must declare the variable as normal, but put the number of items in the array in square brackets after the variable name, for example:
This declares an array called ‘Month’, which consists of 12 integers. You can then read and write each one separately, again by using the index in square brackets. Note that arrays start at zero, so Month actually goes from 0 to 11, not 1 to 12. To assign to one item in the array:
Month = 31;
Month = 28;
And so on…
Functions allow you to group your code into smaller subroutines, that you can then call to execute them. Functions are declared as:
If you don’t want to return a value, or you don’t want any parameters, use the type void.
Every C program must have at least one function, called main. This returns an int, and takes void. (It can take other things, but for programming on a PIC you need not worry about this.)Use of functions is probably easiest to see with an example