lab 7

Dependencies:   SDFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
jedh
Date:
Sat Dec 10 21:08:30 2016 +0000
Commit message:
jgk

Changed in this revision

DS1307/ds1307.cpp Show annotated file Show diff for this revision Revisions of this file
DS1307/ds1307.h Show annotated file Show diff for this revision Revisions of this file
EE3420_time.h Show annotated file Show diff for this revision Revisions of this file
Freedom_headers.h Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
simple_fifo.h Show annotated file Show diff for this revision Revisions of this file
software_osc.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1307/ds1307.cpp	Sat Dec 10 21:08:30 2016 +0000
@@ -0,0 +1,288 @@
+#include "ds1307.h"
+
+DS1307::DS1307(PinName sda, PinName scl ) : ds1307i2c(sda,scl) {
+    ds1307i2c.frequency(DS1307_freq);
+}
+
+DS1307::~DS1307() {
+}
+
+int DS1307::read( int addr, int quantity, char *data) {
+    // note the char array at data must contain 63 locations or unpredictable behavior will happen
+    // addr must be 0 - 62 as the 64th(or 63rd as indexed from 0) ram location is clobered in this method of access
+    // quantity must be 1 - 63 as the 64th ram location is clobered in this method of access
+    int test = 0 ;
+    char temp_data[65];
+
+    if (addr > DS1307_lastram) return (1);  // fail because address greater then what chip has to read from
+    if (addr < 0 ) return (1);     // fail because address less then 0 is not available
+    if (quantity > DS1307_lastreg) return (1);  // fail because quantity greater then what can be read
+    if ((addr + quantity) > DS1307_lastreg ) return (1);    // fail because cant read past reg 63
+    if ( quantity == 0 ) return (1);    // fail because zero quantity wanted
+    temp_data[0] = DS1307_lastreg ;  // note this ram location is used to set the addressing pointer in DS1307
+    temp_data[1] = 0;    // just junk to clober this address with
+    test = ds1307i2c.write(DS1307_addr,temp_data,2);
+    if (test == 1) return (1);  // the write operation failed
+    ds1307i2c.stop();   // now the DS1307 is pointing to the first register
+    if ( addr != 0 ) test = ds1307i2c.read(DS1307_addr,temp_data,addr);  // now the DS1307 address pointer is pointing to correct address
+    if (test == 1) return (1);  // the read operation failed
+    test = ds1307i2c.read(DS1307_addr,data,quantity);   // read the DS1307 registers now
+    if (test == 1) return (1);  // read operation failed
+    return(0);  // looks like the data read was good
+}
+
+int DS1307::read(int addr, int *data) {
+    // addr must be 0 - 62 as the 64th(or 63rd as indexed from 0) ram location is clobered in this method of access
+    int test = 0;
+    char temp_data[65];
+    test = DS1307::read(addr, 1, &temp_data[0]);
+    if (test == 1) return(1);   // fail because read to DS1307 failed
+    *data = (int)temp_data[0];      // returing the read data by pointer
+    return (0);                     // the single read is successfull
+}
+
+int DS1307::write( int addr, int quantity, char *data) {
+    // note the char array at data must contain 63 locations or unpredictable behavior will happen
+    // addr must be 0 - 62 as the 64th(or 63rd as indexed from 0) ram location is clobered in this method of access
+    // quantity must be 1 - 63 as the 64th ram location is clobered in this method of access
+    int test = 0 ;
+    char temp_data[65] ;
+    int loop = 0;
+
+    if (addr > DS1307_lastram) return (1);      // fail because address greater then what chip has to read from
+    if (addr < 0 ) return (1);      // fail because address less then 0 is not available
+    if (quantity > DS1307_lastreg) return (1);  // fail because quantity greater then what can be read
+    if (quantity == 0) return (1);  // fail because zero quantity is wanted
+    if ((addr + quantity) > DS1307_lastreg ) return (1);    // fail because cant read past reg 63
+
+    temp_data[0] = (char)addr;
+    for ( ; loop < quantity ; loop++ ) {
+        temp_data[loop+1] = *(data + loop);
+    }
+    test = ds1307i2c.write(DS1307_addr, temp_data, (quantity + 1));
+    ds1307i2c.stop();
+    return(test);   // 0 for success 1 for failure to write
+}
+
+int DS1307::write( int addr, int data ) {
+    // addr must be 0 - 62 as the 64th(or 63rd as indexed from 0) ram location is clobered in this method of access
+    int test = 0 ;
+    char temp_data[2] ;
+
+    temp_data[0] = (char)addr;
+    temp_data[1] = (char)data;
+    if (addr > DS1307_lastram) return (1);      // fail because address greater then what chip has to read from
+    if (addr < 0 ) return (1);      // fail because address less then 0 is not available
+    test = ds1307i2c.write(DS1307_addr, temp_data, 2);
+    ds1307i2c.stop();
+    return(test);
+}
+
+int DS1307::start_clock(void) {           // start the clock
+    int test = 0;
+    int junk = 0;
+
+    test = DS1307::read(DS1307_sec, &junk);
+    if (test == 1) return(1);       // fail because read to DS1307 failed
+    junk = ( 0x7F & junk);              // basicaly i mask bit 8 to set it to zero
+    test = DS1307::write(DS1307_sec,junk);        // now write the seconds back to register and because bit 8 is zero this starts clock.
+    if (test == 1) return(1);        // fail because read to DS1307 failed
+    return(test);                        //
+}
+
+int DS1307::stop_clock(void) {           // stop clock
+    int test = 0;
+    int junk = 0;
+
+    test = DS1307::read(DS1307_sec, &junk);
+    if (test == 1) return(1);        // fail because read to DS1307 failed
+    junk = ( 0x7F & junk);              // basicaly i mask bit 8 to set it to zero but keep all other bits
+    junk = ( 0x80 | junk);              // basicaly i mask bit 8 to set it to one
+    test = DS1307::write(DS1307_sec,junk);        // now write the seconds back to register and because bit 8 is one this starts clock.
+    if (test == 1) return(1);        // fail because read to DS1307 failed
+    return(test);                        //
+}
+
+int DS1307::twelve_hour(void) {           // set 12 hour mode
+    int test = 0;
+    int junk = 0;
+
+    test = DS1307::read(DS1307_hour, &junk);
+    if (test == 1) return(1);       // fail because read to DS1307 failed
+    if ((junk & 0x40) == 0x40) return(0);         // return because 12 mode is active now all done!
+
+    junk = ( junk & 0x3F);              // only use 24 hour time values
+    if (junk == 0x00)
+        junk = 0x12;
+    else if (junk >= 0x13)
+        if (junk < 0x20) {
+            junk = junk - 0x12;
+            junk = (junk | 0x20);   // add back the pm indicator
+        } else
+            switch (junk) {
+                case 0x20:
+                    junk = 0x28;
+                    break;
+                case 0x21:
+                    junk = 0x29;
+                    break;
+                case 0x22:
+                    junk = 0x30;
+                    break;
+                case 0x23:
+                    junk = 0x31;
+                    break;
+            }
+
+    test = DS1307::write(DS1307_hour,(0x40 | junk));    // set bit 6 with the new 12 hour time converted from the 24 hour time
+    if (test == 1) return(1);       // fail because read to DS1307 failed
+
+    return(0);
+}
+
+int DS1307::twentyfour_hour(void) {     // set 24 hour mode
+    int test = 0;
+    int junk = 0;
+
+    test = DS1307::read(DS1307_hour, &junk);
+    if (test == 1) return(1);       // fail because read to DS1307 failed
+    if ((junk & 0x40) == 0) return(0);         // return because 24 mode is active now all done!
+
+    junk = (junk &  0xBF);              // get value bits and am/pm indicator bit but drop 12/24 hour bit
+
+    if (junk > 0x12)
+        if ( junk <= 0x27 )
+            junk = junk - 0x0E;
+        else
+            junk = junk - 0x08;
+
+    test = DS1307::write(DS1307_hour,( 0xBF & junk));   // clear bit 6 and set the new 24 hour time converted from 12 hour time
+    if (test == 1) return(1);       // fail because read to DS1307 failed
+
+    return(0);
+}
+
+int DS1307::settime(int sec, int min, int hour, int day, int date, int month, int year) {        // to set the current time and start clock
+    // sec = 0 to 59, min = 0 to 59, hours = 0 to 23 ( 24 hour mode only ), day = 1 to 7 ( day of week ), date = 1 to 31, month = 1 to 12, year 0 to 99 ( this is for 2000 to 2099)
+    DS1307::stop_clock();
+
+    if (1 == DS1307::hilow_check( 59, 0, sec)) {
+        return(1);    // failed because recieved value is not in bounds
+    } else {
+        if (1 == (DS1307::write(DS1307_sec,DS1307::dectobcd(sec)))) return(1);    // failed to write for some reason
+    }
+
+    if (1 == DS1307::hilow_check( 59, 0, min)) {
+        return(1);    // failed because recieved value is not in bounds
+    } else {
+        if (1 == (DS1307::write(DS1307_min,DS1307::dectobcd(min)))) return(1);    // failed to write for some reason
+    }
+
+    if (1 == DS1307::twentyfour_hour()) return(1);                                      // failed to set 24 hour format
+    if (1 == DS1307::hilow_check( 23, 0, hour)) {                                       // note setting 24 hour mode befor and after writing the hour value ensures 24 hour mode is set
+        return(1);    // failed because recieved value is not in bounds
+    } else {
+        if (1 == (DS1307::write(DS1307_hour,DS1307::dectobcd(hour)))) return(1);    // failed to write for some reason
+    }
+    if (1 == DS1307::twentyfour_hour()) return(1);                                      // failed to set 24 hour format
+
+    if (1 == DS1307::hilow_check( 7, 1, day)) {
+        return(1);    // failed because recieved value is not in bounds
+    } else {
+        if (1 == (DS1307::write(DS1307_day,DS1307::dectobcd(day)))) return(1);    // failed to write for some reason
+    }
+
+    if (1 == DS1307::hilow_check( 31, 1, date)) {
+        return(1);    // failed because recieved value is not in bounds
+    } else {
+        if (1 == (DS1307::write(DS1307_date,DS1307::dectobcd(date)))) return(1);    // failed to write for some reason
+    }
+
+    if (1 == DS1307::hilow_check( 12, 1, month)) {
+        return(1);    // failed because recieved value is not in bounds
+    } else {
+        if (1 == (DS1307::write(DS1307_month,DS1307::dectobcd(month)))) return(1);    // failed to write for some reason
+    }
+
+    if (1 == DS1307::hilow_check( 99, 0, year)) {
+        return(1);    // failed because recieved value is not in bounds
+    } else {
+        if (1 == (DS1307::write(DS1307_year,DS1307::dectobcd(year)))) return(1);    // failed to write for some reason
+    }
+
+    DS1307::start_clock();
+    return (0);             // time is now set
+}
+
+int DS1307::gettime(int *sec, int *min, int *hour, int *day, int *date, int *month, int *year) { // to get the current time information
+    // sec = 0 to 59, min = 0 to 59, hours = 0 to 23 ( 24 hour mode only ), day = 1 to 7 ( day of week ), date = 1 to 31, month = 1 to 12, year 0 to 99 ( this is for 2000 to 2099)
+    if (1 == DS1307::read(DS1307_sec,sec)) return(1);       // failed to read for some reason
+    *sec = (*sec & 0x7F );                                  // drop the clock start stop bit
+    *sec = DS1307::bcdtodec( *sec);                         // bcd is now dec value
+
+    if (1 == DS1307::read(DS1307_min,min)) return(1);       // failed to read for some reason
+    *min = (*min & 0x7F );                                  // drop bit 7 because it should be 0 anyways
+    *min = DS1307::bcdtodec( *min);                         // bcd is now dec value
+
+    if (1 == DS1307::read(DS1307_hour,hour)) return(1);     // failed to read for some reason
+    if ((*hour & 0x40) == 0x40) {                           // if true then 12 hour mode is set currently  so change to 24 hour, read value, and return to 12 hour mode
+        if (1 == DS1307::twentyfour_hour()) return(1);          // failed to set 24 hour mode for some reason
+        if (1 == DS1307::read(DS1307_hour,hour)) return(1);     // failed to read for some reason
+        *hour = (*hour & 0x3F );                                // drop bit 7 & 6 they are not used for 24 hour mode reading
+        *hour = DS1307::bcdtodec( *hour);                       // bcd is now dec value
+        if (1 == DS1307::twelve_hour()) return(1);              // failed to return to 12 hour mode for some reason
+    } else {                                                     // in 24 hour mode already so just read the hour value
+        if (1 == DS1307::read(DS1307_hour,hour)) return(1);    // failed to read for some reason
+        *hour = (*hour & 0x3F );                                // drop bit 7 & 6 they are not used for 24 hour mode reading
+        *hour = DS1307::bcdtodec( *hour);                       // bcd is now dec value
+    }
+
+    if (1 == DS1307::read(DS1307_day,day)) return(1);       // failed to read for some reason
+    *day = (*day & 0x07 );                                  // drop the non used bits
+    *day = DS1307::bcdtodec( *day);                         // bcd is now dec value
+
+    if (1 == DS1307::read(DS1307_date,date)) return(1);     // failed to read for some reason
+    *date = (*date & 0x3F );                                // drop bit 6 and 7 not used for date value
+    *date = DS1307::bcdtodec( *date);                       // bcd is now dec value
+
+    if (1 == DS1307::read(DS1307_month,month)) return(1);   // failed to read for some reason
+    *month = (*month & 0x1F );                              // drop bit 5, 6 and 7 not used for month value
+    *month = DS1307::bcdtodec( *month);                     // bcd is now dec value
+
+    if (1 == DS1307::read(DS1307_year,year)) return(1);     // failed to read for some reason
+    *year = DS1307::bcdtodec( *year);                       // bcd is now dec value
+
+    return (0);                                             // data returned is valid
+}
+
+
+int DS1307::dectobcd( int dec) {
+    int low = 0;
+    int high = 0;
+
+    high = dec / 10;                // this gives the high nibble value
+    low = dec - (high * 10);        // this gives the lower nibble value
+    return ((high *16) + low);      // this is the final bcd value but in interger format
+}
+
+int DS1307::bcdtodec( int bcd) {
+    int low = 0;
+    int high = 0;
+
+    high = bcd / 16;
+    low = bcd - (high * 16);
+    return ((high * 10) + low);
+
+}
+
+int DS1307::hilow_check( int hi, int low, int value) {
+    if ((value >= low)&(value <= hi))
+        return(0);              // value is equal to or inbetween hi and low
+    else
+        return(1);              // value is not equal to or inbetween hi and low
+}
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1307/ds1307.h	Sat Dec 10 21:08:30 2016 +0000
@@ -0,0 +1,224 @@
+#ifndef DS1307_H
+#define DS1307_H
+
+/* mbed Dallas Semiconductor DS1307 serial real time clock
+* Copyright (c) 2012 pksmith
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+*/
+
+#include "mbed.h"
+
+#define DS1307_addr 0xD0    // this is fixed by Dallas
+#define DS1307_freq 100000  // this is the Dallas spec for operating i2c for this device
+#define DS1307_sec 0x00     // seconds
+#define DS1307_min  0x01    // min
+#define DS1307_hour 0x02    // hours
+#define DS1307_day  0x03    // day
+#define DS1307_date 0x04    // date
+#define DS1307_month 0x05   // month
+#define DS1307_year 0x06    // year
+#define DS1307_sqrout 0x07  // square output register
+#define DS1307_ramstart 0x08    // register address that ram starts at
+#define DS1307_lastreg 0x3F // this is the last register in the device (note also this register is used to address everything so it gets clobbered)
+#define DS1307_lastram 0x3E // last usable ram by this class as the lastreg is clobbered by code for normal operation
+
+/** DS1307 control and communication class using mbed's i2c class
+ *
+ * Example:
+ * @code
+ * // show how the DS1307 class works
+ * #include "ds1307.h"
+ * #include "mbed.h"
+ *
+ * Serial pc(USBTX, USBRX); // tx, rx  for debug and usb pc comunications
+ *
+ * DS1307 my1307(p9,p10); // start DS1307 class and give it pins for connections of the DS1307 device
+ *
+ * int sec = 0;
+ * int min = 0;
+ * int hours = 0;
+ * int day = 0;
+ * int date = 0;
+ * int month = 0;
+ * int year = 0;
+ *
+ * void test_rw(int test) {
+ *     if (test == 0) pc.printf("Last R/W operaion passed!\n\r");
+ *     else pc.printf("Last R/W operation failed!\n\r");
+ * }
+ *
+ * int main() {
+ *     int junk = 0;
+ *
+ *     sec = 24;       // 24 seconds
+ *     min = 13;       // 13 min
+ *     hours = 13;     // 1 pm
+ *     day = 4;        // wednesday
+ *     date = 20;      // June 20
+ *     month = 6;
+ *     year = 12;      // 2012
+ *                     // set time to these values on the ds1307 connected device
+ *
+ *     test_rw(my1307.settime( sec, min, hours, day, date, month, year));
+ *     pc.printf("seconds set are %.2D \n\r",sec);
+ *     pc.printf("min set are %.2D \n\r",min);
+ *     pc.printf("hour set are %.2D \n\r",hours);
+ *     pc.printf("day set are %.2D \n\r",day);
+ *     pc.printf("date set are %.2D \n\r",date);
+ *     pc.printf("month set are %.2D \n\r",month);
+ *     pc.printf("year set are %.2D \n\r",year);
+ *     wait(3);
+ *                     // now read the time of the DS1307 device and see what time it is
+ *                     // note that because of the 3 second wait this time should be 3 seconds past what it was set to earlier
+ *
+ *     test_rw(my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year));
+ *     pc.printf("seconds read are %.2D \n\r",sec);
+ *     pc.printf("min read are %.2D \n\r",min);
+ *     pc.printf("hour read are %.2D \n\r",hours);
+ *     pc.printf("day read are %.2D \n\r",day);
+ *     pc.printf("date read are %.2D \n\r",date);
+ *     pc.printf("month read are %.2D \n\r",month);
+ *     pc.printf("year read are %.2D \n\r",year);
+ *
+ *     junk = 0x39;                            // just a junk value do read and write test to DS1307 ram
+ *     test_rw(my1307.write( 0x20, junk));     // this should write the value of junk to register 0x20 (a ram location) in the ds1307.
+ *     pc.printf("Value written to register 0x20 %.2X \n\r",junk);
+ *     junk = 0;                               // clear junk to show that when the register is read from the correct value is obtained
+ *     test_rw(my1307.read( 0x20, &junk));     // this should read register 0x20
+ *     pc.printf("Value read from register 0x20 %.2X \n\r",junk);
+ * }
+ * @endcode
+ */
+class DS1307 {
+public:
+    /** Create object connected to DS1307 pins ( remember both pins need pull up resisters)
+    *
+    * Ensure the pull up resistors are used on these pins.  Also note there is no checking on 
+    *  if you use thes pins p9, p10, p27, p28 so ensure you only use these ones on the LPC1768 device
+    *
+    * @param sda pin that DS1307 connected to (p9 or p28 as defined on LPC1768)
+    * @param slc pin that DS1307 connected to (p10 or p27 ad defined on LPC1768)
+    */
+    DS1307( PinName sda, PinName slc) ;                 // constructor
+
+    ~DS1307();                                          // destructor
+
+    /** Bulk read of several registers at a time
+    *
+    * Ensure the variable data pointer passed to this function has the room needed to recieve the quantity!
+    *
+    * @param addr the address to read from
+    * @param quantity the amount of registers to read from
+    * @param data the place to put the values read
+    * @param returns 0 if read worked 1 if the read of DS1307 failed for some reason
+    */
+    int read( int addr, int quantity, char *data);      // to read some of the 63 bytes from DS1307
+
+    /** Read one register of DS1307 device
+    *
+    * @param addr the address to read from
+    * @param data read from the one register
+    * @param returns 0 if read worked 1 if the read of DS1307 failed for some reason
+    */
+    int read(int addr, int *data);                      // to read one byte only
+
+    /** Bulk write of several registers at a time
+    *
+    * @param addr the address to write to
+    * @param quantity the amount of registers to write to
+    * @param data that contains the values to be written to the registers
+    * @param returns 0 if write worked 1 if the write to DS1307 failed for some reason
+    */
+    int write( int addr, int quantity, char *data);     // to write bytes to some of the 63 locations in the DS1307
+
+    /** Write one register of DS1307 device
+    *
+    * @param addr the address to write to
+    * @param data to write to register
+    * @param returns 0 if write worked 1 if the write to DS1307 failed for some reason
+    */
+    int write( int addr, int data );                    // to write one byte only
+
+    /** Start DS1307 clock
+    *
+    * @param returns 0 if clock started 1 if the write command to DS1307 failed for some reason
+    */
+    int start_clock(void);                              // start the clock
+
+    /** Stop DS1307 clock
+    *
+    * @param returns 0 if clock stopped 1 if the write command to DS1307 failed for some reason
+    */
+    int stop_clock(void);                               // stop clock
+
+    /** Set twelve hour mode on DS1307 (note this also converts 24 hour time to 12 time if needed on DS1307)
+    *
+    * Note this will convert DS1307 time values in registers to 12 hour values from 24 hour values if needed
+    *
+    * @param returns 0 if DS1307 is now in 12 hour mode 1 if the command to DS1307 failed for some reason
+    */
+    int twelve_hour(void);                              // set 12 hour mode
+
+    /** Set twenty four hour mode on DS1307 
+    *
+    * Note this will convert DS1307 time values in registers to 24 hour values from 12 hour values if needed
+    *
+    * @param returns 0 if DS1307 is now in 24 hour mode 1 if the command to DS1307 failed for some reason
+    */
+    int twentyfour_hour(void);                          // set 24 hour mode
+
+    /** Set the time to some current or other value ( note that this will start the clock after it is set!)
+    *
+    * Note this will return 1 if any of the values passed to this function are not as listed below!
+    *
+    * @param sec the seconds value (0 - 59)
+    * @param min the minute value (0 - 59)
+    * @param hour the hour value (0 - 23) always in 24 hour
+    * @param day the day value ( sunday is 1 )
+    * @param date the date value (1 - 31)
+    * @param month the month value (1-12)
+    * @param year the year value (00 - 99) this is for 2000 to 2099 only as i understand it!
+    * @param returns 0 if time is set 1 if the time setting failed in some way
+    */
+    int settime(int sec, int min, int hour, int day, int date, int month, int year);         // to set the current time and start clock
+
+    /** Read the current time of the DS1307
+    *
+    * @param sec the seconds value (0 - 59)
+    * @param min the minute value (0 - 59)
+    * @param hour the hour value (0 - 23) always in 24 hour
+    * @param day the day value ( sunday is 1 )
+    * @param date the date value (1 - 31)
+    * @param month the month value (1-12)
+    * @param year the year value (00 - 99) this is for 2000 to 2099 only as i understand it!
+    * @param returns 0 if time is read correctly 1 if the time was not recieved correctly for some reason
+    */
+    int gettime(int *sec, int *min, int *hour, int *day, int *date, int *month, int *year);  // to get the current time information
+
+
+protected:
+    I2C ds1307i2c;
+    int dectobcd( int );
+    int bcdtodec( int );
+    int hilow_check( int, int, int);
+
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EE3420_time.h	Sat Dec 10 21:08:30 2016 +0000
@@ -0,0 +1,217 @@
+#ifndef EE3420_TIME_H
+#define EE3420_TIME_H
+
+#include "mbed.h"
+
+
+/*support for internal RTC of Freedom KL46Z uses the time_t and tm data types */
+#include <time.h>
+time_t EE3420_time;
+struct tm * EE3420_timeinfo;
+/*
+tm_sec  int seconds after the minute    0-61*
+tm_min  int minutes after the hour  0-59
+tm_hour int hours since midnight    0-23
+tm_mday int day of the month    1-31
+tm_mon  int months since January    0-11
+tm_year int years since 1900    
+tm_wday int days since Sunday   0-6
+tm_yday int days since January 1    0-365
+tm_isdst    int Daylight Saving Time flag
+*/
+
+
+/* support for DS1307 uses DS1307_data type */
+
+#include "ds1307.h"
+
+DS1307 EE3420_DS1307(PTE0,PTE1); // start DS1307 class and give it pins for connections of the DS1307 device
+
+typedef struct ds1307_data
+{
+int sec;
+int min;
+int hours;
+int day;
+int date;
+int month;
+int year;
+} DS1307_DATA;
+
+DS1307_DATA EE3420_DS1307_data;
+
+char * EE3420_weekday_names[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
+char * EE3420_month_names[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
+
+void show_clock_24(DS1307_DATA *tdata)
+{
+pc.printf("%02i:%02i:%02i, %s, %s %i, %i\r\n",tdata->hours,tdata->min,tdata->sec,EE3420_weekday_names[(tdata->day)-1],EE3420_month_names[(tdata->month)-1],tdata->date,(tdata->year)+2000 );
+ 
+}
+
+void format_time_string_24(DS1307_DATA *tdata, char *time_str)
+{
+sprintf(time_str,"%02i:%02i:%02i, %s, %s %i, %i\r\n",tdata->hours,tdata->min,tdata->sec,EE3420_weekday_names[(tdata->day)-1],EE3420_month_names[(tdata->month)-1],tdata->date,(tdata->year)+2000 );
+}
+
+void show_clock_12(DS1307_DATA *tdata)
+{
+char ap='a';
+int hr=0;
+
+if (tdata->hours >= 12) {ap='p';} else {ap='a';}
+hr=(tdata->hours)%12;
+if (hr==0) {hr=12;} 
+pc.printf("%02i:%02i:%02i %c.m., %s, %s %i, %i\r\n",hr,tdata->min,tdata->sec,ap,EE3420_weekday_names[(tdata->day)-1],EE3420_month_names[(tdata->month)-1],tdata->date,(tdata->year)+2000 );
+}
+
+void format_time_string_12(DS1307_DATA *tdata, char *time_str)
+{
+char ap='a';
+int hr=0;
+
+if (tdata->hours >= 12) {ap='p';} else {ap='a';}
+hr=(tdata->hours)%12;
+if (hr==0) {hr=12;} 
+sprintf(time_str,"%02i:%02i:%02i %c.m., %s, %s %i, %i\r\n",hr,tdata->min,tdata->sec,ap,EE3420_weekday_names[(tdata->day)-1],EE3420_month_names[(tdata->month)-1],tdata->date,(tdata->year)+2000 );
+}
+
+
+
+void prompt_for_time(DS1307_DATA *tdata) 
+{
+
+pc.printf("\r\nEnter the time you want to set as prompted.\r\n");
+
+tdata->year=100;
+while( (tdata->year < 0) || (tdata->year > 99))
+{
+pc.printf("Enter the year as a number 0-99 to represent the year 2000-2099:  ");
+pc.scanf("%i",&tdata->year);
+pc.printf("\r\n");
+}
+
+tdata->month=100;
+while( (tdata->month < 1) || (tdata->month > 12))
+{
+pc.printf("Enter the month as a number 1-12 for January - December:  ");
+pc.scanf("%i",&tdata->month);
+pc.printf("\r\n");
+}
+
+tdata->date=100;
+while( (tdata->date < 1) || (tdata->date > 31))
+{
+pc.printf("Enter the day of the month as a number 1-31 to represent the day of the month:  ");
+pc.scanf("%i",&tdata->date);
+pc.printf("\r\n");
+if((tdata->month==2) && (tdata->date > 29))
+{
+    tdata->date=33;
+    pc.printf("February has 29 days at most.\r\n");
+}
+if((tdata->month==2) && (tdata->date == 29) && ((tdata->year%4) !=0) && (tdata->year !=0))
+{
+    tdata->date=33;
+    pc.printf("February has 28 days at most in non-leap years.\r\n");
+}
+}
+
+tdata->day=100;
+while( (tdata->day < 1) || (tdata->day > 7))
+{
+pc.printf("Enter the day of the week as a number 1-7 for Sunday - Saturday:  ");
+pc.scanf("%i",&tdata->day);
+pc.printf("\r\n");
+}
+
+int ampm=2;
+tdata->hours=100;
+while((tdata->hours < 0) || (tdata->hours > 23))
+{
+pc.printf("Enter the hour as 0-23:  ");
+pc.scanf("%i",&tdata->hours);
+pc.printf("\r\n");
+if((tdata->hours >=1 ) && (tdata->hours <= 12) )
+{
+    ampm=2;
+    while((ampm<0) || (ampm > 1))
+    {
+        pc.printf("Enter 0 for a.m. and 1 for p.m.: ");
+        pc.scanf("%i",&ampm);
+        pc.printf("\r\n");        
+    }
+    tdata->hours = (tdata->hours + (ampm*12)) % 24 ;
+}
+}
+
+tdata->min=100;
+while( (tdata->min < 0) || (tdata->min > 59))
+{
+pc.printf("Enter the minute as 0-59:  ");
+pc.scanf("%i",&tdata->min);
+pc.printf("\r\n");
+}
+
+tdata->sec=100;
+while( (tdata->sec < 0) || (tdata->sec > 59))
+{
+pc.printf("Enter the second as 0-59:  ");
+pc.scanf("%i",&tdata->sec);
+pc.printf("\r\n");
+}
+
+}
+
+void set_DS1307_time(DS1307_DATA *tdata)
+{
+
+if(0!=EE3420_DS1307.twentyfour_hour())
+{
+    pc.printf("Failed to set 24-hour mode on DS1307.\r\n");
+    exit(-1);
+}
+
+if(0!=EE3420_DS1307.settime( tdata->sec, tdata->min, tdata->hours, tdata->day, tdata->date, tdata->month, tdata->year))
+{
+    pc.printf("Failed to set time on DS1307.\r\n");
+    exit(-1);
+}
+
+}
+
+void get_DS1307_time(DS1307_DATA *tdata) 
+{
+if(0!=EE3420_DS1307.gettime( &tdata->sec, &tdata->min, &tdata->hours, &tdata->day, &tdata->date, &tdata->month, &tdata->year))
+{
+    pc.printf("Unable to read DS1307 time\r\n");
+    exit(-1);
+}
+}
+ 
+void set_KL46Z_RTC_from_DS1307()
+{
+get_DS1307_time(&EE3420_DS1307_data); 
+time(&EE3420_time);
+EE3420_timeinfo = localtime ( &EE3420_time );
+EE3420_timeinfo->tm_sec=EE3420_DS1307_data.sec;
+EE3420_timeinfo->tm_min=EE3420_DS1307_data.min;
+EE3420_timeinfo->tm_hour=EE3420_DS1307_data.hours;
+EE3420_timeinfo->tm_mday=EE3420_DS1307_data.date;
+EE3420_timeinfo->tm_mon=(EE3420_DS1307_data.month)-1;
+EE3420_timeinfo->tm_year=(EE3420_DS1307_data.year)+100;    
+EE3420_timeinfo->tm_wday=(EE3420_DS1307_data.day)-1;
+//timeinfo->tm_isdst=-1;
+EE3420_time=mktime(EE3420_timeinfo);
+set_time(EE3420_time);     
+
+}
+
+
+ #endif /* EE3420_TIME_H */
+ 
+ 
+ 
+ 
+ 
+ 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Freedom_headers.h	Sat Dec 10 21:08:30 2016 +0000
@@ -0,0 +1,456 @@
+#ifndef FREEDOM__HEADERS_H
+#define FREEDOM__HEADERS_H
+
+#include "mbed.h"
+
+/*
+The USB connections are on this end of the board
+
+                                    J2_19   OO  J2_20
+                                    J2_17   OO  J2_18
+                                    J2_15   OO  J2_16
+                                    J2_13   OO  J2_14
+J3_2    OO  J3_1                    J2_11   OO  J2_12
+J3_4    OO  J3_3                    J2_9    OO  J2_10
+J3_6    OO  J3_5                    J2_7    OO  J2_8
+J3_8    OO  J3_7                    J2_5    OO  J2_6
+J3_10   OO  J3_9                    J2_3    OO  J2_4
+J3_12   OO  J3_11                   J2_1    OO  J2_2
+J3_14   OO  J3_13                   
+J3_16   OO  J3_15                   J1_15   OO  J1_16
+                                    J1_13   OO  J1_14
+J4_2    OO  J4_1                    J1_11   OO  J1_12
+J4_4    OO  J4_3                    J1_9    OO  J1_10
+J4_6    OO  J4_5                    J1_7    OO  J1_8
+J4_8    OO  J4_7                    J1_5    OO  J1_6
+J4_10   OO  J4_9                    J1_3    OO  J1_4
+J4_12   OO  J4_11                   J1_1    OO  J1_2
+
+*/
+
+#if   defined (TARGET_KL46Z)
+PinName const J1_1 = PTB18 ;
+PinName const J1_2 = PTA1 ;
+PinName const J1_3 = PTB19 ;
+PinName const J1_4 = PTA2 ;
+PinName const J1_5 = PTC0 ;
+PinName const J1_6 = PTD3 ;
+PinName const J1_7 = PTC4 ;
+PinName const J1_8 = PTA12 ;
+PinName const J1_9 = PTC6 ;
+PinName const J1_10 = PTA4 ;
+PinName const J1_11 = PTC7 ;
+PinName const J1_12 = PTA5 ;
+PinName const J1_13 = PTC10 ;
+PinName const J1_14 = PTC8 ;
+PinName const J1_15 = PTC11 ;
+PinName const J1_16 = PTC9 ;
+
+PinName const J2_1 = PTC13 ;
+PinName const J2_2 = PTA13 ;
+PinName const J2_3 = PTC16 ;
+PinName const J2_4 = PTD2 ;
+PinName const J2_5 = PTA7 ;
+PinName const J2_6 = PTD4 ;
+PinName const J2_7 = PTA6 ;
+PinName const J2_8 = PTD6 ;
+PinName const J2_9 = PTA14 ;
+PinName const J2_10 = PTD7 ;
+PinName const J2_11 = PTA15 ;
+PinName const J2_12 = PTD5 ;
+PinName const J2_13 = PTA16 ;
+PinName const J2_14 = NC ;  //GND
+PinName const J2_15 = PTA17 ;
+PinName const J2_16 = NC ;  //AREF
+PinName const J2_17 = PTB9 ;
+PinName const J2_18 = PTE0 ;
+PinName const J2_19 = NC ; //NC
+PinName const J2_20 = PTE1 ;
+
+PinName const J3_1 = PTE31 ;
+PinName const J3_2 = NC ;  //SDA_PTD5
+PinName const J3_3 = PTE19 ;
+PinName const J3_4 = NC ;  //3.3V
+PinName const J3_5 = PTE18 ;
+PinName const J3_6 = PTA20 ;  //RESET
+PinName const J3_7 = PTE17 ;
+PinName const J3_8 = NC ;  //3.3V
+PinName const J3_9 = PTE16 ;
+PinName const J3_10 = NC ;  //5V
+PinName const J3_11 = PTE6 ;
+PinName const J3_12 = NC ;  //GND
+PinName const J3_13 = PTE3 ;
+PinName const J3_14 = NC ;  //GND
+PinName const J3_15 = PTE2 ;
+PinName const J3_16 = NC ;  //VIN
+
+PinName const J4_1 = PTE20 ;
+PinName const J4_2 = PTB0 ;
+PinName const J4_3 = PTE21 ;
+PinName const J4_4 = PTB1 ;
+PinName const J4_5 = PTE22 ;
+PinName const J4_6 = PTB2 ;
+PinName const J4_7 = PTE23 ;
+PinName const J4_8 = PTB3 ;
+PinName const J4_9 = PTB20 ;
+PinName const J4_10 = PTC2 ;
+PinName const J4_11 = PTE30 ;
+PinName const J4_12 = PTC1 ;
+
+
+#elif   defined (TARGET_KL25Z) 
+
+PinName const J1_1 = PTC7 ;
+PinName const J1_2 = PTA1 ; //?
+PinName const J1_3 = PTBC0 ;
+PinName const J1_4 = PTA2 ; //?
+PinName const J1_5 = PTC3 ;
+PinName const J1_6 = PTD4 ;
+PinName const J1_7 = PTC4 ;
+PinName const J1_8 = PTA12 ;
+PinName const J1_9 = PTC5 ;
+PinName const J1_10 = PTA4 ;
+PinName const J1_11 = PTC6 ;
+PinName const J1_12 = PTA5 ;
+PinName const J1_13 = PTC10 ;
+PinName const J1_14 = PTC8 ;
+PinName const J1_15 = PTC11 ;
+PinName const J1_16 = PTC9 ;
+
+PinName const J2_1 = PTC12 ;
+PinName const J2_2 = PTA13 ;
+PinName const J2_3 = PTC13 ;
+PinName const J2_4 = PTD5 ;
+PinName const J2_5 = PTC16 ;
+PinName const J2_6 = PTD0 ;
+PinName const J2_7 = PTC17 ;
+PinName const J2_8 = PTD2 ;
+PinName const J2_9 = PTA16 ;
+PinName const J2_10 = PTD3 ;
+PinName const J2_11 = PTA17 ;
+PinName const J2_12 = PTD1 ;
+PinName const J2_13 = PTE31 ;
+PinName const J2_14 = NC ;  //GND
+PinName const J2_15 = NC ; //NC
+PinName const J2_16 = NC ;  //AREF
+PinName const J2_17 = PTD6 ;
+PinName const J2_18 = PTE0 ;
+PinName const J2_19 = PTD7 ; 
+PinName const J2_20 = PTE1 ;
+
+PinName const J3_1 = PTB8 ;
+PinName const J3_2 = NC ;  //SDA_PTD5
+PinName const J3_3 = PTB9 ;
+PinName const J3_4 = NC ;  //3.3V
+PinName const J3_5 = PTB10 ;
+PinName const J3_6 = PTA20 ;  //RESET
+PinName const J3_7 = PTB11 ;
+PinName const J3_8 = NC ;  //3.3V
+PinName const J3_9 = PTE2 ;
+PinName const J3_10 = NC ;  //5V
+PinName const J3_11 = PTE3 ;
+PinName const J3_12 = NC ;  //GND
+PinName const J3_13 = PTE4 ;
+PinName const J3_14 = NC ;  //GND
+PinName const J3_15 = PTE5 ;
+PinName const J3_16 = NC ;  //VIN
+
+PinName const J4_1 = PTE20 ;
+PinName const J4_2 = PTB0 ;
+PinName const J4_3 = PTE21 ;
+PinName const J4_4 = PTB1 ;
+PinName const J4_5 = PTE22 ;
+PinName const J4_6 = PTB2 ;
+PinName const J4_7 = PTE23 ;
+PinName const J4_8 = PTB3 ;
+PinName const J4_9 = PTE29 ;
+PinName const J4_10 = PTC2 ;
+PinName const J4_11 = PTE30 ;
+PinName const J4_12 = PTC1 ;
+
+#elif defined (TARGET_KL05Z)
+
+PinName const J1_1 = NC ;
+PinName const J1_2 = PTB2 ; //?
+PinName const J1_3 = NC ;
+PinName const J1_4 = PTB1 ; //?
+PinName const J1_5 = NC ;
+PinName const J1_6 = PTA11 ;
+PinName const J1_7 = NC ;
+PinName const J1_8 = PTB5 ;
+PinName const J1_9 = NC ;
+PinName const J1_10 = PTA10 ;
+PinName const J1_11 = NC ;
+PinName const J1_12 = PTA12 ;
+PinName const J1_13 = NC ;
+PinName const J1_14 = PTB6 ;
+PinName const J1_15 = NC ;
+PinName const J1_16 = PTB7 ;
+
+PinName const J2_1 = NC ;
+PinName const J2_2 = PTB10 ;
+PinName const J2_3 = NC ;
+PinName const J2_4 = PTB11 ;
+PinName const J2_5 = NC ;
+PinName const J2_6 = PTA5 ;
+PinName const J2_7 = NC ;
+PinName const J2_8 = PTA7 ;
+PinName const J2_9 = NC ;
+PinName const J2_10 = PTA6 ;
+PinName const J2_11 = NC ;
+PinName const J2_12 = PTB0 ;
+PinName const J2_13 = NC ;
+PinName const J2_14 = NC ;  //GND
+PinName const J2_15 = NC ; //NC
+PinName const J2_16 = NC ;  //AREF
+PinName const J2_17 = NC ;
+PinName const J2_18 = PTB4 ;
+PinName const J2_19 = NC ; 
+PinName const J2_20 = PTB3 ;
+
+PinName const J3_1 = NC ;
+PinName const J3_2 = NC ;  //SDA_PTD5
+PinName const J3_3 = NC ;
+PinName const J3_4 = NC ;  //3.3V
+PinName const J3_5 = NC ;
+PinName const J3_6 = NC ;  //RESET
+PinName const J3_7 = NC ;
+PinName const J3_8 = NC ;  //3.3V
+PinName const J3_9 = NC ;
+PinName const J3_10 = NC ;  //5V
+PinName const J3_11 = NC ;
+PinName const J3_12 = NC ;  //GND
+PinName const J3_13 = NC ;
+PinName const J3_14 = NC ;  //GND
+PinName const J3_15 = NC ;
+PinName const J3_16 = NC ;  //VIN
+
+PinName const J4_1 = NC ;
+PinName const J4_2 = PTB8 ;
+PinName const J4_3 = NC ;
+PinName const J4_4 = PTB9 ;
+PinName const J4_5 = NC ;
+PinName const J4_6 = PTA8 ;
+PinName const J4_7 = NC ;
+PinName const J4_8 = PTA0 ;
+PinName const J4_9 = NC ;
+PinName const J4_10 = PTA9 ;
+PinName const J4_11 = NC ;
+PinName const J4_12 = PTB13 ;
+
+#elif defined (TARGET_K22F)
+
+PinName const J1_1 = PTA5 ;
+PinName const J1_2 = PTD2 ; //?
+PinName const J1_3 = PTA13 ;
+PinName const J1_4 = PTD3 ; //?
+PinName const J1_5 = PTA12 ;
+PinName const J1_6 = PTB16 ;
+PinName const J1_7 = PTC8 ;
+PinName const J1_8 = PTA2 ;
+PinName const J1_9 = PTC9 ;
+PinName const J1_10 = PTA4 ;
+PinName const J1_11 = PTC7 ;
+PinName const J1_12 = PTB10 ;
+PinName const J1_13 = PTC10 ;
+PinName const J1_14 = PTC3 ;
+PinName const J1_15 = PTC5 ;
+PinName const J1_16 = PTC6 ;
+
+PinName const J2_1 = NC ;
+PinName const J2_2 = PTB19 ;
+PinName const J2_3 = NC ;
+PinName const J2_4 = PTA1 ;
+PinName const J2_5 = PTC0 ;
+PinName const J2_6 = PTD4 ;
+PinName const J2_7 = PTC11 ;
+PinName const J2_8 = PTD6 ;
+PinName const J2_9 = NC ;
+PinName const J2_10 = PTD7 ;
+PinName const J2_11 = NC ;
+PinName const J2_12 = PTD5 ;
+PinName const J2_13 = NC ;
+PinName const J2_14 = NC ;  //GND
+PinName const J2_15 = NC ; //NC
+PinName const J2_16 = NC ;  //AREF
+PinName const J2_17 = NC ;
+PinName const J2_18 = PTE0 ;
+PinName const J2_19 = NC ; 
+PinName const J2_20 = PTE1 ;
+
+PinName const J3_1 = NC ;
+PinName const J3_2 = NC ;  //SDA_PTD5
+PinName const J3_3 = NC ;
+PinName const J3_4 = NC ;  //3.3V
+PinName const J3_5 = NC ;
+PinName const J3_6 = NC ;  //RESET
+PinName const J3_7 = NC ;
+PinName const J3_8 = NC ;  //3.3V
+PinName const J3_9 = NC ;
+PinName const J3_10 = NC ;  //5V
+PinName const J3_11 = NC ;
+PinName const J3_12 = NC ;  //GND
+PinName const J3_13 = NC ;
+PinName const J3_14 = NC ;  //GND
+PinName const J3_15 = NC ;
+PinName const J3_16 = NC ;  //VIN
+
+PinName const J4_1 = NC ; //ADC0_DP0
+PinName const J4_2 = PTB0 ;
+PinName const J4_3 = NC ; //ADC0_DM0
+PinName const J4_4 = PTB1 ;
+PinName const J4_5 = NC ; //ADC0_DP3
+PinName const J4_6 = PTC1 ;
+PinName const J4_7 = NC ; //ADC0_DM3
+PinName const J4_8 = PTC2 ;
+PinName const J4_9 = PTC4 ;
+PinName const J4_10 = PTB3 ;
+PinName const J4_11 = NC ; //DAC0_OUT
+PinName const J4_12 = PTB2 ;
+
+#elif defined (TARGET_K20D50M)
+
+PinName const J1_1 = PTD0 ;
+PinName const J1_2 = PTE1 ; //?
+PinName const J1_3 = PTC11 ;
+PinName const J1_4 = PTE0 ; //?
+PinName const J1_5 = PTC5 ;
+PinName const J1_6 = PTA5 ;
+PinName const J1_7 = PTC6 ;
+PinName const J1_8 = PTD4 ;
+PinName const J1_9 = PTC7 ;
+PinName const J1_10 = PTC8 ;
+PinName const J1_11 = PTA4 ;
+PinName const J1_12 = PTA1 ;
+PinName const J1_13 = PTD7 ;
+PinName const J1_14 = PTC3 ;
+PinName const J1_15 = PTC9 ;
+PinName const J1_16 = PTC4 ;
+
+PinName const J2_1 = PTC13 ;
+PinName const J2_2 = PTA12 ;
+PinName const J2_3 = PTC10 ;
+PinName const J2_4 = PTA2 ;
+PinName const J2_5 = NC ;
+PinName const J2_6 = PTC2 ;
+PinName const J2_7 = NC ;
+PinName const J2_8 = PTD2 ;
+PinName const J2_9 = NC ;
+PinName const J2_10 = PTD3 ;
+PinName const J2_11 = NC ;
+PinName const J2_12 = PTD1 ;
+PinName const J2_13 = NC ;
+PinName const J2_14 = NC ;  //GND
+PinName const J2_15 = NC ; //NC
+PinName const J2_16 = NC ;  //AREF
+PinName const J2_17 = NC ;
+PinName const J2_18 = PTB3 ;
+PinName const J2_19 = NC ; 
+PinName const J2_20 = PTB2 ;
+
+PinName const J3_1 = NC ;
+PinName const J3_2 = NC ;  //SDA_PTD5
+PinName const J3_3 = NC ;
+PinName const J3_4 = NC ;  //3.3V
+PinName const J3_5 = NC ;
+PinName const J3_6 = NC ;  //RESET
+PinName const J3_7 = NC ;
+PinName const J3_8 = NC ;  //3.3V
+PinName const J3_9 = NC ;
+PinName const J3_10 = NC ;  //5V
+PinName const J3_11 = NC ;
+PinName const J3_12 = NC ;  //GND
+PinName const J3_13 = NC ;
+PinName const J3_14 = NC ;  //GND
+PinName const J3_15 = NC ;
+PinName const J3_16 = NC ;  //VIN
+
+PinName const J4_1 = NC ; //CMP1_IN5
+PinName const J4_2 = PTC0 ;
+PinName const J4_3 = NC ; //CMP1_IN3
+PinName const J4_4 = PTC1 ;
+PinName const J4_5 = NC ; //ADC0_DP3
+PinName const J4_6 = PTD6 ;
+PinName const J4_7 = NC ; //ADC0_DM3
+PinName const J4_8 = PTD5 ;
+PinName const J4_9 = NC ; //ADC0_DP0
+PinName const J4_10 = PTB1 ;
+PinName const J4_11 = NC ; //ADC0_DM0;
+PinName const J4_12 = PTB0 ;
+
+#elif defined (TARGET_K64F)
+
+PinName const J1_1 = PTB10 ;
+PinName const J1_2 = PTC16 ; //?
+PinName const J1_3 = PTB19 ;
+PinName const J1_4 = PTC17 ; //?
+PinName const J1_5 = PTC1 ;
+PinName const J1_6 = PTB9 ;
+PinName const J1_7 = PTC8 ;
+PinName const J1_8 = PTA1 ;
+PinName const J1_9 = PTC9 ;
+PinName const J1_10 = PTB23 ;
+PinName const J1_11 = PTC0 ;
+PinName const J1_12 = PTA2 ;
+PinName const J1_13 = PTC7 ;
+PinName const J1_14 = PTC2 ;
+PinName const J1_15 = PTC5 ;
+PinName const J1_16 = PTC3 ;
+
+PinName const J2_1 = PTE26 ;
+PinName const J2_2 = PTA0 ;
+PinName const J2_3 = NC ;
+PinName const J2_4 = PTC4 ;
+PinName const J2_5 = NC ; //ADC0_DP0
+PinName const J2_6 = PTD0 ;
+PinName const J2_7 = NC ; //ADC0_DM0
+PinName const J2_8 = PTD2 ;
+PinName const J2_9 = NC ;
+PinName const J2_10 = PTD3 ;
+PinName const J2_11 = NC ; //ADC1_DP0
+PinName const J2_12 = PTD1 ;
+PinName const J2_13 = NC ; //ADC1_DM0
+PinName const J2_14 = NC ;  //GND
+PinName const J2_15 = NC ; //NC
+PinName const J2_16 = NC ;  //AREF
+PinName const J2_17 = NC ; //ADC1_SE18
+PinName const J2_18 = PTE25 ;
+PinName const J2_19 = NC ; 
+PinName const J2_20 = PTE24 ;
+
+PinName const J3_1 = NC ;
+PinName const J3_2 = NC ;  //SDA_PTD5
+PinName const J3_3 = NC ;
+PinName const J3_4 = NC ;  //3.3V
+PinName const J3_5 = NC ;
+PinName const J3_6 = NC ;  //RESET
+PinName const J3_7 = NC ;
+PinName const J3_8 = NC ;  //3.3V
+PinName const J3_9 = NC ;
+PinName const J3_10 = NC ;  //5V
+PinName const J3_11 = NC ;
+PinName const J3_12 = NC ;  //GND
+PinName const J3_13 = NC ;
+PinName const J3_14 = NC ;  //GND
+PinName const J3_15 = NC ;
+PinName const J3_16 = NC ;  //VIN
+
+PinName const J4_1 = NC ; //ADC0_DP1
+PinName const J4_2 = PTB2 ;
+PinName const J4_3 = NC ; //ADCO_DM1
+PinName const J4_4 = PTB3 ;
+PinName const J4_5 = NC ; //ADC1_DP1
+PinName const J4_6 = PTB10 ;
+PinName const J4_7 = NC ; //ADC1_DM1
+PinName const J4_8 = PTB11 ;
+PinName const J4_9 = PTB20 ;
+PinName const J4_10 = PTC11 ;
+PinName const J4_11 = NC ; //DAC0_OUT
+PinName const J4_12 = PTC10 ;
+
+#else
+  #error TARGET NOT DEFINED
+#endif
+
+
+#endif // FREEDOM__HEADERS_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Sat Dec 10 21:08:30 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 10 21:08:30 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/99a22ba036c9
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simple_fifo.h	Sat Dec 10 21:08:30 2016 +0000
@@ -0,0 +1,808 @@
+#ifndef SIMPLE_FIFO_H
+#define SIMPLE_FIFO_H
+
+/*
+SIMPLE_FIFO was designed as an example of a FIFO construct using "char" data.
+The defined type structure called SIMPLE_FIFO uses an array of type "char" and
+two integer pointers "write_pointer" and "read_pointer" to form a circuular buffer.
+The number of elements in the circular buffer is defined by SIMPLE_FIFO_SIZE.
+
+The following functions are defined for the SIMPLE_FIFO type:
+void simple_fifo_init(SIMPLE_FIFO *f)
+int simple_fifo_writeable(SIMPLE_FIFO *f)
+int simple_fifo_readable(SIMPLE_FIFO *f)
+int simple_fifo_write(SIMPLE_FIFO *f, char c)
+int simple_fifo_read(SIMPLE_FIFO *f, char *c)
+char simple_fifo_putc(SIMPLE_FIFO *f, char c)
+char simple_fifo_getc(SIMPLE_FIFO *f, char *c)
+void simple_fifo_puts(SIMPLE_FIFO *f, char str[])
+void simple_fifo_gets(SIMPLE_FIFO *f, char str[], int count)
+
+The function simple_fifo_init initializes both pointers to 0 and initializes all data in the fifo to 0.
+The function simple_fifo_writeable returns true if space is available in the fifo and returns false if the fifo is full.
+The function simple_fifo_readable returns true if data is available in the fifo and returns false if the fifo is empty.
+The function simple_fifo_write returns true if if data was successfully written to the fifo and returns false if the fifo is full.
+The function simple_fifo_read returns true if if data was successfully read from the fifo and returns false if the fifo is empty.
+The function simple_fifo_putc blocks until the fifo is writeable then writes a single character to the fifo.  The return value is the character written.
+The function simple_fifo_getc blocks until the fifo is readable then reads a single character from the fifo.  The return value is the character read.
+The function simple_fifo_puts blocks until the fifo is writeable then writes a single character to the fifo.  This is repeated until all characters in the null-terminated string out written to the fifo.  
+The function simple_fifo_getc blocks until the fifo is readable then reads a single character from the fifo.  This is repeated until the carriage return character is encountered.  The resulting string is returned as null-terminated without the carriage return caracter included.
+*/
+
+#ifndef TRUE
+#define TRUE ( 1 == 1 )
+#endif
+
+#ifndef FALSE
+#define FALSE ( 1 == 0 )
+#endif
+
+#ifndef SIMPLE_FIFO_SIZE 
+#define SIMPLE_FIFO_SIZE 16
+#endif
+
+#ifndef SIMPLE_FIFO
+typedef struct simple_fifo
+{
+char buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} SIMPLE_FIFO;
+#endif
+
+void simple_fifo_init(SIMPLE_FIFO *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int simple_fifo_writeable(SIMPLE_FIFO *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int simple_fifo_readable(SIMPLE_FIFO *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int simple_fifo_write(SIMPLE_FIFO *f, char c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int simple_fifo_read(SIMPLE_FIFO *f, char *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+char simple_fifo_putc(SIMPLE_FIFO *f, char c)
+{
+    while(!simple_fifo_writeable(f)) {}
+    simple_fifo_write(f, c);
+    return(c);
+}
+
+char simple_fifo_getc(SIMPLE_FIFO *f, char *c)
+{
+    while(!simple_fifo_readable(f)) {}
+    simple_fifo_read(f, c);
+    return(*c);
+
+}
+
+void simple_fifo_puts(SIMPLE_FIFO *f, char str[])
+{
+    for(int i=0; str[i]!='\0';i++)
+    {
+        simple_fifo_putc(f, str[i]);
+    }
+}
+
+void simple_fifo_gets(SIMPLE_FIFO *f, char str[], int count)
+{
+    for(int i=0; i<count; i++)
+    {
+        simple_fifo_getc(f, &str[i]);
+        if(str[i] == '\r' || str[i] == '\n')
+        {
+            str[i]='\0';
+            break;
+        }
+    }
+    str[count-1]='\0';
+}
+
+/*
+In addition to the SIMPLE_FIFO type, a number of similar fifo types are constructed for various data types.
+The following fifo types are defined:
+FIFO_CHAR   //for character data, similar to SIMPLE_FIFO above
+FIFO_INT   //for default integer type
+FIFO_U8     //for uint8_t data
+FIFO_U16    //for uint16_t data
+FIFO_U32    //for uint32_t data
+FIFO_I8     //for int8_t data
+FIFO_I16    //for int16_t data
+FIFO_I32    //for int32_t data
+FIFO_FLOAT  //for float data
+FIFO_DOUBLE  //for double data
+
+The following functions are defined for the FIFO_?? types:
+void fifo_??_init(FIFO_?? *f)
+int fifo_??_writeable(FIFO_?? *f)
+int fifo_??_readable(FIFO_?? *f)
+int fifo_??_write(FIFO_?? *f, char c)
+int fifo_??_read(FIFO_?? *f, char *c)
+
+The function fifo_??_init initializes both pointers to 0 and initializes all data in the fifo to 0.
+The function fifo_??_writeable returns true if space is available in the fifo and returns false if the fifo is full.
+The function fifo_??_readable returns true if data is available in the fifo and returns false if the fifo is empty.
+The function fifo_??_write returns true if if data was successfully written to the fifo and returns false if the fifo is full.
+The function sfifo_??_read returns true if if data was successfully read from the fifo and returns false if the fifo is empty.
+*/
+
+#include <stdint.h>
+
+
+#ifndef FIFO_CHAR
+typedef struct fifo_char
+{
+char buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} FIFO_CHAR;
+#endif
+
+void fifo_char_init(FIFO_CHAR *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int fifo_char_writeable(FIFO_CHAR *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int fifo_char_readable(FIFO_CHAR *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int fifo_char_write(FIFO_CHAR *f, char c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int fifo_char_read(FIFO_CHAR *f, char *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+char fifo_char_putc(FIFO_CHAR *f, char c)
+{
+    while(!fifo_char_writeable(f)) {}
+    fifo_char_write(f, c);
+    return(c);
+}
+
+char fifo_char_getc(FIFO_CHAR *f, char *c)
+{
+    while(!fifo_char_readable(f)) {}
+    fifo_char_read(f, c);
+    return(*c);
+
+}
+
+void fifo_char_puts(FIFO_CHAR *f, char str[])
+{
+    for(int i=0; str[i]!='\0';i++)
+    {
+        fifo_char_putc(f, str[i]);
+    }
+}
+
+void fifo_char_gets(FIFO_CHAR *f, char str[], int count)
+{
+    for(int i=0; i<count; i++)
+    {
+        fifo_char_getc(f, &str[i]);
+        if(str[i] == '\r' || str[i] == '\n')
+        {
+            str[i]='\0';
+            break;
+        }
+    }
+    str[count-1]='\0';
+}
+
+
+
+#ifndef FIFO_INT
+typedef struct fifo_int
+{
+int buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} FIFO_INT;
+#endif
+
+void fifo_int_init(FIFO_INT *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int fifo_int_writeable(FIFO_INT *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int fifo_int_readable(FIFO_INT *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int fifo_int_write(FIFO_INT *f, int c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int fifo_int_read(FIFO_INT *f, int *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+#ifndef FIFO_U8
+typedef struct fifo_u8
+{
+uint8_t buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} FIFO_U8;
+#endif
+
+void fifo_u8_init(FIFO_U8 *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int fifo_u8_writeable(FIFO_U8 *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int fifo_u8_readable(FIFO_U8 *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int fifo_u8_write(FIFO_U8 *f, uint8_t c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int fifo_u8_read(FIFO_U8 *f, uint8_t *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+#ifndef FIFO_U16
+typedef struct fifo_u16
+{
+uint16_t buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} FIFO_U16;
+#endif
+
+void fifo_u16_init(FIFO_U16 *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int fifo_u16_writeable(FIFO_U16 *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int fifo_u16_readable(FIFO_U16 *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int fifo_u16_write(FIFO_U16 *f, uint16_t c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int fifo_u16_read(FIFO_U16 *f, uint16_t *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+#ifndef FIFO_U32
+typedef struct fifo_u32
+{
+uint32_t buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} FIFO_U32;
+#endif
+
+void fifo_u32_init(FIFO_U32 *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int fifo_u32_writeable(FIFO_U32 *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int fifo_u32_readable(FIFO_U32 *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int fifo_u32_write(FIFO_U32 *f, uint32_t c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int fifo_u32_read(FIFO_U32 *f, uint32_t *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+#ifndef FIFO_I8
+typedef struct fifo_i8
+{
+int8_t buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} FIFO_I8;
+#endif
+
+void fifo_i8_init(FIFO_I8 *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int fifo_i8_writeable(FIFO_I8 *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int fifo_i8_readable(FIFO_I8 *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int fifo_i8_write(FIFO_I8 *f, int8_t c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int fifo_i8_read(FIFO_I8 *f, int8_t *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+
+#ifndef FIFO_I16
+typedef struct fifo_i16
+{
+int16_t buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} FIFO_I16;
+#endif
+
+void fifo_i16_init(FIFO_I16 *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int fifo_i16_writeable(FIFO_I16 *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int fifo_i16_readable(FIFO_I16 *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int fifo_i16_write(FIFO_I16 *f, int16_t c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int fifo_i16_read(FIFO_I16 *f, int16_t *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+#ifndef FIFO_I32
+typedef struct fifo_i32
+{
+int32_t buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} FIFO_I32;
+#endif
+
+void fifo_i32_init(FIFO_I32 *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int fifo_i32_writeable(FIFO_I32 *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int fifo_i32_readable(FIFO_I32 *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int fifo_i32_write(FIFO_I32 *f, int32_t c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int fifo_i32_read(FIFO_I32 *f, int32_t *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+
+#ifndef FIFO_FLOAT
+typedef struct fifo_float
+{
+float buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} FIFO_FLOAT;
+#endif
+
+void fifo_float_init(FIFO_FLOAT *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int fifo_float_writeable(FIFO_FLOAT *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int fifo_float_readable(FIFO_FLOAT *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int fifo_float_write(FIFO_FLOAT *f, float c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int fifo_float_read(FIFO_FLOAT *f, float *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+
+#ifndef FIFO_DOUBLE
+typedef struct fifo_double
+{
+double buffer[SIMPLE_FIFO_SIZE];
+int write_pointer;
+int read_pointer;
+} FIFO_DOUBLE;
+#endif
+
+void fifo_double_init(FIFO_DOUBLE *f)
+{
+    f->write_pointer=0;
+    f->read_pointer=0;
+    for(int i=0; i<SIMPLE_FIFO_SIZE; i++)
+    { 
+        f->buffer[i]=0; 
+    }
+}
+
+int fifo_double_writeable(FIFO_DOUBLE *f)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    return(TRUE);
+}
+
+int fifo_double_readable(FIFO_DOUBLE *f)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    return(TRUE);
+}
+
+int fifo_double_write(FIFO_DOUBLE *f, double c)
+{
+    if(((f->write_pointer+1)% SIMPLE_FIFO_SIZE) == f->read_pointer)
+    {
+        return(FALSE);     /* buffer full, can't write */  
+    }
+    f->buffer[f->write_pointer] = c;
+    f->write_pointer = (f->write_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+int fifo_double_read(FIFO_DOUBLE *f, double *c)
+{
+    if(f->read_pointer == f->write_pointer)
+    {
+        return(FALSE); /* buffer empty, can't read */
+    }
+    *c = f->buffer[f->read_pointer];
+    f->read_pointer = (f->read_pointer+1)% SIMPLE_FIFO_SIZE;
+    return(TRUE);
+}
+
+
+
+
+
+
+#endif /* #ifndef SIMPLE_FIFO_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software_osc.cpp	Sat Dec 10 21:08:30 2016 +0000
@@ -0,0 +1,156 @@
+#include "stdio.h"
+#include "stdint.h"
+#include "mbed.h"
+#include "Freedom_headers.h"
+
+#define USE_PC TRUE
+/* UNCOMMENT THE FOLLOWING LINE TO ENABLE SD CARD FILESYSTEM VIA DEFAULT SPI */
+#define USE_SD_CARD TRUE
+/* UNCOMMENT THE FOLLOWING LINE TO ENABLE DS1307 REAL-TIME CLOCK VIA IIC */
+#define USE_DS1307 TRUE
+/* UNCOMMENT THE FOLLOWING LINE TO ENABLE SIMPLE FIFO FUNCTIONS */
+#define USE_SIMPLE_FIFO TRUE
+
+#ifdef USE_PC
+Serial pc(USBTX,USBRX);
+
+#ifdef USE_SD_CARD
+#include "SDFileSystem.h"
+#define SD_MOSI PTD6
+#define SD_MISO PTD7
+#define SD_SCK  PTD5
+#define SD_CS   PTD4
+char sd_root_name[]="sd";
+char filename[80];
+SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCK, SD_CS, sd_root_name);  /* MOSI,MISO,SCK,CS, "Name of directory structure" */
+
+#endif /* #ifdef USE_SD_CARD*/
+
+#ifdef USE_DS1307
+#include "EE3420_time.h"
+
+#endif /* #ifdef USE_DS1307*/
+
+#ifdef USE_SIMPLE_FIFO
+
+/* comment out the folloing definitions to use the library defaults */
+#define SIMPLE_FIFO_SIZE 32
+
+#include "simple_fifo.h"
+
+#endif /* #ifdef USE_SIMPLE_FIFO*/
+
+FIFO_FLOAT scope_data;
+int samples_active=0;
+float voltage_level;
+float ftemp;
+char timestr[80];
+
+int sample_count=0;
+    
+AnalogIn voltage_sensor(PTB0);
+InterruptIn left_button(PTC12);  /* button labeled SW3, wired active-low needing pull-up */
+Ticker t;
+#define SAMPLE_FREQUENCY 5000.0
+
+void take_sample()
+{
+    if(samples_active==1)
+    {    
+        voltage_level=voltage_sensor.read();
+        /*if(fifo_float_writable(&scope_data))
+        {
+        fifo_float_write(&scope_data,voltage_level);
+        }
+        else
+        {
+            printf("fifo overrun\n");
+            samples_active=0;
+        }*/
+        
+        
+        sample_count++;
+    }
+    if(sample_count>= 2000)
+    {
+        samples_active=0;
+    }
+}
+
+void start_sample()
+{
+    if(samples_active==0)
+    {
+        fifo_float_init(&scope_data);
+        sample_count=0;
+        samples_active=1;  
+    }
+    else
+    {
+        samples_active=0;
+    }
+    
+}
+
+int main()
+{
+
+#ifdef USE_PC    
+    pc.baud(115200);    /* set serial port speed to 115200 - must be matched in terminal emulator */
+#endif
+#ifdef USE_SLCD
+    slcd.All_Segments(0);
+#endif
+#ifdef USE_CHARACTER_LCD
+    character_lcd_initialize();
+#endif
+
+    fifo_float_init(&scope_data);
+    
+#ifdef USE_PC
+    pc.printf("\n");
+#endif
+
+    get_DS1307_time(&EE3420_DS1307_data);
+    set_KL46Z_RTC_from_DS1307();
+
+    sprintf(filename,"/sd/voltage.csv");
+    
+    FILE *fp = fopen(filename, "w");
+    if(fp == NULL) 
+    {
+        error("Could not open file ""%s"" for write\n", filename);
+    }
+    fprintf(fp,"date, time, scopes\n");
+    fclose(fp);
+
+    samples_active=0;
+    
+    left_button.mode(PullUp);
+    left_button.fall(&start_sample);
+
+    t.attach(&take_sample,1.0/SAMPLE_FREQUENCY);
+
+while(true)
+{
+    
+    if(fifo_float_readable(&scope_data))
+    {
+        
+        fp = fopen(filename, "a");
+        while(fifo_float_readable(&scope_data))
+        {
+            //get_DS1307_time(&EE3420_DS1307_data);
+            //format_time_string_24(&EE3420_DS1307_data, timestr);
+            fifo_float_read(&scope_data,&ftemp);
+            //fprintf(fp, "20%02i/%02i/%02i, %02i:%02i:%02i, %f\n",EE3420_DS1307_data.year,EE3420_DS1307_data.month,
+            //EE3420_DS1307_data.day,EE3420_DS1307_data.hours,EE3420_DS1307_data.min,EE3420_DS1307_data.sec,ftemp);
+            fprintf(fp, "%f\n",ftemp);
+            pc.printf("%f\n",ftemp);
+        }
+        fclose(fp);  
+    }
+}
+} //end of main()
+
+