Tuesday, July 3, 2012

PIC16 C Program Basics Variables

● Variables
● Looping
● Decisions

The purpose of an embedded program is to read in data or control inputs, process them, and operate the outputs as required. Input from parallel, serial, and analog ports are held in the file registers for temporary storage and processing; and the results are output later on, as data or a signal. The program C in Pic for processing the data usually contains repetitive loops and conditional branching, which depends on an input or calculated value.

Variables with Pic C Programming


Most programs need to process data in some way, and named variables are needed to hold their values. A variable name is a label attached to the memory location where the variable value is stored. When working in assembly language, a register label acts as the variable name and has to be assigned explicitly. In Pic C Programming, the variable label is automatically assigned to the next available location or locations (many variable types need more than 1 byte of memory). The variable name and type must be declared at the start of the program block, so that the compiler can allocate a corresponding set of locations. Variable values are assumed to be in decimal by default; so if a value is given in hexadecimal in the source code, it must be written with the prefix 0x, so that 0xFF represents 255, for example. A variable called x is used in the program in Listing 2.2 , VARI.C. Longer labels are sometimes preferable, such as “ output_value, ” but spaces are not allowed. Only alphanumeric characters (a–z, A–Z, 0–9) and underscore, instead of space, can be used. By default, the CCS compiler is not case sensitive, so ‘a’ is the same as ‘A’ (even though the ASCII code is different). A limited number of key words in C, such as main and include , must not be used as variable names.
PIC16 C Programming
The variable x is an 8-bit integer with whole number values 0–255 10 . The value in binary can be seen when it is output at an 8-bit port. Generally, C integers (int) are stored as 16- bit values, but Pic C Programming  for 8-bit microcontrollers uses a default 8-bit integer format. In Program VARI.C, an initial value is assigned to the variable (99), which is then used in the output function. The point here is that the variable value can now be modified without having to change the output function call itself.
In the program C With Pic, an 8-bit variable x is declared and assigned a value 99 using the “ equals ”
operator. It is then output to Port D using the standard output function.

No comments:

Post a Comment