Hiroshi M
/
LPC1114FN28_I2C_24LCXXX
LPC1114FN28 I2C 24LC256 Test Program
main.cpp@0:1d290b4f8374, 2013-12-06 (annotated)
- Committer:
- bant62
- Date:
- Fri Dec 06 10:01:40 2013 +0000
- Revision:
- 0:1d290b4f8374
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bant62 | 0:1d290b4f8374 | 1 | #include "mbed.h" |
bant62 | 0:1d290b4f8374 | 2 | #include "_24LCXXX.h" |
bant62 | 0:1d290b4f8374 | 3 | |
bant62 | 0:1d290b4f8374 | 4 | I2C i2c(dp5,dp27); // sda, scl |
bant62 | 0:1d290b4f8374 | 5 | Serial pc(dp16, dp15); // tx, rx |
bant62 | 0:1d290b4f8374 | 6 | _24LCXXX eeprom(&i2c, 0x50); |
bant62 | 0:1d290b4f8374 | 7 | |
bant62 | 0:1d290b4f8374 | 8 | DigitalOut myled(LED1); |
bant62 | 0:1d290b4f8374 | 9 | |
bant62 | 0:1d290b4f8374 | 10 | int main() { |
bant62 | 0:1d290b4f8374 | 11 | pc.baud(9600); |
bant62 | 0:1d290b4f8374 | 12 | char data1; |
bant62 | 0:1d290b4f8374 | 13 | int data2; |
bant62 | 0:1d290b4f8374 | 14 | |
bant62 | 0:1d290b4f8374 | 15 | pc.printf("memoroy byte data write!\n"); |
bant62 | 0:1d290b4f8374 | 16 | eeprom.byte_write(0, 1); |
bant62 | 0:1d290b4f8374 | 17 | eeprom.byte_write(1, 2); |
bant62 | 0:1d290b4f8374 | 18 | eeprom.byte_write(2, 3); |
bant62 | 0:1d290b4f8374 | 19 | eeprom.byte_write(3, 4); |
bant62 | 0:1d290b4f8374 | 20 | pc.printf("end\n"); |
bant62 | 0:1d290b4f8374 | 21 | |
bant62 | 0:1d290b4f8374 | 22 | eeprom.nbyte_read( 0, &data1, 1 ); |
bant62 | 0:1d290b4f8374 | 23 | pc.printf("0:%02x ",data1); |
bant62 | 0:1d290b4f8374 | 24 | eeprom.nbyte_read( 1, &data1, 1 ); |
bant62 | 0:1d290b4f8374 | 25 | pc.printf("1:%02x ",data1); |
bant62 | 0:1d290b4f8374 | 26 | eeprom.nbyte_read( 2, &data1, 1 ); |
bant62 | 0:1d290b4f8374 | 27 | pc.printf("2:%02x ",data1); |
bant62 | 0:1d290b4f8374 | 28 | eeprom.nbyte_read( 3, &data1, 1 ); |
bant62 | 0:1d290b4f8374 | 29 | pc.printf("3:%02x ",data1); |
bant62 | 0:1d290b4f8374 | 30 | pc.printf("\nend\n"); |
bant62 | 0:1d290b4f8374 | 31 | |
bant62 | 0:1d290b4f8374 | 32 | pc.printf("memoroy int data write!\n"); |
bant62 | 0:1d290b4f8374 | 33 | data2 = 100; |
bant62 | 0:1d290b4f8374 | 34 | eeprom.nbyte_write( 10, &data2, sizeof(int)); |
bant62 | 0:1d290b4f8374 | 35 | pc.printf("\nend\n"); |
bant62 | 0:1d290b4f8374 | 36 | |
bant62 | 0:1d290b4f8374 | 37 | eeprom.nbyte_read( 10, &data2, sizeof(int) ); |
bant62 | 0:1d290b4f8374 | 38 | pc.printf("int:%d ",data2); |
bant62 | 0:1d290b4f8374 | 39 | pc.printf("\nend\n"); |
bant62 | 0:1d290b4f8374 | 40 | |
bant62 | 0:1d290b4f8374 | 41 | while(1) { |
bant62 | 0:1d290b4f8374 | 42 | myled = 1; |
bant62 | 0:1d290b4f8374 | 43 | wait(0.2); |
bant62 | 0:1d290b4f8374 | 44 | myled = 0; |
bant62 | 0:1d290b4f8374 | 45 | wait(0.2); |
bant62 | 0:1d290b4f8374 | 46 | } |
bant62 | 0:1d290b4f8374 | 47 | } |