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.
Diff: mcp7940n.cpp
- Revision:
- 2:4b7f5a060c22
- Child:
- 3:6ca4d7dd8bea
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcp7940n.cpp Sun Oct 01 19:30:04 2017 +0000 @@ -0,0 +1,37 @@ +#include "i2c.h" +#include "mcp7940n.h" + +//endere�o do dispositivo, deslocado por causa do bit de RW +//1101000 +#define MCP7940N_CTRL_ID (0x6e<<1) +#define I2C_WRITE 0 +#define I2C_READ 1 + +int dec2bcd(int value) { + return ((value / 10 * 16) + (value % 10)); +} +int bcd2dec(int value) { + return ((value / 16 * 10) + (value % 16)); +} +void mcpInit(void) { + i2cInit(); +} +void mcpStartClock(void) { + int seconds; + seconds = mcpReadData(SEC); + mcpWriteData(0x7f & seconds,SEC); + return; +} +void mcpWriteData(unsigned char value, int address) { + i2cWriteByte(1,0, MCP7940N_CTRL_ID |I2C_WRITE); + i2cWriteByte(0,0,address); + i2cWriteByte(0,1,value); +} +int mcpReadData(int address) { + int result; + i2cWriteByte(1,0,MCP7940N_CTRL_ID | I2C_WRITE); + i2cWriteByte(0,0,address); + i2cWriteByte(1,0, MCP7940N_CTRL_ID | I2C_READ); + result = i2cReadByte(1,1 ); + return result; +}