M24LC64 library
See https://developer.mbed.org/users/yasuyuki/notebook/24LC64/
Revision 0:4ab58ea5ecf6, committed 2014-10-04
- Comitter:
- yasuyuki
- Date:
- Sat Oct 04 12:03:05 2014 +0000
- Commit message:
- first release
Changed in this revision
diff -r 000000000000 -r 4ab58ea5ecf6 M24LC64.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/M24LC64.cpp Sat Oct 04 12:03:05 2014 +0000 @@ -0,0 +1,41 @@ +//********************** +// M24LC64.cpp for mbed +// +// M24LC64 lcd(P0_5,P0_4); +// or +// I2C i2c(P0_5,P0_4); +// M24LC64 lcd(i2c); +// +// (C)Copyright 2014 All rights reserved by Y.Onodera +// http://einstlab.web.fc2.com +//********************** + +#include "mbed.h" +#include "M24LC64.h" + +M24LC64::M24LC64 (PinName sda, PinName scl) : _i2c(sda, scl) { +} +M24LC64::M24LC64 (I2C& p_i2c) : _i2c(p_i2c) { +} + +void M24LC64::put(unsigned int a, unsigned char b) +{ + adr.Val=a; + buf[0]=adr.byte.HB; + buf[1]=adr.byte.LB; + buf[2]=b; + _i2c.write(M24LC64_ADDR, buf, 3); + wait_ms(5); +} + + +unsigned char M24LC64::get(unsigned int a) +{ + adr.Val=a; + buf[0]=adr.byte.HB; + buf[1]=adr.byte.LB; + _i2c.write(M24LC64_ADDR, buf, 2, true); // no stop, repeated + _i2c.read( M24LC64_ADDR, buf, 1); + return buf[0]; +} +
diff -r 000000000000 -r 4ab58ea5ecf6 M24LC64.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/M24LC64.h Sat Oct 04 12:03:05 2014 +0000 @@ -0,0 +1,33 @@ +//********************** +// M24LC64.h for mbed +// +// (C)Copyright 2014 All rights reserved by Y.Onodera +// http://einstlab.web.fc2.com +//********************** + +#ifndef M24LC64_H_ +#define M24LC64_H_ + +#define M24LC64_ADDR 0xA0 + +#include "mbed.h" +#include "typedef.h" + +class M24LC64{ +public: + M24LC64 (PinName sda, PinName scl); + M24LC64 (I2C& p_i2c); + + void put(unsigned int a, unsigned char b); + unsigned char get(unsigned int a); + +protected: + I2C _i2c; + char buf[3]; + WORD_VAL adr; + +}; + + +#endif /* M24LC64_H_ */ +
diff -r 000000000000 -r 4ab58ea5ecf6 typedef.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/typedef.h Sat Oct 04 12:03:05 2014 +0000 @@ -0,0 +1,54 @@ +//********************** +// typedef for mbed +// +// Condition: +// +// (C)Copyright 2014 All rights reserved by Y.Onodera +// http://einstlab.web.fc2.com +//********************** +#ifndef TYPEDEF_H +#define TYPEDEF_H + +typedef unsigned char BYTE; /* 8-bit unsigned */ +typedef unsigned short int WORD; /* 16-bit unsigned */ +typedef unsigned int DWORD; /* 32-bit unsigned */ +typedef unsigned long long QWORD; /* 64-bit unsigned */ + + +typedef union +{ + WORD Val; + BYTE v[2]; + struct + { + BYTE LB; + BYTE HB; + } byte; +} WORD_VAL; + +typedef union +{ + DWORD Val; + WORD w[2]; + BYTE v[4]; + struct + { + WORD LW; + WORD HW; + } word; + struct + { + BYTE LB; + BYTE HB; + BYTE UB; + BYTE MB; + } byte; + struct + { + WORD_VAL low; + WORD_VAL high; + }wordUnion; + +} DWORD_VAL; + +#endif /* TYPEDEF_H */