Lab_interaccio/2015/mcp79400/mcp79400.ino

46 lines
1.9 KiB
Arduino
Raw Permalink Normal View History

2025-02-25 21:29:42 +01:00
#include <Wire.h>
// Set up a serial monitor port and initialize the MCP79400 to run.
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
Wire.beginTransmission(0x6f); // transmit to device address 111 (0x6F)
Wire.write(0); // point to internal register “0”
Wire.write(0x80); // Set highest bit to enable 32KHz clock
Wire.endTransmission(0); // send bytes and stop transmission
delay(5);
Wire.beginTransmission(0x6f); // transmit to device address 111 (0x6F)
Wire.write(7); // point to internal register “7”
Wire.write(0x40); // make MFP pin an output w/ 1HZ square wave
Wire.endTransmission(0); // send bytes and stop transmission
delay(5);
}
// Main program loop reads MCP79400 registers associated with time/date.
void loop()
{
Wire.beginTransmission(0x6f); // transmit to device address 111 (0x6F)
Wire.write(0); // point to internal register “0”
Wire.endTransmission(); // send bytes and stop transmission
Wire.requestFrom(0x6f,6); // reads bytes from sequential addresses
byte Seconds = Wire.read(); // receive a byte
byte Minutes = Wire.read(); // receive a byte
byte Hours = Wire.read(); // receive a byte
byte Day = Wire.read(); // receive a byte
byte Date = Wire.read(); // receive a byte
byte Month = Wire.read(); // receive a byte
byte Year = Wire.read(); // receive a byte
//Convert BCD seconds to total seconds and send to serial monitor
Serial.print((((Seconds&0x70)>>4)*10)+(Seconds&0x0f)); // print seconds
Serial.println(" seconds");
delay(1000);
}