I2C Real Time Clock (DS1307)

The DS1307 Real Time Clock is an I2C device which provides all the timekeeping functions of a calendar and clock. Used with a backup battery it can keep track of date and time even when the main circuit power is removed.

The DS1307 Real Time Clock and other I2C devices (I2C EEPROM) connect to the PICAXE using a two-wire I2C bus and can be controlled with a range of I2C specific commands.

Related Commands:

Print Page

Share

Schematic

PCB

Set and read a DS1307 real time clock

Example of how to use DS1307 Time Clock (i2c device) Note the data is sent/received in BCD format.

Code Example:
symbol seconds = b0
symbol mins = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7

	; set DS1307 slave address
	
	i2cslave %11010000, i2cslow, i2cbyte

	; Initialise the clock - "Thu 2003-12-25 11:59:00" 

	let day     = $03	; 03 Note all BCD format
	let year    = $03	; 03 Note all BCD format
	let month   = $12	; 12 Note all BCD format
	let date    = $25	; 25 Note all BCD format
	let hour    = $11	; 11 Note all BCD format
	let mins    = $59	; 59 Note all BCD format
	let seconds = $00	; 00 Note all BCD format
 	let control = %00010000 ; Enable output at 1Hz

	writei2c 0,(seconds,mins,hour,day,date,month,year,control)
main:
	; Read the clock time

	readi2c 0,(seconds,mins,hour,day,date,month,year)
	
	; Report time read

	debug

	pause 500
	goto main




Copy Code Submit an Example

Create Module

A DS1307 I2C real-time clock can be connected using two generic terminal block create modules to carry the SDA and SCL signals of the I2C bus.

Bill of Materials

DescriptionCodeQty
DS1307 i2c realtime clock MIC055 1 Buy Now
8-pin 0.3" DIP IC Socket ICH008 1 Buy Now
32.768kHz watch crystal (12pF) RES038 1 Buy Now
4k7 resistor (pack 100) RES4K7 1 Buy Now
100nF miniature polysester capacitor CAP001 1 Buy Now
3.0 V Lithium button cell CR2032. BAT004 1 Buy Now
3.0 V Lithium button cell CR2032 holder BAT004H 1 Buy Now

Simulation

No Image Selected

Submit Your Own Code!

You must be logged in to submit code examples. Login now.

Comments

  • Posted by daniel0055

    good how do I set the time to push barias tried to shape and noda works because I use the picaxe 18m2 and also I have the 28x2 gracis and good day.

  • Posted by daniel0055

    good as I can set the time with buttons use the picaxe 18m2 and also I have the 28x2 gracis and good day.

  • Login to leave a comment.