11.07.2015 Views

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

C Language FeaturesSupported Data Types and Variablesconst char * cp = "hello " "world";assigned the pointer with the string "hello world".3.4.2 Bit Data Types and VariablesHI-TECH <strong>dsPIC</strong>Csupports bit integral types which can hold the values 0 or 1. Single bit variablesmay be declared using the keyword bit. bit objects declared within a function, for example:static bit init_flag;will be allocated in the bit-addressable psect bitbss, and will be visible only in that function. Whenthe following declaration is used outside any function:bit init_flag;init_flag will be globally visible, but located within the same psect.Bit variables cannot be auto or parameters to a function. A function may return a bit objectby using the bit keyword in the functions prototype in the usual way. The bit return value will bereturning in the carry flag in the status register.Bit variables behave in most respects like normal unsigned char variables, but they may onlycontain the values 0 and 1, and therefore provide a convenient and efficient method of storing booleanflags without consuming large amounts of internal RAM. It is, however, not possible to declaredpointers to bit variables or statically initialise bit variables.Operations on bit objects are performed using the single bit instructions (SET and CLR) whereverpossible, thus the generated code to access bit objects is very efficient.Note that when assigning a larger integral type to a bit variable, only the least-significant bit isused. For example, if the bit variable bitvar was assigned as in the following:int data = 0x54;bit bitvar;bitvar = data;it will be cleared by the assignment since the least significant bit of data is zero. If you want to seta bit variable to be 0 or 1 depending on whether the larger integral type is zero (false) or non-zero(true), use the form:bitvar = data != 0;31

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

Saved successfully!

Ooh no, something went wrong!