This class provides simplified I2C access to a MAXIM DS130x Real-Time Clock device, even if the LPC1768 has an embedded RTC module. My objective is to share the same RTC with Microchip 18F MCU.
Diff: DS130x_I2C.h
- Revision:
- 1:834e9897e269
- Parent:
- 0:a1b58e3c9fdb
--- a/DS130x_I2C.h Wed Feb 09 13:43:21 2011 +0000
+++ b/DS130x_I2C.h Fri Feb 11 10:16:20 2011 +0000
@@ -29,7 +29,7 @@
#include "Debug.h" // Include mbed header + debug primitives. See DebugLibrary
namespace DS130X_I2C {
- /** This class provides simplified I2C access to a MAXIM DS130x Real-Time Clock device. V0.0.0.1
+ /** This class provides simplified I2C access to a MAXIM DS130x Real-Time Clock device. V0.0.0.2
*
* A typical use case should be the Mbed which acts as a time server with an ethernet connection, it synchronyzes a RTC circuit for all other module (Microchip/ATiny MCUs).
*
@@ -143,7 +143,16 @@
* @return The packed BCD value
*/
inline unsigned char ConvertBCDToHex(const unsigned char p_bcdValue) {
- return (unsigned char)((unsigned char)(p_bcdValue >> 4) * 10) + (unsigned char)(p_bcdValue & 0x0f);
+ /*DEBUG("ConvertBCDToHex: %02x - %02x - %02x - %02x - %d",
+ p_bcdValue,
+ (unsigned char)(p_bcdValue >> 4),
+ (unsigned char)((unsigned char)(p_bcdValue >> 4) * 10),
+ (unsigned char)(p_bcdValue & 0x0f),
+ (int)(
+ (unsigned char)((unsigned char)(p_bcdValue >> 4) * 10) | (unsigned char)(p_bcdValue & 0x0f)
+ )
+ )*/
+ return (unsigned char)((unsigned char)(p_bcdValue >> 4) * 10) | (unsigned char)(p_bcdValue & 0x0f);
}
/** This methods converts an hexadecimal value < 99 into a packed BCD (e.g. 0x20 -> 0x32)
@@ -152,7 +161,8 @@
* @return The packed BCD value
*/
inline unsigned char ConvertHexToBCD(const unsigned char p_hexaValue) {
- return (p_hexaValue / 10) << 4 + (p_hexaValue % 10);
+ //DEBUG("ConvertHexToBCD: %02x - %02x - %02x", p_hexaValue, (unsigned char)(p_hexaValue / 10 << 4), (unsigned char)(p_hexaValue % 10))
+ return (unsigned char)(p_hexaValue / 10 << 4) | (unsigned char)(p_hexaValue % 10);
}
/** Restart the clock
Yann Garcia