picture from S65More advanced RAM addressing modes (LS020)

by Christian Kranz, December 2006
Updated: December 8, 2006


Address Auto-Increment and Windowing

The display controller generates the addresses of the integrated display-RAM automatically. For that a window has to be defined in the display RAM. If data is written to the display RAM the data is displayed in that window. Depending on the address generating sequence the data is written in different modes to this window. This code shows how to write a rectangular bitmap image to the display memory. Pixes are drawn with textcolor, the background is drawn with backcolor. The image is stored as bit-array in the ascii_tab. array.

  // image size is 8x14
  uint8_t ascii_tab[14]={ 0x00, 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x66, 0x66, 0x66, 0xfc, 0x00, 0x00},

  for (h=0; h < CHAR_H; h++) // every column of the picture y-direction (mode 0)
  {
    ch=ascii_tab[h];	
    mask=0x80;
    for (p=0; p < CHAR_W; p++)  // write the pixels in x direction (mode 0)
    {
      if (ch & mask)  {
        lcd_wrdat16(textcolor);                
      }
      else  {
        lcd_wrdat16(backcolor);
      }
      mask=mask/2;
    }
  }

Address generating sequence

The order of the automatically generated addresses can be programmed. That means by using the same drawing routine the picture will appear in different orientations on the screen. For example the picture can be rotated by 90, 180 or 270 degree before it appears on the screen. The following pictues are showing all possible orientations.


addressing_mode_0 addressing_mode_1 addressing_mode_2 addressing_mode_0 addressing_mode_1 addressing_mode_2 addressing_mode_0 addressing_mode_1

The given programming sequences are using the definition of the picture writing routine above. Note that the width (CHAR_W) and the height (CHAR_H) have to be swapped, if the image is displayed in a 90 degree rotation. Inital, before starting data writing and address mode changing, the register have to be defined and the addressing mode has to be set using the following code sequence:

#define ASX 0x1200
#define ASY 0x1300
#define APX 0x1400
#define AEX 0x1500
#define AEY 0x1600
#define APY 0x1700

lcd_wrcmd16(0xEF80);
In the tabe you find the code for the mode change and the window definition code.
Mode Programming
normal mode
  lcd_wrcmd16(0x1800);   
  lcd_wrcmd16(ASX+x);
  lcd_wrcmd16(AEX+x+(CHAR_W-1));
  lcd_wrcmd16(ASY+y);
  lcd_wrcmd16(AEY+y+(CHAR_H-1));
y-axis symmetry (mirror image)
  lcd_wrcmd16(0x1801);
  lcd_wrcmd16(ASX+x);
  lcd_wrcmd16(AEX+x-(CHAR_W-1));
  lcd_wrcmd16(ASY+y);
  lcd_wrcmd16(AEY+y+(CHAR_H-1));
x-axis line symmetry (mirror image)
  lcd_wrcmd16(0x1802);
  lcd_wrcmd16(ASX+x);
  lcd_wrcmd16(AEX+x+(CHAR_W-1));  
  lcd_wrcmd16(ASY+y);
  lcd_wrcmd16(AEY+y-(CHAR_H-1));
180 degree rotation
  lcd_wrcmd16(0x1803);
  lcd_wrcmd16(ASX+x);
  lcd_wrcmd16(AEX+x-(CHAR_W-1));
  lcd_wrcmd16(ASY+y);
  lcd_wrcmd16(AEY+y-(CHAR_H-1));
mirror image, -90 degree
  lcd_wrcmd16(0x1804);
  lcd_wrcmd16(ASX+x);
  lcd_wrcmd16(AEX+x+(CHAR_W-1));
  lcd_wrcmd16(ASY+y);
  lcd_wrcmd16(AEY+y+(CHAR_H-1)); 
+90 degree
  lcd_wrcmd16(0x1805);
  lcd_wrcmd16(ASX+x);
  lcd_wrcmd16(AEX+x-(CHAR_H-1));  
  lcd_wrcmd16(ASY+y);
  lcd_wrcmd16(AEY+y+(CHAR_W-1)); 
-90 degree
  lcd_wrcmd16(0x1806);
  lcd_wrcmd16(ASX+x);
  lcd_wrcmd16(AEX+x-(CHAR_H-1));  
  lcd_wrcmd16(ASY+y);
  lcd_wrcmd16(AEY+y-(CHAR_W-1));
+90 degree (mirror image)
  lcd_wrcmd16(0x1807);
  lcd_wrcmd16(ASX+x);
  lcd_wrcmd16(AEX+x-(CHAR_H-1));  
  lcd_wrcmd16(ASY+y);
  lcd_wrcmd16(AEY+y-(CHAR_W-1));