
RP6 ROBOT SYSTEM - 4. Programming the RP6
4.4.4. Variables
First we'll have a look at storing and reading data to and from RAM. Data access is
done through variables. C knows several data types for variables. Basically we will use
8, 16 or 32 Bits integer data types, which may be used either signed or unsigned.
The deserved value range determines the required number of bits for defining a stor-
age location for a variable.
For the RP6 we will use the following data types:
Type
Alternative
Value range
Remarks
signed char
int8_t
8 Bit:
-128
...
+127
1 Byte
char
uint8_t
8 Bit:
0
...
255
'' unsigned
int
int16_t
16 Bit:
-32768
...
+32767
2 Bytes
unsigned int
uint16_t
16 Bit:
0
...
65535
'' unsigned
long
int32_t
32 Bit:
–2147483648
...
+2147483647
4 Bytes
unsinged long uint32_t
32 Bit:
0
...
4294967295
'' unsigned
By a lack of standardisation, there are several varying sizes defined on different plat-
forms especially for the data type “int” : for our microcontroller the size is 16 bits, but
its 32 bits for (modern) PC's. For this reason we preferred the modern standard defini-
tion: int16_t
These data types are always made up like: [u] int N _t
u : unsigned
int : Integer
N : Number of bits, e.g. 8, 16, 32 or 64
_t : t for “type” to prevent collisions to other symbols
On a small microcontroller, every single byte counts and clearly defined data types will
help to keep track of memory consumption. You can immediately identify a 16bit data
type by the number 16 in the name. The letter “u” at the beginning marks an “un-
signed” data type, whereas this letter is omitted for a “signed” data type.
For the normal (classic) datatypes we only used the “signed” for
“signed char” in the table above, as int and long are defined as
signed types anyway and char is unsigned, even if you do not expli-
citly write this. The reason for these definitions is an AVR-GCC com-
piler option, which is activated in most cases.
The data type “char” will be used for strings, because an “uint8_t”-
definition would lead to a few incompatibilities with standard C librar-
ies and “char” is a clear and logical name for a character/string any-
way. We will explain details on this topic in the RP6Library chapter
for text outputs via the serial interface.
By now we simply note:
we always use “char” for characters and
strings, respectively uintN_t or intN_t for integers!
- 66 -