M24LC64 library

Dependents:   mbed_DEMO

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers M24LC64.cpp Source File

M24LC64.cpp

00001 //**********************
00002 // M24LC64.cpp for mbed
00003 //
00004 // M24LC64 lcd(P0_5,P0_4);
00005 // or
00006 // I2C i2c(P0_5,P0_4);
00007 // M24LC64 lcd(i2c);
00008 //
00009 // (C)Copyright 2014 All rights reserved by Y.Onodera
00010 // http://einstlab.web.fc2.com
00011 //**********************
00012 
00013 #include "mbed.h"
00014 #include "M24LC64.h"
00015 
00016 M24LC64::M24LC64 (PinName sda, PinName scl) : _i2c(sda, scl) {
00017 }
00018 M24LC64::M24LC64 (I2C& p_i2c) : _i2c(p_i2c) {
00019 }
00020 
00021 void M24LC64::put(unsigned int a, unsigned char b)
00022 {
00023     adr.Val=a;
00024     buf[0]=adr.byte.HB;
00025     buf[1]=adr.byte.LB;
00026     buf[2]=b;
00027     _i2c.write(M24LC64_ADDR, buf, 3);
00028     wait_ms(5);
00029 }
00030 
00031 
00032 unsigned char M24LC64::get(unsigned int a)
00033 {
00034     adr.Val=a;
00035     buf[0]=adr.byte.HB;
00036     buf[1]=adr.byte.LB;
00037     _i2c.write(M24LC64_ADDR, buf, 2, true); // no stop, repeated
00038     _i2c.read( M24LC64_ADDR, buf, 1);
00039     return buf[0];
00040 }
00041