Control Programming C | Controller Circuit

Tuesday, December 21, 2010

Control Programming C



In last matter of we have tried studies about header, etc. Now we will to continue study about programming structure C. At this structure we study about reserved keywords, operator and ramification.



1. Operator.

Operator is an instruction of fit containing operator and operand. Operand is variable which is the part of statement while operator is a symbol expressing which operation will be done by operand. For example:

c = a+b

There is 3 type operand (a,b and c) and 2 operator (= and +).

Operator in programming of C divided to become 3 group;

a. Unary is operator operating on one operand, example; - nitrogen.

b. Binary is operator operating on two operand, example; a-n.

c. Nitrogen is operator operating with three or more operand, example; a= ( b*c)+d



2. Reserved Keywords.

Reserved keyword is glossary is standard which useless for label, identification or variable. Following the glossary;

break flash signed continue

bit float sizeof if

case for sfrb struct

char funcused sfrw default

const go to static inline

switch do int typedef

double interrupt union unsigned

eeprom long else register

void enum return volatile

extern short while

3. Branching

In doing ramification at programming of C there is 4 form of public.

a. if - then.

b. if - then - else

c. switch - case

d. switch - case - default

We will study one by one to the four instructions.



a. If - then

Form of generally is

if (condition) {

// statement

};

Mean was statement will be implemented if condition full filled. For example is

if (a<0x55)>

PORTC=0x55;

};

In this example PORTC will be sent data 0x55 (remembers in the form of heksa) if value a smaller than 0x50.

b. if – then – else

Form of generally is

if (condition) {

// statement a

}

Else {

// statement b

};

Mean is statement of a will be implemented if condition full filled and statement of b will be implemented if condition is not full filled. For example;

PORTC will be sent data 0x55 if value a smaller than 0x50 and PORTC will be sent data 0x44 if a>0x50.

if (a<0x50)>

// PORTC=0x55;

}

Else {

// PORTC=0x44

};

c. switch – case

Statement switch - case is applied if happened many ramifications. Writing structure in general is;

switch (expression) {

case constant 1:

Statement1

break;

case constant 2:

Statement 2

break;

case constantN:

StatementN

break;

}

For example:

switch (a) {

case 1:

PORTC=0x01;

break;

case 2:

PORTC=0x02;

break;

case3:

PORTC=0x04;

break;

}

PORTC will be sent data 0x01 if value a=1, PORTC will be sent data 0x02 if value a=2 and PORTC will be sent data 0x04 if value a=3.

d. switch – case – default.

Statement switch - case - default much the same to with switch - case. Becoming difference was there is default hence otherwise there is condition of case matching with expression switch hence would towards statement which there is part of default. This writing structure like under this;

switch ( expression) {

case constanta 1:

statement 1

break;

case konstanta 2:

statement 2

break;

case konstanta N:

statement N

break;

default:

statements;

}

For example:

switch (a) {

case 1:

PORTC=0x01;

break;

case 2:

PORTC=0x02;

break;

case 3:

PORTC=0x04;

break;

default:

PORTC=0xFF;

}

PORTC will be sent data 0x01 if value a=1, PORTC will be sent data 0x02 if value a=2 and PORTC will be sent the data 0x04 if value a=3 and if condition of case unmatched to expression hence statement at default will be implemented.

No comments:

Post a Comment