File: progmem.c

package info (click to toggle)
avr-libc 1%3A1.2.3-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,816 kB
  • ctags: 14,018
  • sloc: ansic: 17,998; asm: 5,024; sh: 2,778; makefile: 712; pascal: 441
file content (32 lines) | stat: -rw-r--r-- 792 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <avr/pgmspace.h>
#include <stdio.h>

/*
  You can put data in program memory,
  but reading this data allowed only through macro `pgm_read_byte'
*/



prog_char b[500] = {1,2,3,4,5}; /* This 8bit array in program memory. */

prog_int i[10] = {1,2,3,4,5}; /* This 16bit array in program memory. */

prog_long l[] = {1,2,3,4,5}; /* This 32bit array in program memory. */

prog_long_long ll[] = {1,2,3,4,5}; /* This 64bit array in program memory. */

char a[] PROGMEM = "This string in program memory too";

void
foo(void)
{
  char *p = PSTR ("This string in program memory");
  
  printf_P (PSTR ("This string in program memory"));
  
  char c = pgm_read_byte (p+5);	/* c = 's' */
  char aa = pgm_read_byte (&a[10]);	/* aa = 'g' */
  char bb = pgm_read_byte (&b[3]);	/* bb = 4 */
  
}