why C?
is making thing easy for AVR, i'm using Mr Ari Winoto book as a guide for making thing that i explain below.
this is a great book
this is how i'm learning c
making this file on my blog
here is the example of c format file:
/*Learning C language
Basic of programming format with c
by: Agas
*/
#include
#include .... //preposesor include
#define on 1
#define off 1
// change the value 1 with 'on' and 0 with 'off
/* description: prepocessor #include is used when using a header file.h or a library file,
<> for file that is in strandar folder, ".." the user mention the location of the file
#define : used to define a macro konstant, the format:
#define identifier konstanta
*/
unsigned char data; //global variable
......
/*a global variable is declared outside of every function, including the main function
must be declare on the first line, the property of this variable is
can be access with every statement on the program
Format:
DataType Variablename;*/
void initialization (void); // function prototype
unsigned int kuadrat(unsigned char);
.......
/* this is a function prototype
used for declare the function that is written below the "main" function
we don't need to declare the function first,
the format:
Datatype functionname(datatype, ...,...); or
datatype functionname (datatype variable name, ....,...); */
//example of a function prototype
unsigned char x_pangkat_y(char x, char y) // a function
{ char z; // local variable
...
...}
int main void () //main function (must be included)
{ unsigned int temp; //local variable
........
initialization() //calling the initialization function
........
temp=kuadrat(2); //calling the kuadrat function
while(1){
.....
...
return();
}
/* this function will be executed first,
a call function in c
function name();
for a function that have an ouput value
variablecontainer = functionname();
*/
void initialization (void) //function
{...
...
}
unsigned int kuadrat (unsigned char x); //function
{unsigned int y;
y = x*x
return(y);}

Tidak ada komentar:
Posting Komentar