 |
ooPIC Programmer's Guide
Chapter 5 - Variables and Constants
|
|
|
|
What are Variables?
|
| | As discussed in Chapter 4 - Programming Fundamentals, Variables are used to store values. In most languages, variables are just a storage area that holds a single value. In the ooPIC languages, variables are objects. The advantage of doing so is that each Variable will have more properties than just its value. ooPIC provides you with several variables of different sizes and types of Variable Object to accommodate the needs of your program.
- Bit, Nibble, Byte, Char, Word, and Int.
- oBit, oNibble, oByte, oChar, oWord and oInt
- oPower, oHeading, and oDistance
- oBuffer
- oEEProm
- oRam
|
Byte and Word Variables
|
| | The Bit, Nibble, Byte, Char, Word, Int Variables are used to store and retrieve a single values. Each works approximately the same, but the magnitude of the Value is of different sizes.
| Type | Bit-Size | Magnitude | Memory Size |
| Bit | 1 | 1 | 1 |
| Nib | 4 | 15 | 1 |
| Byte | 8 | 255 | 1 |
| Char | 8 | -128 to 127 | 1 |
| Word | 16 | 65535 | 2 |
| Int | 16 | -32768 to 32767 | 2 |
|
Obit, oNibble, oByte and oWord Variable Objects
|
| | The oBit, oNibble, oByte, oChar, oWord and oInt Variable Objects are used to store values. Each of the different Variables types work approximately the same, but the magnitude of the Value property is of different sizes.
| | Object | Description | A1 | A2 | B1 | B2 | C1 |
 | oBit | Manages a 1-bit value with a range of 0 to 1. | x | x | x | x | x |
 | oNib | Manages a 4-bit value with a range of 0 to 15. | x | x | x | x | x |
 | oNibX | Manages a 4-bit signed value with a range of -8 to +7. | x |
 | oByte | Manages a 8-bit value with a range of 0 to 255. | x | x | x | x | x |
 | oChar | Manages a 8-bit signed value with a range of -128 to -127. | x | x | x |
 | oWord | Manages a 16-bit value with a range of 0 to 65,535. | x | x | x | x | x |
 | oInt | Manages a 16-bit signed value with a range of -32,768 to +32,767. | x | x | x |
 | oBuffer(1-32) | 32 Objects that Manage various sized data-buffer/string variable. | x | x | x | x | x |
Each Variable that is declared in an application will occupy an amount of memory within the ooPIC, and it is always best to use the least amount of memory possible in any application. Therefore, to select the type of Variable to use when needing to store a value, determine the highest value that will be needed and select the Variable type with the lowest Bit-size that will still be able to hold that highest value within its magnitude. These Variables have a oLogic NonZero property that indicates when the variable is not zero in value. The two Variables, oByte and oWord have a oLogic MSB property that indicates the state of the Most Significant Bit of the Value Property. The oChar and oInt objects use the MSB as a sign bit when moving between byte and word sizes and other mathematical functions. Thusly, they have a Negative property instead of a MSB property. The oBit Variable has the unique feature of having the compiler treat its value property as an oValue AND an oLogic property. To maintain backwards compatibility, if a oLogic pointer is used to point to the oBit Object or the oBit Object's Value property, the compiler will redirect the pointer automatically to the Data property and no error will occur. The oValue and oLogic properties can be linked in Virtual Circuits with oValue pointers and oLogic pointers. (See Chapter 8, "Virtual Circuits" For more information on linking oLogic properties to Virtual Circuits) |
oPower, oHeading and oDistance Variables
|
| | The oPower, oHeading, oDistance Variables are used to store and retrieve a single values. Each are URCP variables and are explained in detail in Chapter 15 - URCP.
| | Object | Description | A1 | A2 | B1 | B2 | C1 |
 | oDistance | Manages a URCP Distance value. | x | x | x |
 | oHeading | Manages a URCP Heading value. | x | x | x |
 | oPower | Manages a URCP Power value. | x | x | x |
|
oBuffer Variable Object
|
| | The oBuffer Variable is used to store a contiguous group of bytes. It can be defined with as little as 1 byte or as many as 32 bytes of storage.
| | Object | Description | A1 | A2 | B1 | B2 | C1 |
 | oBuffer(1-32) | 32 Objects that Manage various sized data-buffer/string variable. | x | x | x | x | x |
The Value property of the oBuffer Variable is a 1-byte value that access one of the elements in the contiguous group of bytes. The element that the Value property accesses is specified by the Location property. |
oEEProm Object
|
| | The oEEProm is a Co-Processor object but can also be thought of as a Variable as it is used to store or retrieve data from nonvolatile memory located within the EEPROM memory chips plugged into the E0 and E1 sockets on the ooPIC.
| | Object | Description | A1 | A2 | B1 | B2 | C1 |
 | oEEProm | Provides access to an I2C EEPROM memory. | x | x | x | x | x |
Care must be taken when using this Object, as it has the power to access and change the currently running application program. |
oRam Object
|
| | The oRam Variable is a PIC Hardware object but can also used to access any one of the 256 locations within the ooPIC object RAM space.
| | Object | Description | A1 | A2 | B1 | B2 | C1 |
 | oRAM | Provides access to the PIC's Random-Access-Memory. | x | x | x | x | x |
Extreme care must be taken when using this Object, as it has the power to access and change critical OS operations. |
Constants
|
| | A Constant is a value that is given a name. Like a Variable, a constant is referred to in code to retrieve its value. However, unlike a Variable, its value can only be defined once within the code and cannot be changed during program execution. |
|