05.08.2014 Views

1 C Programming for Embedded Systems. Data RAM Pointer Types ...

1 C Programming for Embedded Systems. Data RAM Pointer Types ...

1 C Programming for Embedded Systems. Data RAM Pointer Types ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

P. Klimo Sep 2010<br />

Pre-Processor:<br />

#define HERE_WE_GO<br />

# ifdef HERE_WE_GO<br />

/* Do something */<br />

#else<br />

static bank1 unsigned char fred; // fred allocated to bank 1<br />

/* do something else */<br />

#endif<br />

static bank3 unsigned char fred; // fred allocated to bank 3<br />

Example of a Simple Source File:<br />

const int a = 66;<br />

int c = 23;<br />

int myFunc( const int x, int y){<br />

static int count =0;<br />

int c;<br />

c = x + y + count++;<br />

// Define integer 66 in program ROM<br />

// Initialize 2 bytes in the general <strong>RAM</strong><br />

// Define a function in the general <strong>RAM</strong><br />

// Private variable placed in the general <strong>RAM</strong><br />

// Automatic variable defined on the myFunc stack<br />

// Will increment count between calls<br />

return c;<br />

}<br />

void main(){<br />

int b;<br />

// The main function executes after initialization<br />

// Automatic variable defined on main’s stack<br />

while(1){<br />

b = myFunc(a, c);<br />

// Infinite Loop calls repeatedly calls myFunc<br />

}<br />

}<br />

4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!