~ubuntu-branches/ubuntu/breezy/avr-libc/breezy

« back to all changes in this revision

Viewing changes to doc/examples/progmem.c

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2002-04-15 14:53:38 UTC
  • Revision ID: james.westby@ubuntu.com-20020415145338-c8hi0tn5bx74w7o3
Tags: upstream-20020203
ImportĀ upstreamĀ versionĀ 20020203

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <progmem.h>
 
2
 
 
3
/*
 
4
  You can put data in program memory,
 
5
  but reading this data allowed only through macro `PRG_RDB'
 
6
*/
 
7
 
 
8
 
 
9
 
 
10
prog_char b[500] = {1,2,3,4,5}; /* This 8bit array in program memory. */
 
11
 
 
12
prog_int i[10] = {1,2,3,4,5}; /* This 16bit array in program memory. */
 
13
 
 
14
prog_long l[] = {1,2,3,4,5}; /* This 32bit array in program memory. */
 
15
 
 
16
prog_long_long ll[] = {1,2,3,4,5}; /* This 64bit array in program memory. */
 
17
 
 
18
char a[] __attribute__ ((progmem)) = "This string in program memory too";
 
19
 
 
20
void
 
21
foo(void)
 
22
{
 
23
  char *p = PSTR ("This string in program memory");
 
24
  
 
25
  printf (PSTR ("This string in program memory")); /* special version of
 
26
                                                      printf needed ! */
 
27
  
 
28
  char c = PRG_RDB (p+5);       /* c = 's' */
 
29
  char aa = PRG_RDB (&a[10]);   /* aa = 'g' */
 
30
  char bb = PRG_RDB (&b[3]);    /* bb = 4 */
 
31
  
 
32
}