ATMEL's AVR ....
.... and C-Compiler



If  you use a C Compiler for writting AVR Programms, you can make many mistakes.
Sometimes, you can
save many Flash Programm Memory:

Here is an example:
This code is for setting the Cursor on a LCD

// *************************************************** //
// *** Position the LCD cursor at "row", "column".                        *** //
// *************************************************** //
void LCD_Cursor (char row, char column)
{
   switch (row)
 {
     case 1: LCD_WriteControl (0x80 + column - 1); break;
     case 2: LCD_WriteControl (0x80+ 0x40 + column - 1); break;
     default: break;
  }
}

This piece of code needs 48 Byte Code !
 
 

Now, the switch command will be replaced by if statements:
{
if (row==1)
 { LCD_WriteControl (0x80 + column - 1);}
 if (row==2)
 { LCD_WriteControl (0x80 + 0x40 + column - 1);}
}

This piece of code needs 34 Byte Code.This is 14 Bytes less than Code 1 !
 

In Code 3, the constant summation is replaced by a single constant:

{
if (row==1)
 { LCD_WriteControl (0x7F + column );}
if (row==2)
 { LCD_WriteControl (0xBF  + column );}
}

Now, this code needs only 30 Bytes of Code (saved 4 Bytes again).
 

If you have only a 2 Row Display, you can save Code again:

{
if (row==1)
 { LCD_WriteControl (0x7F + column );}
 else
 { LCD_WriteControl (0xBF  + column );}
}

This is the smallest version. It needs only 28 byte of Code !
This is (approx) the half than the first Code.
 
 

Wondering why code seems never to be executed:

If  you have declared a function with no input and output, like this:

void enable_bit()
{
...
}

and you call it like this:

enablebit;

the funtion will never be executed !

You had to call it this way:

enablebit();

!!!!!! Don't worry !!!!
 
 
 

To be continued................
 
 
 
 
 
 
 
 
 
 

HOME