PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Devices
Memory
SD Datalogger.c
1
/*
2
SD Datalogger.side
3
4
Application prompts you to type numbers into SimpleIDE Terminal, and
5
records to SD. Plays back all numbers after you type q and press Enter.
6
7
http://learn.parallax.com/propeller-c-simple-devices/sd-card-data
8
*/
9
10
#include "
simpletools.h
"
// Include simpletools header .
11
12
int
DO = 22, CLK = 23, DI = 24, CS = 25;
// SD card pins on Propeller BOE
13
14
int
main
(
void
)
// main function
15
{
16
print
(
"Enter several values.\n\n"
);
// User instructions
17
print
(
"To see logged values, press\n"
);
18
print
(
"Enter a second time.\n\n"
);
19
20
sd_mount
(DO, CLK, DI, CS);
// Mount SD card
21
22
FILE
* fp = fopen(
"test.txt"
,
"w"
);
// Open a file for writing
23
24
int
n, status;
// Number & status variables
25
while
(1)
// Endless loop
26
{
27
print
(
"> "
);
// User prompt
28
status =
scan
(
"%d"
, &n);
// Get number & status
29
if
(!status)
break
;
// Status 0? Break out of loop
30
fwrite(&n, 4, 1, fp);
// Write number to SD card
31
}
32
fclose(fp);
// Close the file
33
34
print
(
"\nYou entered:\n"
);
// List heading
35
36
fp = fopen(
"test.txt"
,
"r"
);
// Open a file for writing
37
while
(1)
38
{
39
status = fread(&n, 4, 1, fp);
// Read from SD & get status
40
if
(!status)
break
;
// If no more, break loop
41
print
(
"n = %d\n"
, n);
// Display value
42
}
43
fclose(fp);
// Close the file
44
}
45
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
sd_mount
int sd_mount(int doPin, int clkPin, int diPin, int csPin)
Mount an SD card with the minimal 4-pin interface. For Parallax Learn Site examples,...
Definition:
sddriverconfig.c:7
_FILE
Definition:
stdio.h:62
scan
int int scan(const char *fmt,...) __attribute__((format(printf
Convert formatted simple terminal input to the "..." args. The input is limited to 256 bytes.
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17