ajkdvgoqueg

Dependencies:   eeprom mbed

Committer:
sunninety1
Date:
Fri Nov 16 16:50:31 2018 +0000
Revision:
0:8d6e82c584a0
Child:
1:95c54222290a
sdgofiwug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sunninety1 0:8d6e82c584a0 1 #include "mbed.h"
sunninety1 0:8d6e82c584a0 2 #include "eeprom.h"
sunninety1 0:8d6e82c584a0 3
sunninety1 0:8d6e82c584a0 4 EEPROM memory(PB_9,PB_8,5);// Pinname sda=PB_9 , Pinname scl=PB_8 , address=1
sunninety1 0:8d6e82c584a0 5 BusOut le(D2,D3,D4,D5,D6,D7,D8);
sunninety1 0:8d6e82c584a0 6
sunninety1 0:8d6e82c584a0 7 BusIn sw1(D10,D11,D12,D13,PC_0,PC_1,PB_0);
sunninety1 0:8d6e82c584a0 8 DigitalIn sw(D9);
sunninety1 0:8d6e82c584a0 9 DigitalIn tog(PA_0);
sunninety1 0:8d6e82c584a0 10
sunninety1 0:8d6e82c584a0 11 Serial pc(D1,D0);
sunninety1 0:8d6e82c584a0 12
sunninety1 0:8d6e82c584a0 13 void _Read(int8_t x,int16_t y)
sunninety1 0:8d6e82c584a0 14 {
sunninety1 0:8d6e82c584a0 15
sunninety1 0:8d6e82c584a0 16 memory.write(y,x);
sunninety1 0:8d6e82c584a0 17 wait_ms(1);
sunninety1 0:8d6e82c584a0 18 pc.printf("write to %d with value: %d\n",(int)x,(int)y);
sunninety1 0:8d6e82c584a0 19 }
sunninety1 0:8d6e82c584a0 20
sunninety1 0:8d6e82c584a0 21 void _write(int16_t y)
sunninety1 0:8d6e82c584a0 22 {
sunninety1 0:8d6e82c584a0 23 int8_t st;
sunninety1 0:8d6e82c584a0 24
sunninety1 0:8d6e82c584a0 25 memory.read(y,st);
sunninety1 0:8d6e82c584a0 26 wait_ms(1);
sunninety1 0:8d6e82c584a0 27 pc.printf("Read from %d value is: %d\n",(int)y,st);
sunninety1 0:8d6e82c584a0 28 le=st;
sunninety1 0:8d6e82c584a0 29 }
sunninety1 0:8d6e82c584a0 30
sunninety1 0:8d6e82c584a0 31 int main()
sunninety1 0:8d6e82c584a0 32 {
sunninety1 0:8d6e82c584a0 33 int c1=2,c2=2;
sunninety1 0:8d6e82c584a0 34 while(1) {
sunninety1 0:8d6e82c584a0 35 if(tog==0){
sunninety1 0:8d6e82c584a0 36 while(tog==0);
sunninety1 0:8d6e82c584a0 37 if (sw==0) {
sunninety1 0:8d6e82c584a0 38 c2=2;
sunninety1 0:8d6e82c584a0 39 _Read((int8_t)sw1,(int16_t)c1);
sunninety1 0:8d6e82c584a0 40 c1+=1;
sunninety1 0:8d6e82c584a0 41 }
sunninety1 0:8d6e82c584a0 42 else{
sunninety1 0:8d6e82c584a0 43 c1=2;
sunninety1 0:8d6e82c584a0 44 _write((int16_t)c2);
sunninety1 0:8d6e82c584a0 45 c2+=1;
sunninety1 0:8d6e82c584a0 46 }
sunninety1 0:8d6e82c584a0 47 }
sunninety1 0:8d6e82c584a0 48 }
sunninety1 0:8d6e82c584a0 49 }