ftyrityrytrtyrtyrtyrtyrgtrghf
main.cpp@14:f7e3d84f3970, 2018-11-30 (annotated)
- Committer:
- sunninety1
- Date:
- Fri Nov 30 05:12:23 2018 +0000
- Revision:
- 14:f7e3d84f3970
- Parent:
- 13:d4ed04e04e9b
123514532521352wtretui\;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bi18rdbi18rd | 5:eb65bd646089 | 1 | |
soulx | 0:8b5e53600ba0 | 2 | #include "mbed.h" |
soulx | 0:8b5e53600ba0 | 3 | #include "eeprom.h" |
bi18rdbi18rd | 5:eb65bd646089 | 4 | |
sunninety1 | 14:f7e3d84f3970 | 5 | EEPROM memory(PB_9,PB_8,5);// Pinname sda=PB_9 , Pinname scl=PB_8 , address=0 |
soulx | 0:8b5e53600ba0 | 6 | |
soulx | 0:8b5e53600ba0 | 7 | int main() |
soulx | 0:8b5e53600ba0 | 8 | { |
Pitiwut | 8:1628d2c67f5e | 9 | //// Initial data to write ///// |
Pitiwut | 8:1628d2c67f5e | 10 | int8_t data_dummy = 'r'; |
Pitiwut | 8:1628d2c67f5e | 11 | int8_t data[4]; |
Pitiwut | 8:1628d2c67f5e | 12 | float x = 0.0f; |
Pitiwut | 8:1628d2c67f5e | 13 | float j = 9785.26844; |
bi18rdbi18rd | 5:eb65bd646089 | 14 | |
Pitiwut | 8:1628d2c67f5e | 15 | //// Write data to Address 1 and 2 |
sunninety1 | 14:f7e3d84f3970 | 16 | memory.write(0x0001,(int8_t)data_dummy);// write(address 16bit , data 8bit) |
bi18rdbi18rd | 5:eb65bd646089 | 17 | wait_ms(1); |
Pitiwut | 9:70102b54bfcd | 18 | memory.write(0x0002,(int8_t)'c'); |
bi18rdbi18rd | 5:eb65bd646089 | 19 | wait_ms(1); |
Pitiwut | 8:1628d2c67f5e | 20 | |
Pitiwut | 13:d4ed04e04e9b | 21 | /// Read data from address 0x0001 to 0x0004, and store in data array |
sunninety1 | 14:f7e3d84f3970 | 22 | memory.read(0x0001,data,4); /* read at adress 0001=1 เก็บไว้ที่ array data ตำแหน่ง |
sunninety1 | 14:f7e3d84f3970 | 23 | ที่ 1-4 โดยตัวที่ตำแหน่ง 0x0001 จะถูกอ่านแล้วเก้บไว้ที่ data[0] 0x0002 --> data[1] 0x0003 --> data[2] 0x0004--> data[3] */ |
bi18rdbi18rd | 5:eb65bd646089 | 24 | wait_ms(1); |
Pitiwut | 8:1628d2c67f5e | 25 | |
Pitiwut | 8:1628d2c67f5e | 26 | printf("read[1] = %c\n",data[0]); |
Pitiwut | 8:1628d2c67f5e | 27 | printf("read[2] = %c\n",data[1]); |
Pitiwut | 8:1628d2c67f5e | 28 | printf("read[3] = %c\n",data[2]); |
Pitiwut | 8:1628d2c67f5e | 29 | printf("read[4] = %c\n",data[3]); |
bi18rdbi18rd | 5:eb65bd646089 | 30 | |
Pitiwut | 13:d4ed04e04e9b | 31 | //// Write float data to address 0x000A |
Pitiwut | 9:70102b54bfcd | 32 | memory.write(0x000A,j); |
bi18rdbi18rd | 5:eb65bd646089 | 33 | wait_ms(1); |
bi18rdbi18rd | 5:eb65bd646089 | 34 | |
Pitiwut | 8:1628d2c67f5e | 35 | //// Read float data, and store to x |
sunninety1 | 14:f7e3d84f3970 | 36 | memory.read(0x000A,x);// อ่านตัวแปรที่ตำแหน่ง 0x000A แล้วเก็บค่านั้นไว้ที่ x ซึ่งทำให้ตอนนี้ x=j |
bi18rdbi18rd | 5:eb65bd646089 | 37 | wait_ms(1); |
Pitiwut | 8:1628d2c67f5e | 38 | |
bi18rdbi18rd | 5:eb65bd646089 | 39 | printf("float = %f\n",x); |
Pitiwut | 11:8d8c3e003153 | 40 | |
Pitiwut | 13:d4ed04e04e9b | 41 | /// Read data from address 0x000A to 0x000D, and store in data array |
sunninety1 | 14:f7e3d84f3970 | 42 | memory.read(0x000A,data,4);//อ่านค่าที่อยู่ใน adress 0x000A-->data[0] 0x000B-->data[1] 0x000C-->data[2] 0x000D-->data[3] |
Pitiwut | 12:4c5be5aadf51 | 43 | printf("read[1]:0x000A = %X\n",(uint8_t)data[0]); |
Pitiwut | 12:4c5be5aadf51 | 44 | printf("read[2]:0x000B = %X\n",(uint8_t)data[1]); |
Pitiwut | 12:4c5be5aadf51 | 45 | printf("read[3]:0x000C = %X\n",(uint8_t)data[2]); |
Pitiwut | 12:4c5be5aadf51 | 46 | printf("read[4]:0x000D = %X\n",(uint8_t)data[3]); |
sunninety1 | 14:f7e3d84f3970 | 47 | // float j=9785.26844= 0x4618E513 แล้วถูกซอยย่อยเป็น 46-->data[3] 18-->data[2] E5-->data[1] 13-->data[0] |
bi18rdbi18rd | 5:eb65bd646089 | 48 | |
soulx | 0:8b5e53600ba0 | 49 | } |