filmov
tv
Arduino DS1307 Real Time Clock Square Wave Generator
![preview_player](https://i.ytimg.com/vi/SXnqI23XXxQ/maxresdefault.jpg)
Показать описание
Using an Arduino to set square wave frequencies on the SQWOut pin of the DS1307 real time clock chip.
Arduino sketch:
#include "Wire.h"
#include "Time.h"
#define DS1307_I2C_ADDRESS 0x68
// 00010000 to produce a 1 Hz square wave
// from the SQW pin. 00010011 for 32.768 kHz.
// 00010001 for 4.096 kHz. and 00010010 for
// 8.192 kHz. The square wave output
// can be viewed on an oscilloscope.
byte ctrlRegBytes[] = {B00010000, B00010001, B00010010, B00010011};
int freqIdx = 3;
void setup()
{
initFreqDs1307();
}
void loop()
{
}
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
void initFreqDs1307()
{
setFreqDs1307();
}
void setFreqDs1307()
{
byte ctrlRegByte = ctrlRegBytes[freqIdx];
}
Arduino sketch:
#include "Wire.h"
#include "Time.h"
#define DS1307_I2C_ADDRESS 0x68
// 00010000 to produce a 1 Hz square wave
// from the SQW pin. 00010011 for 32.768 kHz.
// 00010001 for 4.096 kHz. and 00010010 for
// 8.192 kHz. The square wave output
// can be viewed on an oscilloscope.
byte ctrlRegBytes[] = {B00010000, B00010001, B00010010, B00010011};
int freqIdx = 3;
void setup()
{
initFreqDs1307();
}
void loop()
{
}
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
void initFreqDs1307()
{
setFreqDs1307();
}
void setFreqDs1307()
{
byte ctrlRegByte = ctrlRegBytes[freqIdx];
}
Комментарии