Monday, April 14, 2008

Addition to variables

Thanks 9W2GU on the extra notes. I have made some addition to your addition, as marked by the green text.

Some extra notes on variables. Variables cannot start with numbers special characters. Only with underscore "_" and characters. Variables in C can be up to 32 characters long. It is good practice to give your variables meaningful name. Example, if you need a variable for voltage, define the variable as :-

signed double Voltage;

Defining it as "x" for example, will work too, but later you may have problems debugging your code.

Case Sensitivity

mikroC identifiers are not case sensitive at present, so that Sum, sum, and suM represent an equivalent identifier. However, future versions of mikroC will offer the option of activating/suspending case sensitivity. The only exceptions at present are the reserved words main and interrupt which must be written in lowercase.

TRISA=0b00110011; is the same as TrisA=0b00110011;

or

portb=128;
PortB=128;

Variables as explained by Basir hold values that may and usually changes. Another type of variable type is a constant, where it's value does not change or rarely changes. A constant is not a variable, it cannot change it's value. If you try to assign or change it's value apart elsewhere in your program, MikroC will give you an error. Variables use RAM space whereas Constants use ROM. Take note that MikroC is an optimizing compiler, i.e., it will remove redundant codes, variables and constants whenever possible. Make it a practice to use constants instead of hard-coded numbers. It will helps in two ways... it prevent unintentionally changing the value of a constant and if the constant is used in several places, you only need to change once at the declaration line.

example:

const double PI = 3.1415;

const byte HTab = 0x09;


HTab is now set to horizantal tab. And can be used like:-

Lcd_Out(HTab+"Hello, World");

Will output a tab and Hello, World on your LCD.


No comments: