by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

Committer:
robt
Date:
Fri May 24 22:11:47 2013 +0000
Revision:
0:965fcc0691fd
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:965fcc0691fd 1 /* Program Example 10.1: read and write char data bytes
robt 0:965fcc0691fd 2 */
robt 0:965fcc0691fd 3 #include "mbed.h"
robt 0:965fcc0691fd 4 Serial pc(USBTX,USBRX); // setup terminal link
robt 0:965fcc0691fd 5 LocalFileSystem local("local"); // define local file system
robt 0:965fcc0691fd 6 int write_var;
robt 0:965fcc0691fd 7 int read_var; // create data variables
robt 0:965fcc0691fd 8
robt 0:965fcc0691fd 9 int main ()
robt 0:965fcc0691fd 10 {
robt 0:965fcc0691fd 11 FILE* File1 = fopen("/local/datafile.txt","w"); // open file
robt 0:965fcc0691fd 12 write_var=0x23; // example data
robt 0:965fcc0691fd 13 fputc(write_var, File1); // put char (data value) into file
robt 0:965fcc0691fd 14 fclose(File1); // close file
robt 0:965fcc0691fd 15
robt 0:965fcc0691fd 16 FILE* File2 = fopen ("/local/datafile.txt","r"); // open file for reading
robt 0:965fcc0691fd 17 read_var = fgetc(File2); // read first data value
robt 0:965fcc0691fd 18 fclose(File2); // close file
robt 0:965fcc0691fd 19 pc.printf("input value = %i \n",read_var); // display read data value
robt 0:965fcc0691fd 20 }
robt 0:965fcc0691fd 21