ajkdvgoqueg
LAB5.cpp@1:95c54222290a, 2018-11-18 (annotated)
- Committer:
- sunninety1
- Date:
- Sun Nov 18 08:05:12 2018 +0000
- Revision:
- 1:95c54222290a
- Parent:
- 0:8d6e82c584a0
xxcxcxc;
Who changed what in which revision?
User | Revision | Line number | New 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 | |
sunninety1 | 1:95c54222290a | 6 | InterruptIn gogo(PA_0); |
sunninety1 | 0:8d6e82c584a0 | 7 | BusIn sw1(D10,D11,D12,D13,PC_0,PC_1,PB_0); |
sunninety1 | 0:8d6e82c584a0 | 8 | DigitalIn sw(D9); |
sunninety1 | 1:95c54222290a | 9 | int mode,check; |
sunninety1 | 0:8d6e82c584a0 | 10 | |
sunninety1 | 0:8d6e82c584a0 | 11 | Serial pc(D1,D0); |
sunninety1 | 0:8d6e82c584a0 | 12 | void _Read(int8_t x,int16_t y) |
sunninety1 | 0:8d6e82c584a0 | 13 | { |
sunninety1 | 0:8d6e82c584a0 | 14 | memory.write(y,x); |
sunninety1 | 0:8d6e82c584a0 | 15 | wait_ms(1); |
sunninety1 | 0:8d6e82c584a0 | 16 | pc.printf("write to %d with value: %d\n",(int)x,(int)y); |
sunninety1 | 0:8d6e82c584a0 | 17 | } |
sunninety1 | 1:95c54222290a | 18 | void eiei() |
sunninety1 | 1:95c54222290a | 19 | { |
sunninety1 | 1:95c54222290a | 20 | if(sw==0){ |
sunninety1 | 1:95c54222290a | 21 | mode=0; |
sunninety1 | 1:95c54222290a | 22 | check=1; |
sunninety1 | 1:95c54222290a | 23 | } |
sunninety1 | 1:95c54222290a | 24 | else{ |
sunninety1 | 1:95c54222290a | 25 | mode=1; |
sunninety1 | 1:95c54222290a | 26 | check=1; |
sunninety1 | 1:95c54222290a | 27 | } |
sunninety1 | 1:95c54222290a | 28 | } |
sunninety1 | 0:8d6e82c584a0 | 29 | void _write(int16_t y) |
sunninety1 | 0:8d6e82c584a0 | 30 | { |
sunninety1 | 1:95c54222290a | 31 | BusOut le(D8,D7,D6,D5,D4,D3,D2); |
sunninety1 | 0:8d6e82c584a0 | 32 | int8_t st; |
sunninety1 | 0:8d6e82c584a0 | 33 | memory.read(y,st); |
sunninety1 | 1:95c54222290a | 34 | le=st; |
sunninety1 | 0:8d6e82c584a0 | 35 | wait_ms(1); |
sunninety1 | 0:8d6e82c584a0 | 36 | pc.printf("Read from %d value is: %d\n",(int)y,st); |
sunninety1 | 1:95c54222290a | 37 | |
sunninety1 | 0:8d6e82c584a0 | 38 | } |
sunninety1 | 0:8d6e82c584a0 | 39 | int main() |
sunninety1 | 0:8d6e82c584a0 | 40 | { |
sunninety1 | 0:8d6e82c584a0 | 41 | int c1=2,c2=2; |
sunninety1 | 1:95c54222290a | 42 | gogo.rise(&eiei); |
sunninety1 | 1:95c54222290a | 43 | for(int i=0 ;i<1000;i++){ |
sunninety1 | 1:95c54222290a | 44 | memory.write(i,0); |
sunninety1 | 1:95c54222290a | 45 | } |
sunninety1 | 0:8d6e82c584a0 | 46 | while(1) { |
sunninety1 | 1:95c54222290a | 47 | |
sunninety1 | 1:95c54222290a | 48 | if (mode==0 && check==1) { |
sunninety1 | 0:8d6e82c584a0 | 49 | c2=2; |
sunninety1 | 0:8d6e82c584a0 | 50 | _Read((int8_t)sw1,(int16_t)c1); |
sunninety1 | 0:8d6e82c584a0 | 51 | c1+=1; |
sunninety1 | 1:95c54222290a | 52 | check=0; |
sunninety1 | 0:8d6e82c584a0 | 53 | } |
sunninety1 | 1:95c54222290a | 54 | if (mode==1 && check==1) |
sunninety1 | 1:95c54222290a | 55 | { |
sunninety1 | 0:8d6e82c584a0 | 56 | c1=2; |
sunninety1 | 0:8d6e82c584a0 | 57 | _write((int16_t)c2); |
sunninety1 | 0:8d6e82c584a0 | 58 | c2+=1; |
sunninety1 | 1:95c54222290a | 59 | check=0; |
sunninety1 | 0:8d6e82c584a0 | 60 | } |
sunninety1 | 0:8d6e82c584a0 | 61 | } |
sunninety1 | 1:95c54222290a | 62 | |
sunninety1 | 0:8d6e82c584a0 | 63 | } |