User manual
RP6 ROBOT SYSTEM - 4. Programming the RP6
functions, but is not needed in a microcontroller system. We only need to add this re-
turn value to meet the standard C-conventions (and as we will see later, programs for
microcontrollers will usually never terminate).
This tiny program gave you a first impression of C-programming. Now we have to dis-
cuss some other basics before we can go on with example programs.
4.4.3. C basics
As already mentioned before, a C program is written in pure ASCII (American Stand-
ard Code for Information Interchange) text. It is strictly case sensitive and if a func-
tion is named “MyFavouriteFunction” you will have to call the function by this exact
name! A function call for “myfavouritefunction” would not be recognized!
You can insert any number of spaces, tabs and line breaks between all commands and
symbols without interfering with the programming syntax. As you may have seen in
the sample program the commands have been indented by tabulators to improve the
program's readability. But that's not necessary! You could write the program text from
line 7 in listing 1 e.g.:
1 int main(void){initRobotBase();writeString("Hallo Welt!\n");return 0;}
This is an identical program, but the text is rather confusing. However we only deleted
tabs, spaces and line breaks! The compiler does not care for formatting styles at all!
(Of course we will need a space as a separator between keywords and variables like
“int” and “main” – and we are not allowed to use a line break between two quotation
marks (at least not without an escape sequence)!)
The accolades { } allow us to combine several assignments and commands to blocks,
which will be needed for functions, conditional statements and loops.
Each assignment is to be terminated by a semicolon ';' to allow the compiler to identi-
fy individual commands.
Before you start typewriting and copying the program snippets from this tutorial we
would like to give you an important advice: most beginners do easily forget to termin-
ate commands by a semicolon – or use the semicolon at wrong locations and wonder
about the strange program behaviour! Forgetting to place one single semicolon at cer-
tain programming sections may result in a great number of error messages – even if
the real error is only one single error. In fact, the first error message will most likely
identify the real error location.
Forgetting to close one of several accolade pairs or bad syntax in spelling commands
belong to the common error patterns for beginners. Compilers do not accept any syn-
tax errors! It takes time getting used to all this rules, but you will quickly learn by trial
and error.
Each and every C-program starts in the main function. Basically any following com-
mands will be executed step by step, sequentially from the beginning to the end.
The AVR Microcontroller is unable to execute several commands simultaneously! This
restriction is not causing any problems as we will have ample options to control the
program flow and jump to other sections of the program (this will be discussed in a
later chapter).
- 65 -










