![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
0508_Lab5
main.cpp@0:25f0bf2e4247, 2015-11-14 (annotated)
- Committer:
- Gennanio
- Date:
- Sat Nov 14 11:24:59 2015 +0000
- Revision:
- 0:25f0bf2e4247
0508_Lab5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Gennanio | 0:25f0bf2e4247 | 1 | // Lab 5 |
Gennanio | 0:25f0bf2e4247 | 2 | // 8/11/2015 |
Gennanio | 0:25f0bf2e4247 | 3 | #include "mbed.h" |
Gennanio | 0:25f0bf2e4247 | 4 | #include "eeprom.h" |
Gennanio | 0:25f0bf2e4247 | 5 | |
Gennanio | 0:25f0bf2e4247 | 6 | EEPROM ee(I2C_SDA,I2C_SCL,0); |
Gennanio | 0:25f0bf2e4247 | 7 | // PB_9(D14),PB_8(D15) |
Gennanio | 0:25f0bf2e4247 | 8 | BusOut led(D4,D5,D6,A0,A1,A2,A3); |
Gennanio | 0:25f0bf2e4247 | 9 | DigitalIn in1(D7),in2(D8),in3(D9),in4(D10),in5(D11),in6(D12),in7(D13); |
Gennanio | 0:25f0bf2e4247 | 10 | DigitalIn sw(D2),mode(D3); |
Gennanio | 0:25f0bf2e4247 | 11 | |
Gennanio | 0:25f0bf2e4247 | 12 | int main() |
Gennanio | 0:25f0bf2e4247 | 13 | { |
Gennanio | 0:25f0bf2e4247 | 14 | int8_t a=0,sum; |
Gennanio | 0:25f0bf2e4247 | 15 | int8_t wc=0,rc=0; |
Gennanio | 0:25f0bf2e4247 | 16 | while(1) |
Gennanio | 0:25f0bf2e4247 | 17 | { |
Gennanio | 0:25f0bf2e4247 | 18 | if(sw) |
Gennanio | 0:25f0bf2e4247 | 19 | { |
Gennanio | 0:25f0bf2e4247 | 20 | if(mode) //read |
Gennanio | 0:25f0bf2e4247 | 21 | { |
Gennanio | 0:25f0bf2e4247 | 22 | led=0; |
Gennanio | 0:25f0bf2e4247 | 23 | if(rc<wc) |
Gennanio | 0:25f0bf2e4247 | 24 | { |
Gennanio | 0:25f0bf2e4247 | 25 | ee.read(rc,a); |
Gennanio | 0:25f0bf2e4247 | 26 | wait_ms(1); |
Gennanio | 0:25f0bf2e4247 | 27 | rc++; |
Gennanio | 0:25f0bf2e4247 | 28 | led=a; |
Gennanio | 0:25f0bf2e4247 | 29 | } |
Gennanio | 0:25f0bf2e4247 | 30 | else |
Gennanio | 0:25f0bf2e4247 | 31 | { |
Gennanio | 0:25f0bf2e4247 | 32 | led=127; wait(0.2); |
Gennanio | 0:25f0bf2e4247 | 33 | led=0; wait(0.2); |
Gennanio | 0:25f0bf2e4247 | 34 | led=127; wait(0.2); |
Gennanio | 0:25f0bf2e4247 | 35 | led=0; |
Gennanio | 0:25f0bf2e4247 | 36 | rc=0; |
Gennanio | 0:25f0bf2e4247 | 37 | ee.read(rc,a); |
Gennanio | 0:25f0bf2e4247 | 38 | wait_ms(1); |
Gennanio | 0:25f0bf2e4247 | 39 | rc++; |
Gennanio | 0:25f0bf2e4247 | 40 | led=a; |
Gennanio | 0:25f0bf2e4247 | 41 | } |
Gennanio | 0:25f0bf2e4247 | 42 | } |
Gennanio | 0:25f0bf2e4247 | 43 | else //write |
Gennanio | 0:25f0bf2e4247 | 44 | { |
Gennanio | 0:25f0bf2e4247 | 45 | if(wc>60||rc>60) |
Gennanio | 0:25f0bf2e4247 | 46 | { |
Gennanio | 0:25f0bf2e4247 | 47 | //warning data can be overflow |
Gennanio | 0:25f0bf2e4247 | 48 | led=63; wait(1); |
Gennanio | 0:25f0bf2e4247 | 49 | led=0; wait(1); |
Gennanio | 0:25f0bf2e4247 | 50 | led=63; wait(1); |
Gennanio | 0:25f0bf2e4247 | 51 | led=0; |
Gennanio | 0:25f0bf2e4247 | 52 | //reset eeprom go to address 0 |
Gennanio | 0:25f0bf2e4247 | 53 | wc=0; rc=0; |
Gennanio | 0:25f0bf2e4247 | 54 | } |
Gennanio | 0:25f0bf2e4247 | 55 | sum=0; |
Gennanio | 0:25f0bf2e4247 | 56 | if(in1) sum+=1; |
Gennanio | 0:25f0bf2e4247 | 57 | if(in2) sum+=2; |
Gennanio | 0:25f0bf2e4247 | 58 | if(in3) sum+=4; |
Gennanio | 0:25f0bf2e4247 | 59 | if(in4) sum+=8; |
Gennanio | 0:25f0bf2e4247 | 60 | if(in5) sum+=16; |
Gennanio | 0:25f0bf2e4247 | 61 | if(in6) sum+=32; |
Gennanio | 0:25f0bf2e4247 | 62 | if(in7) sum+=64; |
Gennanio | 0:25f0bf2e4247 | 63 | ee.write(wc,sum); //save |
Gennanio | 0:25f0bf2e4247 | 64 | wait_ms(1); |
Gennanio | 0:25f0bf2e4247 | 65 | wc++; |
Gennanio | 0:25f0bf2e4247 | 66 | } |
Gennanio | 0:25f0bf2e4247 | 67 | } |
Gennanio | 0:25f0bf2e4247 | 68 | wait(0.2); |
Gennanio | 0:25f0bf2e4247 | 69 | } |
Gennanio | 0:25f0bf2e4247 | 70 | } |