i2c RTC LCD Countdown Timer

Mad Professor

Senior Member
Good Day All.

This will be my 1st project that uses any i2c based units.

As of yet I don't have any of the hardware but it has been ordered.
1x AXE012X2
1x AXE033B
1x AXE034

The rest of the parts I can pick up locally.

I have spent the best part of the day searching the forum, so I would not need to post, but yet again I must admit defeat and post requesting help.

To start with all I need to learn how to do is code a 5 min countdown timer using the i2c Real Time Clock, and i2c LCD display.

Once I can get that working, I can then look into expanding.

As said before I have never done any work with i2c.

I don't want anyone to write the full program (code) for me, but any working examples or links to posts to get me start would be grate.

Thanks for your time.

Best Regards.
 

Chavaquiah

Senior Member
I think the DS1307 does not have a count down mode. That would make it all very easy but is certainly not a show stopper.

You could start by using the square wave output. Setting it to 1Hz and then counting pulses until 5x60 seconds elapse. The Picaxe might keep a counter for minutes and one for seconds, initialized to 5 and zero, respectively. For each tick of the clock, the seconds counter would be decremented. When seconds goes below zero (i.e., goes to 255 if using a byte variable) it gets reset to 59 and the minutes counter is decremented. When both reach zero, the bomb goes off... errr... I mean... the buzzer sounds, the LED flashes and all that.

Another way would be to continuously check the time. When the counter starts you read current time and add 5 minutes to it (watching for minutes/hours overflow). When that time is read back, the countdown ends. Of course, to display an up to date countdown on the LCD, a little math is needed. Many ways to achieve it. My preferred method is to use an "internal" time expressed in seconds (measured from, say, the top of the hour). So that 30 means 0m30s and 1085 is 18m5s (18*60+5).
 

BeanieBots

Moderator
I'd agree with Chavaquiah.
For a countdown timer, it would probably be easier to use the 1Hz signal and count the pulses than it would be to use the RTC data.

If however, you want to use this as an oportunity to learn about I2C and the RTC chip, then step one will be to download the DS1307 datasheet.
Also, get familiar with the BCD method of representing data.

After doing that, you will probably have some specific questions which will get more specific answers.
 

inglewoodpete

Senior Member
If however, you want to use this as an oportunity to learn about I2C and the RTC chip, then step one will be to download the DS1307 datasheet.

>>>>Also, get familiar with the BCD method of representing data.<<<<
Don't forget to have a look at the DS1307 sample program in the Samples folder of the Programming Editor. It is a great leg-up to get you started. I've just completed a project using the DS1307 (not a countdown timer, though).
 
Last edited:

westaust55

Moderator
You can also use the Programming Editor AXE110 datalogger wizard and extract a same of the output code to see how they set up a duration interval for data logging.

Basically, the PE wizard code takes the current time from the DS1307, adds the necessary interval duration and then interrogates the DS1307 until the desired time has been reached.

If your code is not doing anyting else during the propsed 5 minute period then that method works and demonstrates/utilises more i2c comms than just setting the clock output pulse

Just determine the time for the endf of the interval and then subtract the current time to determine the remaining duration for your display.

Do you have to display in just seconds or minutes and seconds?
 
Last edited:

Mad Professor

Senior Member
eclectic: for this count down timer I could do it without the use of i2c, but I have few project ideas that will have to use i2c, so I might as well start learning.

inglewoodpete: I totally forgot about the Programming Editor Samples folder, I will have a look at that.

westaust55: I guess the countdown in just seconds would be easier, but I would prefer to have the countdown in minutes and seconds.
 

westaust55

Moderator
If you have the total reminaing seconds derived from a count down or whatever method, the display of the remaining Minutes and Seconds from total remaining seconds:

Minutes = TotalSeconds / 60
Seconds = TotalSeconds // 60
 
Top