problem with rtc ds1307 code


Im new to this so plz try to help me :slight_smile:

Im trying to load a code that i found online that will dimm leds,
i want over the code and correct all the errors but i left with one error
in the rtc code.
im using Tiny rtc ds1307.

i’ve tried to run the only the rtc code but im still getting the same error:
error: expected declaration before ‘}’ token
i changed the { back and forward to try to solve this buy when
i change it im only get more errors.

thats the code for the rtc:

// include the libraries:
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Button.h>
#include <EEPROM.h>
#include <EEPROMVar.h>

// set the RTC's I2C address
#define DS1307_I2C_ADDRESS 0x68

// Convert decimal numbers to binary coded decimal
byte decToBcd(byte val)
  return ( (val/10*16) + (val%10) );

// Convert binary coded decimal to decimal numbers
byte bcdToDec(byte val)
  return ( (val/16*10) + (val%16) );

// Sets date and time, starts the clock
void setDate(byte second,        // 0-59
             byte minute,        // 0-59
             byte hour,          // 1-23
             byte dayOfWeek,     // 1-7
             byte dayOfMonth,    // 1-31
             byte month,         // 1-12
             byte year);          // 0-99

// Gets the date and time
void getDate(byte *second,
             byte *minute,
             byte *hour,
             byte *dayOfWeek,
             byte *dayOfMonth,
             byte *month,
             byte *year);
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
  *second     = bcdToDec( & 0x7f);
  *minute     = bcdToDec(;
  *hour       = bcdToDec( & 0x3f);
  *dayOfWeek  = bcdToDec(;
  *dayOfMonth = bcdToDec(;
  *month      = bcdToDec(;
  *year       = bcdToDec(;

plz help me find what is wrong in this code.


Brace is facing wrong way


void setDate(byte second,        // 0-59
             byte minute,        // 0-59
             byte hour,          // 1-23
             byte dayOfWeek,     // 1-7
             byte dayOfMonth,    // 1-31
             byte month,         // 1-12
             byte year);  <<--semicolon should not be there        // 0-99
} << - wrong way round
{  <<-- wrong way round

sp. “please”

thank you AWOL,

i change that and new errors come up
error: no matching function for call to 'TwoWire::read(byte)'

i think its the wire librarie, how i can solve it?;

Well, call me perverse, but shouldn’t that be “write” ?

I have tried all of the available libraries for real time clocks, rtc. I could not get any of them to function as I wanted.
After studying the libraries, I found that the libraries made accessing rtc's more complicated than necessary.

Years ago, I wrote a BASIC program for a Basic Stamp micro-controller to access a rtc module, so I ported it to Arduino.
Using the Wire library, it is surprisingly easy to access a rtc.

Later I purchased a new module with battery backup, I did not want to keep setting the time and date.
I have rewritten my rtc sketch to access the new module. This module uses a DS3232 chip which is very similar to the DS1307.
The first seven addresses are identical: seconds, minutes, hours, Day of Week(1 - 7), Day of Month(1 - 31), month, year.
The DS3232 has gained only 9 seconds in 192 days of operation, most of which was on battery backup.

I use a Arduino Mega because it has 3 extra serial ports. I use one of these extra ports for a serial lcd to display the time and other data.
My lcd is a Modern Device serial display (LCD117), it has a easy to learn command set and only uses one wire to connect to a serial port.

Let me know if your would like me to post my rtc sketch.