1.1 The basic concepts of the programming language Pascal
All examples presented in this book rely on the programming language Pascal and its application in the mikroPascal compiler for dsPIC. It is thus necessary to introduce some of the concepts, modes of their applications, and their meanings in order to facilitate understaning of the abundant examples contained by the book. The simplest structures of Pascal are used, so the examples can be understood with no need for an analysis of the programming language.
NOTE: In this chapter no complete Pascal language used by the compiler has been presented, but only some of the methods of declaring types and some of the key words often used in the examples. The reader is referred to the help-system accompanying the mikroPascal compiler for a detailed study of the possibilities of the Pascal language and its application in programming the microcontrollers of the family dsPIC30F.
The memory of a microcontroller of the family dsPIC30F keeps 16-bit (2-bytes) basic data. All other types of data are derived from these. The compiler also supports 1-byte and 4-bytes data. Both integer and floating point variables are supported. This chapter will present the most frequently used types of data. Table 1-1 presents a review of integer variables supported by the dsPIC mikroPascal compiler.
||RANGE OF VALUES
|bit (compiled to word)
|word, byte, char
||0 ... 65536
||-32768 ... 32767
||-2147483648 ... 2147483647
Example – declaring integer variable:
letter : char;
number : integer;
Example – declaration of a floating point variable:
The floating point variables are supported by the type of data real
, 32 bits wide in the memory and of the range (±1.17549435082*10-38 ... ±6.80564774407*1038).
number : real;
Example – declaration of arrays:
A set of variables of the same type, if indexed, is represented by an array.
series : array[3...12] of real;
second_series : array of integer;
As can be noticed from the above examples, the indexes in an array can start from any integer value. If within the square brackets only one value is declared, the array has so many members (5 in the above example). In that case the index of the first member iz zero!
Example – declaration of type string:
A series of characters is represented by a type of data called string
. It, in essense, represents an array of the type char
, but sometimes it is useful to be considered as text.
text : string;
Example – declaration of pointer:
More difficult to understand, but often used type of data is pointer. It serves for keeping the address in the memory where some essential information is kept. The application of this type of data is of exceptional significance for the module described in Chapter 11:
p : ^word;