Académique Documents
Professionnel Documents
Culture Documents
Programming Language
(MikroC)
Programming
Language
.
In mikro c , it must know the data type to reserve
appropriate size for it
Ex :int temp ; >>>> type of variable is int
name of variable is temp
Ex : x=13
I will choose int x ; or char x ; or float x; ????
All cases are right , but char x is the best to save size for
the ram .
X= 1 ; >> I can use char x ; and int x ;
X=“1” ; >> I can use only char x as x here is equal to
character 1 .
Declarations
Every variable must be declared prior to being used for the first time in the
program. Since variables are stored in RAM memory, it is necessary to reserve
space for them (one, two or more bytes)
IF Statement
Case 1 :
if(condition ) {operation; }
Ex:
if (sw==1){led=1; }
Case 2 :
If (condition ) {operation 1 ;}
Else {operation 2 ;}
Ex:
if (sw==1){led=1; }
Else {led=0; }
Case 3 :
If(condition 1) {operation 1 ; }
Else if(condition 2) {operation 2 ; }
Else if(condition 3) {operation 3 ; }
.
.
Else {operation ; }
Ex :
If (temp>=20 && temp<25) {Lcd_Out(1, 3, “clod"); }
Else If (temp>=25 && temp<30) {Lcd_Out(1, 3, “normal"); }
Else If (temp>=30 && temp<=35) {Lcd_Out(1, 3, “hot "); }
Else {alarm=1 ; }
Switch case
Switch(condition){
Case condition 1 : operation 1 ; break ;
Case condition 2 : operation 2 ; break ;
Case condition 3: operation 3; break ;
Default : operation 4; }
Ex :
Switch(temp){
Case 37: lcd_out(1,1,”normal temperature “); break ;
Case 40: lcd_out(1,1,”hot temperature “); break ;
Default : lcd_out(1,1,” temperature is not critical “);
}
(B)Iteration Statement ( program loop )
For statement
EX:
Ex: For (i=0; i<=10; i*=2)
For (i=0 ; i<5 ; i++ ) { alarm ; }
{ led=1; used to repeat operation for
Delay_ms(1000); certain number of times
Led=0;
Delay_ms(1000);
}
any for loop with out condition is endless loop
EX:
For ( ; ; )
{
Alarm ;
}
While statement
while(condition ) EX:
{ operation ; } while (sw==1)
{ alarm=1; }
repeating the operation
While loop with out
till the condition is broke
condition is endless loop
When the condition
change it will go out of the EX:
loop . While (1 )
Check the condition first {alarm=1; }
before make the operation
For loop While loop
for(k=0 ; k<10 ;++k) K=o
{ alarm=1; While(k<10)
Dealy_ms(500); {alarm=1;
Alarm=0; Dealy_ms(500);
Delay_ms (500); Alarm=0;
} Delay_ms (500);
++k
}
Do statement
Do { EX:
Operation ; Do {
} Alarm;
While (condition) }
While {sw==1; }
Do the operation before
check the condition
(c) Unconditional flow control
Go to statement
Cause the program to jump to specified label
A label can be any alphanumeric character set starting with letter
and terminating with the colon (: ) character
EX :
k=0;
nn: k=1 ;
++k;
.
.
.
If (k>=5 ){ goto nn ;}
Break and continue statement