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.

help needed interfacing RTC DS1307 with 8051

Status
Not open for further replies.

yviswanathbe

Full Member level 4
Joined
Jun 14, 2007
Messages
221
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,298
Activity points
3,066
Hi friends,

I am doing a Digital Clock using RTC DS1307 and 89C4051 micro controller.

Time is displayed on LCD and different alarms can be set through 3 switches.

I have written the following code for updating RTC registers first time. Only minutes code is shown

Code:
//Minutes
min++;
if((min>15)&&(min<20))
{
onmin=min+6;
}
else if((min>=20) &&(min<30))
{
onmin=min+12;
}
else if((min>=30) &&(min<40))
{
onmin=min+18;
}
else if((min>=40) &&(min<50))
{
onmin=min+24;
}
else if((min>=50) &&(min<60))
{
onmin=min+30;
}
else
{
onmin=min;
}

I have added so many conditions because, when i enter the data from the switches(Increment/decrement), i am storing the value in a integer type. But we need to write BCD value to RTC DS1307. Suppose if i want to update the Minute register with 19, with out the above conditions it is updating as 11.
I hope you all understand my query.
I feel the above code is not efficient, i want to write it with out so many if conditions. Can somebody help me in this regard please?

Thanks and Regards,
Viswanath
 

It's not clear why you need to add multiples of 6.
If you type DS1307 in the search box, it reveals 450 results, so it's highly likely
at least one of them will help you with this device.
There is also this URL which shows in
some extreme detail how to use the DS1307. The microcontroller used was an
AVR device and not an 8051, but that is not relevant.
 

HI,

Thanks for the link. I will definitely go through it.

It's not clear why you need to add multiples of 6.

DS1307 Seconds range is 00-59 BCD.

for example

When i update the seconds register with 16, it is updating as 10 and with 20 it is updating as 14.

So for updating seconds with 16 i need to send 232; and for 206 i need to send 32.

for this reason i have used different loops.

My purpose is solved with the code i have shown in my first post, but i want some help to write the code efficiently.

Thanks and Regards,
Viswanath

- - - Updated - - -

Hi,

Finally i have replaced whole if loop condition with a single sentence and it is working.


Code:
onmin=(((min/10)<<4)+(min%10));

Thanks and Regards,
Viswanath
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top