Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. void rtc_setCG(byte val);
  2. const byte rtc_id = 0x68; //DS1307 i2c id: 0x68h, 104 dec, 150 octal, 1101000b
  3. pinMode(2, INPUT_PULLUP);
  4. attachInterrupt (digitalPinToInterrupt(2), rtcout_int, FALLING);
  5.  
  6. void rtcout_int ()
  7. { char buf[5] = " ";
  8. time_t now;
  9. struct tm *ts;
  10.  
  11. wdt_reset();
  12. noInterrupts();
  13. epoque++; //this is a global volatile unsigned long variable that holds the number of seconds since the arduino epoque
  14. interrupts();
  15. }
  16. void rtc_setCG(byte val)
  17. { Wire.beginTransmission(rtc_id);
  18. Wire.write((byte)0x07);
  19. Wire.write(val);
  20. Wire.endTransmission();
  21. }
  22. ISR (TIMER1_COMPA_vect)
  23. { byte nsecond;
  24. nsecond=(byte)((millis()/1000) % 60);
  25. if ( nsecond != second )
  26. { second=nsecond;
  27. epoque++;
  28. minute=(byte)((epoque / 60) % 60);
  29. hour=(byte)(((epoque / 3600) + timezone) % 24);
  30. }
  31. }
  32. rtc_setCG(0x10); //this is how I set up the ds1307 to do 1hz on the SQW/OUT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement