PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Badge
05 EEPROM Data Storage
06 Store and Retrieve Data.c
1
/*
2
Store and Retrieve Data.c
3
Programs can also use structures to organize and manipulate data. So,
4
here is an exaample of storing and retrieving data with structures.
5
*/
6
7
#include "
simpletools.h
"
// Include simpletools library
8
#include "
badgetools.h
"
// Include badgetools library
9
10
typedef
struct
info_st
// Structure for the data
11
{
12
int
num;
13
char
name[32];
14
}
info
;
15
16
info
fred = { 123,
"Fred Flintstone"
};
// Declare fred & wilma
17
info
wilma = { 456,
"Wilma Flintstone"
};
18
19
info
their;
// For getting values from EEPROM
20
21
int
exist, contacts;
22
23
void
main
()
24
{
25
badge_setup
();
26
text_size
(
SMALL
);
27
oledprint
(
"Use SimpleIDE\nTerminal."
);
28
29
// Check if fred's info is already in EEPROM. If not
30
// eeprint it.
31
exist =
eeprinted
(
"%03d\n%32s\n"
, fred.num, fred.name);
32
if
(!exist)
33
eeprint
(
"%03d\n%32s\n"
, fred.num, fred.name);
34
35
// Repeat for wilma
36
exist =
eeprinted
(
"%03d\n%32s\n"
, wilma.num, wilma.name);
37
if
(!exist)
38
eeprint
(
"%03d\n%32s\n"
, wilma.num, wilma.name);
39
40
//contacts_displayAll();
41
42
// Retrieve and display the data
43
contacts =
contacts_count
();
44
for
(
int
record = 0; record < contacts; record++)
45
{
46
eescan
(record,
"%d%s"
, &their.num, &their.name);
47
print
(
"record %d = %d, %s\n"
, record, their.num, their.name);
48
}
49
}
eeprinted
int eeprinted(const char *fmt,...)
Can be called before storing a record with eeprint. Example: if(!eeprinted("Hello EEPROM") eeprint("H...
Definition:
peb_eeprinted.c:12
info_st
Definition:
06 Store and Retrieve Data.c:10
eeprint
int eeprint(const char *fmt,...)
Use to store strings to EEPROM in a manner similar to displaying combinations of strings and variable...
Definition:
peb_eeprint.c:12
contacts_count
int contacts_count()
Find out how many contacts are currently stored in EEPROM. This is useful for setting up a loop to fe...
Definition:
peb_contacts_count.c:11
eescan
int eescan(int recIdx, const char *fmt,...)
Use to retrieve strings to EEPROM in a manner similar to retrieving strings that represent combinatio...
Definition:
peb_eescan.c:12
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
main
int main(void)
Definition:
GraphicsTest.c:20
oledprint
int oledprint(const char *fmt,...)
Use to display strings on the oLED display in a manner similar to displaying combinations of strings ...
Definition:
peb_text.c:4
badge_setup
int badge_setup(void)
Set up all available badge drivers. Call this function at the start of any given program to allow acc...
Definition:
badgealpha.c:29
badgetools.h
This library provides convenient functions for a variety of Parallax eBadge operations.
text_size
void text_size(int size)
Set the text size to either 32x16 pixel (LARGE) or 7x5 (SMALL) characters. Examples: text_size(LARGE)...
Definition:
oled_text_size.c:7
SMALL
#define SMALL
For setting oLED character size to 7x5 pixels. Example: text_size(SMALL).
Definition:
badgetools.h:200
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17