04.03.2013 Views

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Variables<br />

Structure - Variables<br />

Variables are used to store values used in your program. The values stored will typically change<br />

during program run time. What was stored at the start of your program in a given variable can change<br />

by the time your program stops running.<br />

To use a variable it must be defi ned in your program so <strong>Basic</strong> <strong>Micro</strong> <strong>Studio</strong> knows to set aside the<br />

required amount of space in RAM. The ATOM line is 32 bit, so variables can be from 1 bit to 32 bits.<br />

Typically most microcontroller systems are limited to 16 bits.<br />

When creating a variable you specify what type of variable you will need in your program. You can<br />

defi ne as many variables as you want. The only limiting factor is the amount of RAM available which<br />

varies for each ATOM type.<br />

Variable Types<br />

Type Bits Value Range<br />

Bit 1 1 or 0<br />

Nib 4 0 to 15<br />

Byte 8 0 to 255<br />

SByte 8 -128 to +127<br />

Word 16 0 to 65,535<br />

SWord 32 -32,768 to +32,767<br />

Long 32 0 to 4,294,967,295<br />

SLong 32 -2,147,483,647 to +2,147,483,648<br />

Float 32 ± 2.0 EXP -126 to ± 2.0 EXP 127<br />

Pointer 32 0 to 4,294,967,295<br />

Location<br />

Variables should be defi ned in the beginning of your program if you want to access the variable<br />

anywhere from your program. Where the variable is defi ned dictates where the variables can be used.<br />

Variables must be defi ned before they can be used.<br />

Signed<br />

Variables can be signed. This is useful in many applications. A simple example would be controlling<br />

a DC motor. A negative number can indicate one direction of spin, 0 can be stop and a positive value<br />

can be the opposite direction of spin using one variable. Signed variables are created using Sbyte,<br />

Sword and Slong<br />

32

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!