-
-
Save boxalljohn/6118564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DS1307 Square-wave machine sketch for Arduino | |
#include "Wire.h" | |
#define DS1307_I2C_ADDRESS 0x68 // each I2C object has a unique bus address, the DS1307 is 0x68 | |
void setup() | |
{ | |
Wire.begin(); | |
} | |
void sqw1() // set to 1Hz | |
{ | |
Wire.beginTransmission(DS1307_I2C_ADDRESS); | |
Wire.write(0x07); // move pointer to SQW address | |
Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) | |
Wire.endTransmission(); | |
} | |
void sqw2() // set to 4.096 kHz | |
{ | |
Wire.beginTransmission(DS1307_I2C_ADDRESS); | |
Wire.write(0x07); // move pointer to SQW address | |
Wire.write(0x11); // sends 0x11 (hex) 00010001 (binary) | |
Wire.endTransmission(); | |
} | |
void sqw3() // set to 8.192 kHz | |
{ | |
Wire.beginTransmission(DS1307_I2C_ADDRESS); | |
Wire.write(0x07); // move pointer to SQW address | |
Wire.write(0x12); // sends 0x12 (hex) 00010010 (binary) | |
Wire.endTransmission(); | |
} | |
void sqw4() // set to 32.768 kHz (the crystal frequency) | |
{ | |
Wire.beginTransmission(DS1307_I2C_ADDRESS); | |
Wire.write(0x07); // move pointer to SQW address | |
Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) | |
Wire.endTransmission(); | |
} | |
void sqwOff() | |
// turns the SQW off | |
{ | |
Wire.beginTransmission(DS1307_I2C_ADDRESS); | |
Wire.write(0x07); // move pointer to SQW address | |
Wire.write(0x00); // turns the SQW pin off | |
Wire.endTransmission(); | |
} | |
void loop() | |
{ | |
sqw1(); | |
do {} while (1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment