ajkdvgoqueg

Dependencies:   eeprom mbed

LAB5.cpp

Committer:
sunninety1
Date:
2018-11-18
Revision:
1:95c54222290a
Parent:
0:8d6e82c584a0

File content as of revision 1:95c54222290a:

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

EEPROM memory(PB_9,PB_8,5);// Pinname sda=PB_9 , Pinname scl=PB_8 , address=1

InterruptIn gogo(PA_0);
BusIn sw1(D10,D11,D12,D13,PC_0,PC_1,PB_0);
DigitalIn sw(D9);
int mode,check;

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 eiei()
{
    if(sw==0){
        mode=0;
        check=1;
        }
    else{
        mode=1;
        check=1;
        } 
    }
void _write(int16_t y)
{
    BusOut le(D8,D7,D6,D5,D4,D3,D2);
    int8_t st;
    memory.read(y,st);
    le=st;
    wait_ms(1);
    pc.printf("Read from %d value is: %d\n",(int)y,st);
   
}
int main()
{
    int c1=2,c2=2;
    gogo.rise(&eiei);
    for(int i=0 ;i<1000;i++){
        memory.write(i,0);
        }
    while(1) {
        
            if (mode==0 && check==1) {
                c2=2;
                _Read((int8_t)sw1,(int16_t)c1);
                c1+=1;
                check=0;
            }
            if (mode==1 && check==1)
            {                
                c1=2;
                _write((int16_t)c2);
                c2+=1;
                check=0;
            }
    }
    
}