LabsDigital
/
Lab6_EEPROM
lab6 eeprom
main.cpp@0:dfb276461018, 2017-11-23 (annotated)
- Committer:
- Supermil
- Date:
- Thu Nov 23 14:30:41 2017 +0000
- Revision:
- 0:dfb276461018
lab6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Supermil | 0:dfb276461018 | 1 | |
Supermil | 0:dfb276461018 | 2 | #include "mbed.h" |
Supermil | 0:dfb276461018 | 3 | #include "eeprom.h" |
Supermil | 0:dfb276461018 | 4 | |
Supermil | 0:dfb276461018 | 5 | EEPROM memory(I2C_SDA,I2C_SCL,0); |
Supermil | 0:dfb276461018 | 6 | //EEPROM abc(I2C_SDA,I2C_SCL,1); |
Supermil | 0:dfb276461018 | 7 | Serial pc(D1,D0); |
Supermil | 0:dfb276461018 | 8 | |
Supermil | 0:dfb276461018 | 9 | BusIn dataInput(D2,D3,D4,D5,D6,D7,D8); |
Supermil | 0:dfb276461018 | 10 | BusOut ledShow(PC_4,PB_13,PB_14,PB_15,PB_1,PB_2,PB_12); |
Supermil | 0:dfb276461018 | 11 | DigitalIn selectMode(A0); |
Supermil | 0:dfb276461018 | 12 | DigitalIn button(A1); |
Supermil | 0:dfb276461018 | 13 | DigitalIn button1(A2); |
Supermil | 0:dfb276461018 | 14 | int8_t data; |
Supermil | 0:dfb276461018 | 15 | int8_t dataout; |
Supermil | 0:dfb276461018 | 16 | int address; |
Supermil | 0:dfb276461018 | 17 | int current; |
Supermil | 0:dfb276461018 | 18 | int current1; |
Supermil | 0:dfb276461018 | 19 | |
Supermil | 0:dfb276461018 | 20 | |
Supermil | 0:dfb276461018 | 21 | int main(){ |
Supermil | 0:dfb276461018 | 22 | current = 1; |
Supermil | 0:dfb276461018 | 23 | while(1){ |
Supermil | 0:dfb276461018 | 24 | |
Supermil | 0:dfb276461018 | 25 | address = 1; |
Supermil | 0:dfb276461018 | 26 | while(selectMode == 0){ //Write Mode |
Supermil | 0:dfb276461018 | 27 | data = dataInput.read(); |
Supermil | 0:dfb276461018 | 28 | if(button == 1){ |
Supermil | 0:dfb276461018 | 29 | memory.write(address,(int8_t)data); |
Supermil | 0:dfb276461018 | 30 | wait_ms(300); |
Supermil | 0:dfb276461018 | 31 | address++; |
Supermil | 0:dfb276461018 | 32 | current = address; |
Supermil | 0:dfb276461018 | 33 | } |
Supermil | 0:dfb276461018 | 34 | |
Supermil | 0:dfb276461018 | 35 | } |
Supermil | 0:dfb276461018 | 36 | address = 1; |
Supermil | 0:dfb276461018 | 37 | while(selectMode != 0){ //Read Mode |
Supermil | 0:dfb276461018 | 38 | |
Supermil | 0:dfb276461018 | 39 | if(button == 1 && address < current ){ |
Supermil | 0:dfb276461018 | 40 | memory.read(address,dataout); |
Supermil | 0:dfb276461018 | 41 | |
Supermil | 0:dfb276461018 | 42 | ledShow.write(dataout); |
Supermil | 0:dfb276461018 | 43 | wait_ms(300); |
Supermil | 0:dfb276461018 | 44 | address++; |
Supermil | 0:dfb276461018 | 45 | current1 = address-1; |
Supermil | 0:dfb276461018 | 46 | } |
Supermil | 0:dfb276461018 | 47 | if(button1 == 1){ |
Supermil | 0:dfb276461018 | 48 | memory.read(current1-1,dataout); |
Supermil | 0:dfb276461018 | 49 | |
Supermil | 0:dfb276461018 | 50 | ledShow.write(dataout); |
Supermil | 0:dfb276461018 | 51 | address = current1; |
Supermil | 0:dfb276461018 | 52 | current1--; |
Supermil | 0:dfb276461018 | 53 | wait_ms(300); |
Supermil | 0:dfb276461018 | 54 | |
Supermil | 0:dfb276461018 | 55 | } |
Supermil | 0:dfb276461018 | 56 | } |
Supermil | 0:dfb276461018 | 57 | } |
Supermil | 0:dfb276461018 | 58 | |
Supermil | 0:dfb276461018 | 59 | } |