Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to know the last day of the month in DS1307 RTCC ?

Status
Not open for further replies.

ADGAN

Full Member level 5
Full Member level 5
Joined
Oct 9, 2013
Messages
295
Helped
4
Reputation
8
Reaction score
4
Trophy points
18
Visit site
Activity points
1,837
Hi! I'm using a DS1307 as a RTCC for my design. I need to know the last date of the month & need to display it on the LCD. Does anybody know how to do it in a direct or a indirect method ?

Note:
I'm using MikroC pro & PIC18F45k22
 
Last edited:

There are software routines that take a given year/month/day, and convert to Julian days. (Astronomers use Julian days to track time.)

If you know what day falls on Jan. 1, then you divide the difference by 7 (or use MODULO command), and the remainder tells you how many days you should add to the day on Jan. 1. And you arrive at your answer.
 
  • Like
Reactions: ADGAN

    ADGAN

    Points: 2
    Helpful Answer Positive Rating
Thanks for the reply. Can you elaborate your answer and please note that I made a mistake in the previous post. I need the date not the day.
 

Date register address 0x04


Range 01 - 31

BIT7 BIT6 BIT5 BIT4 BIT3 BIT2 BIT1 BIT0


Bits0 to Bits3 = units place
Bits 4 and 5 are tens place
Bits 6 and 7 are always 0


for date 31 you need BD 31

BCD 31 =

0011 0001

You write

11 to bits 4 and 5 and 0001 to bits 0 to 3.
 
Last edited:

Thanks for the reply. But I want to display the last date of the previous month on the LCD throughout the current month. The problem is some months have 28, 29, 30 or 31 days
 

PHP:
algo

if month = jan, mar, may, july, aug, oct, dec then

	if date = 31?

		memdata = date

else if month = feb, apr, jun, sep, nov then

	if month = feb then

		if year = leap then

			if date = 28 then

				memdate = date

		else if year not leap

			if date = 29 then
		
				memdate = date


	else if month != feb then

		if date = 30 then

			memdate = date
 
  • Like
Reactions: ADGAN

    ADGAN

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top