lab6 eeprom

Dependencies:   eeprom mbed

Revision:
0:dfb276461018
diff -r 000000000000 -r dfb276461018 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 23 14:30:41 2017 +0000
@@ -0,0 +1,59 @@
+
+#include "mbed.h"
+#include "eeprom.h"
+
+EEPROM memory(I2C_SDA,I2C_SCL,0);
+//EEPROM abc(I2C_SDA,I2C_SCL,1);
+Serial pc(D1,D0);
+
+BusIn dataInput(D2,D3,D4,D5,D6,D7,D8);
+BusOut ledShow(PC_4,PB_13,PB_14,PB_15,PB_1,PB_2,PB_12);
+DigitalIn selectMode(A0);
+DigitalIn button(A1);
+DigitalIn button1(A2);
+int8_t data;
+int8_t dataout;
+int address;
+int current;
+int current1;
+
+
+int main(){
+    current = 1;
+    while(1){
+        
+        address = 1;
+        while(selectMode == 0){                        //Write Mode
+            data = dataInput.read();
+            if(button == 1){
+                memory.write(address,(int8_t)data);
+                wait_ms(300);
+                address++;
+                current = address;
+            }
+
+        }
+        address = 1;
+        while(selectMode != 0){                         //Read Mode   
+            
+            if(button == 1 && address < current ){
+                memory.read(address,dataout);
+                
+                ledShow.write(dataout);
+                wait_ms(300);
+                address++;
+                current1 = address-1;
+            }
+            if(button1 == 1){
+                memory.read(current1-1,dataout);
+                
+                ledShow.write(dataout);
+                address = current1;
+                current1--;
+                wait_ms(300);
+
+            }
+        }
+    }
+
+}
\ No newline at end of file