How to use EEPROM in TG-LPC11U35-501

Dependencies:   AQM0802 EEPROM mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //**********************
00002 // EEPROM sample for TG-LPC11U35-501
00003 //
00004 // via IAP
00005 //
00006 // (C)Copyright 2014 All rights reserved by Y.Onodera
00007 // http://einstlab.web.fc2.com
00008 //**********************
00009 #include "mbed.h"
00010 #include "AQM0802.h"
00011 #include "EEPROM.h"
00012 
00013 I2C i2c(P0_5,P0_4);
00014 AQM0802 lcd(i2c);
00015 EEPROM eeprom;
00016 
00017 int main() {
00018 
00019     char RAM[4096];
00020     char msg[10];
00021     int i;
00022 
00023     eeprom.put(0,10);
00024     i=eeprom.get(0);
00025     sprintf(msg, "test=%d", i );
00026     lcd.locate(0,0);
00027     lcd.print(msg);
00028     wait(1);    
00029     
00030     for(i=0;i<100;i++)
00031         RAM[i]=i;
00032     i=eeprom.write(0,RAM,100);
00033     sprintf(msg, "write=%d", i );
00034     lcd.locate(0,0);
00035     lcd.print(msg);
00036     wait(1);
00037 
00038     i=eeprom.read(0,RAM,4096-64);
00039     sprintf(msg, "read=%d ", i );
00040     lcd.locate(0,0);
00041     lcd.print(msg);
00042     wait(1);
00043 
00044     for(i=0;i<4096;i++){
00045         sprintf(msg, "adr=%4d", i );
00046         lcd.locate(0,0);
00047         lcd.print(msg);
00048         sprintf(msg, "dat=%02X", RAM[i] );
00049         lcd.locate(0,1);
00050         lcd.print(msg);
00051         wait(1);
00052     }
00053     
00054     while(1);
00055 
00056 }