NucleO call IC eeprom 24lc64 Read/Write value

Dependencies:   eeprom mbed

main.cpp

Committer:
NorNick
Date:
2015-11-16
Revision:
0:03b8ccce5261

File content as of revision 0:03b8ccce5261:

#include "mbed.h"
#include "eeprom.h"

EEPROM memory(I2C_SDA,I2C_SCL,0);
BusIn NobitaX(PA_10, PB_3, PB_5, PB_4, PB_10, PA_8, PA_9);
BusOut LEDs(PB_13, PB_14, PB_15, PB_1,PB_2,PB_12,PA_11);
DigitalIn DeBounce(PA_5),SW(PC_7);
//DigitalIn SW(PC_7);

int main(void)
{
    int16_t i,a=1,b=0,j=0;
    //int16_t data[100];//1-99
    int16_t x=0;
    int16_t c=SW.read();
    int16_t bit[8]={0};
    int16_t dec=0;

    printf("Hello NucleO! %d\n",i);
    while(1)
    {
        if(SW.read()==1)//WRITH DATA
        {
            if(c!=0)
            {
                printf("insert data \n");
                c=0;i=1;
            }
            if(DeBounce.read() == 1)
            {
                memory.write(i,NobitaX.read());
                wait_ms(1);
                printf("%d , ",NobitaX.read());
                /******DCB_TO_BIN_CODE*************/
                dec = NobitaX.read();
                do{
                    bit[b++] = dec % 2;
                    dec = dec / 2;
                }while (dec > 0);
                for(j = b - 1; j >= 0; j--)
                    printf("%d", bit[j]);
                printf(" , %d \n",i);
                /****************************/
                while(DeBounce.read() == 1){}
                i++;
            }
            a=1;
            j=b=0;
        }
        else //READ DATA
        {      
            if(c==0)
            {
                printf("LEAD Input EEProm\n");
                c++;
            }
            if(DeBounce.read() == 1)
            {
                memory.read(a,x);
                LEDs = x; 
                printf("%d , ",LEDs.read());
                /******DCB_TO_BIN_CODE*************/
                dec = LEDs.read();
                do{
                    bit[b++] = dec % 2;
                    dec = dec / 2;
                }while (dec > 0);
                for(j = b - 1; j >= 0; j--)
                    printf("%d", bit[j]);
                printf(" , %d \n",a);
                /****************************/
                while(DeBounce.read() == 1){}
                if(i!=0)
                {
                    if(a>i)a=1;
                    else a++;
                }
                else
                    a++;
            }
            j=b=0;
        }
    }
}