Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Some problem understanding the code

Status
Not open for further replies.

saur

Member level 2
Joined
Feb 23, 2012
Messages
45
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,621
Code:
#define SDRAM_BASE_ADDR 0x28000000

static uint16_t *fb  = (uint16_t *)SDRAM_BASE_ADDR;

void GLCD_DrawChar (unsigned int x, unsigned int y, unsigned int cw, unsigned int ch, unsigned char *c) {
  unsigned int i, j, k, pixs;

  k  = (cw + 7)/8;

  if (k == 1) {
    for (j = 0; j < ch; j++) {
      pixs = *(unsigned char *)c;
      c += 1;
    
      for (i = 0; i < cw; i++) {
       #if (LANDSCAPE == 0)
        fb[(y+j)*PHYS_XSZ + (x+i)] = Color[(pixs >> i) & 1];
       #else
        fb[(x+i)*PHYS_XSZ + (y+j)] = Color[(pixs >> i) & 1];
       #endif
      }
    }
  }
  else if (k == 2) {
    for (j = 0; j < ch; j++) {
      pixs = *(unsigned short *)c;
      c += 2;
      
      for (i = 0; i < cw; i++) {
       #if (LANDSCAPE == 0)
        fb[(y+j)*PHYS_XSZ + (x+i)] = Color[(pixs >> i) & 1];
       #else
        fb[(x+i)*PHYS_XSZ + (y+j)] = Color[(pixs >> i) & 1];
       #endif
      }
    }
  }
}

In the above code the only problem I'm facing is that, fb has been defined as a pointer. Then what does the code
Code:
 fb[(y+j)*PHYS_XSZ+(x+i)]
mean?

Here PHYS_XSZ has been defined as 240. I also understand what
Code:
Color[(pixs>>i)&1]
means.

Just help mw with the fb part of the code.

Thanks
 

A pointer can be addressed in different ways

Code C - [expand]
1
2
*( fb + i )
    fb[ i ] //are same

 
  • Like
Reactions: saur

    saur

    Points: 2
    Helpful Answer Positive Rating
This code used to display a character at the position x,y.
LCD has matrix COLxROW RAM to store character (all characters are display on LCD).
So function will saved the character to RAM of LCD at position x,y.
PHYS_XSZ is number of characters on a line.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top