Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
myi2c.cpp
00001 #include "myi2c.h" 00002 00003 PCF8563::PCF8563(PinName sda, PinName scl) : i2c (sda, scl) 00004 { 00005 i2c.frequency(PCF8563_FREQ); //set the frequency 00006 } 00007 /* 00008 * read function from the TRC 00009 * read a value and return it 00010 */ 00011 uint8_t PCF8563::read(int i2c_r, int address) 00012 { 00013 uint8_t value; //temp 8bit 00014 i2c.start(); //start 00015 i2c.write(i2c_r); //write address 00016 i2c.write(address); 00017 i2c.start(); //restart 00018 i2c.write(address); //read address 00019 value = i2c.read(0); 00020 i2c.stop(); 00021 00022 return value; //returns var value of the method 00023 } 00024 uint8_t PCF8563::read(int i2c_w, int i2c_r, int address) 00025 { 00026 uint8_t value; //temp 8bit 00027 i2c.start(); //start 00028 i2c.write(i2c_w); //write address 00029 i2c.write(address); 00030 i2c.start(); //restart 00031 i2c.write(i2c_r); //read address 00032 value = i2c.read(0); 00033 i2c.stop(); 00034 return value; 00035 } 00036 /* firtly you write the address from the rtc 00037 * secondly the register address 00038 * last but not leat your value 00039 */ 00040 void PCF8563::write(int i2c_w, int address, int value) 00041 { 00042 i2c.start(); //start 00043 i2c.write(i2c_w); //i2c write address 00044 i2c.write(address); 00045 i2c.write(value); 00046 i2c.stop(); //stop 00047 } 00048 /* 00049 * Binary Coded Decimal converter into decimal 00050 */ 00051 uint8_t PCF8563::bcdToDec(uint8_t val) 00052 { 00053 return (10*((val>>4)& 0x0F)+(val & 0x0F)); //convert from bcd to dec 00054 }
Generated on Sun Jul 24 2022 20:18:01 by
