ajkdvgoqueg

Dependencies:   eeprom mbed

LAB5.cpp

Committer:
sunninety1
Date:
2018-11-16
Revision:
0:8d6e82c584a0
Child:
1:95c54222290a

File content as of revision 0:8d6e82c584a0:

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

EEPROM memory(PB_9,PB_8,5);// Pinname sda=PB_9 , Pinname scl=PB_8 , address=1
BusOut le(D2,D3,D4,D5,D6,D7,D8);

BusIn sw1(D10,D11,D12,D13,PC_0,PC_1,PB_0);
DigitalIn sw(D9);
DigitalIn tog(PA_0);

Serial pc(D1,D0);

void _Read(int8_t x,int16_t y)
{
    
    memory.write(y,x);
    wait_ms(1);
    pc.printf("write to %d with value: %d\n",(int)x,(int)y);
}

void _write(int16_t y)
{
    int8_t st;
    
    memory.read(y,st);
    wait_ms(1);
    pc.printf("Read from %d value is: %d\n",(int)y,st);
    le=st;
}

int main()
{
    int c1=2,c2=2;
    while(1) {
        if(tog==0){
            while(tog==0);
            if (sw==0) {
                c2=2;
                _Read((int8_t)sw1,(int16_t)c1);
                c1+=1;
            }
            else{                
                c1=2;
                _write((int16_t)c2);
                c2+=1;
            }
    }
    }
}