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.

RTC DS1307 Interfacing with MCU 89S52

Status
Not open for further replies.
rtc interfacing pin diagram

laktronics said:
Hi,
I am sorry, I should have advised you this earlier, you should get everything about 8052 at www.8052.com. You should visit their code section, and I am sure your clock should me ticking over there, may be you have to join the forum to go to code section.
Regards,
Laktronics

so, this is the reason for lots of threads of RTC left incompleted by users...??:cry:
 

89s52 +reset +prevent

I never used the DS1307 RTC so I'ts just a guess after reading pages 11 to 13 of datasheet.

As I understood the text you need to send this data to write to the RTC:
1) generate a start condition
2) send the address of the DS1307 and the R/W bit : 11010000
3) generate an extra SCL pulse and check for ACK bit from RTC
4) ACK ok then send an address byte (see table 2 for addresses) 01h for minutes
5) generate an extra SCL pulse and check for ACK bit from RTC
6) ACK ok then send the minutes data (0101 1001 for 59 minutes)
7) generate an extra SCL pulse and check for ACK bit from RTC
8) generate a stop condition

To read something from the RTC follow the same steps
1) generate a start condition
2) send the address of the DS1307 and the R/W bit : 11010001
3) generate an extra SCL pulse and check for ACK bit from RTC
4)ACK ok then read the minutes data
5) generate an extra SCL pulse and check for ACK bit from RTC
6) generate a stop condition

Why do you read the minutes in the above sequence?
Because your last write was to that register.

If you want to read another register you need to build up a sequence according to figure 6.
First a write to set a register in the RTC then a read to read the data from that register. Of course wit all start/stop/ACK stuf in between.

I agree that figures 4 to 6 are a littke confusing because of the Data(n), Data(n+1) stuff but according to the text you can send/receive only one byte at the time.

I think the RTC laks an auto incrementing pointer so that you could read/write consecutive addresses without setting the address first.



If it doesn't work, don't shoot me, re-read the first sentence of this post :) :)
 

    H_D_R

    Points: 2
    Helpful Answer Positive Rating
coding forinterfacing ds1307 with 89s52

Thank you mcs51mc,

:D:D:D hello, i am not going to shoot anyone...

i am requesting for help not ordering... :)

i understand these all thing and i am on the way of implementing the clock already.
hope so i'll be able to complete atleast read/write operation till tonight..!! :!:
 

89s52 reset input

hello every one..

one good news is there..

i have got success in making clock.

but still i have to add alarm and not a single but four alarm...??

so ithere anybody who can help me ittle bit..

i am facing problem to store alarm..

thanks to you all for helping me....
 

watchdog timer 89s52 asm code

vietdung79 said:
Try some Voice Recorder ICs such as ISD2560.

THANKS FOR THE INFORMATION..
BUT FOR YOUR KIND INFO. I WANT TO DISPLAY UPDATES ON LCD AND LED.
I JUST WANT TO GLOW LED.
SO NO NEED TO USE THIS IC.
BY THE WAY I AM HAVING PROBLEM ONLY TO STORE THE ALARM TIME IN RTC.

CAN ANYBODY HELP ME...???
 

how to use the address for isd2560

One problem down... ... n to go :):)

Correct me if I'm wrong but the DS doesn't have any alarm time registers so where do you think to store the alarm time?

What was your idea about storing time and compare actual time & alarm time?

My basic idea is:
1) EEPROM to store all alarm times (day of week, hour, minute (, second)).
2) On second or minute basis compare actual time and alarm times.
3) Use PC to download alarmtimes into clock.
 

    H_D_R

    Points: 2
    Helpful Answer Positive Rating
interfacing of eeprom at24c02 with 8052

thanks for reply mcs51mc

Correct me if I'm wrong but the DS doesn't have any alarm time registers so where do you think to store the alarm time?

sir, i know there is no register to store the alarm time but it has 56bytes user space, where we can store the time.
and i am also using that only.

What was your idea about storing time and compare actual time & alarm time?

My basic idea is:
1) EEPROM to store all alarm times (day of week, hour, minute (, second)).
2) On second or minute basis compare actual time and alarm times.
3) Use PC to download alarmtimes into clock.

i am not using PC to store the real time.
i am setting real time mannually through key pad.

can you help me....????
 

isd2560

Since you enter real time through keypad, you can also enter alarm times through keypad :)

Do you want accuracy of alarmtime on second or minute level?
I mean is alarmtime 07:25 ok or do you need 07:25:35?

Do you need alarmtime based on day of week or not?
Same time for all days of week or not?

The answers to the above questions will determine which data needs to be stored in the 56 bytes of RAM.
Please keep in mind that you will need a battery backup or all you alarms will be gone at the first power down :(

One alarmtime can looks like:
Byte 0: 3 bits = day of week -- 5 bit = alarm hour in 24 hour system
OR
Byte 0: 3 bits = day of week -- 1 bit = AM/PM -- 4 bit = alarm hour in 12 hour system
Byte 1: alarm minute
Byte 2: alarm second if needed

You need 4 alarms? That's 8 or 12 bytes in RAM.

Endless loop in your µC:
Read actual time
Read alarm time 1 : compare with actual time : if needed set alarm bit
Read alarm time 2 : compare with actual time : if needed set alarm bit
Read alarm time 3 : compare with actual time : if needed set alarm bit
Read alarm time 4 : compare with actual time : if needed set alarm bit
 

    H_D_R

    Points: 2
    Helpful Answer Positive Rating
rtc ds1307 code mcs51

Since you enter real time through keypad, you can also enter alarm times through keypad :)

Do you want accuracy of alarmtime on second or minute level?
I mean is alarmtime 07:25 ok or do you need 07:25:35?

minute level is ok.

Do you need alarmtime based on day of week or not?
Same time for all days of week or not?

based on day of the week

The answers to the above questions will determine which data needs to be stored in the 56 bytes of RAM.

Please keep in mind that you will need a battery backup or all you alarms will be gone at the first power down :(

i have battery backup already.

One alarmtime can looks like:
Byte 0: 3 bits = day of week -- 5 bit = alarm hour in 24 hour system
OR
Byte 0: 3 bits = day of week -- 1 bit = AM/PM -- 4 bit = alarm hour in 12 hour system
Byte 1: alarm minute
Byte 2: alarm second if needed


You need 4 alarms? That's 8 or 12 bytes in RAM.

Endless loop in your µC:
Read actual time
Read alarm time 1 : compare with actual time : if needed set alarm bit
Read alarm time 2 : compare with actual time : if needed set alarm bit
Read alarm time 3 : compare with actual time : if needed set alarm bit
Read alarm time 4 : compare with actual time : if needed set alarm bit

sorry to say but, the bold one part of your answer is confusing me..
can you tell me in bit detail or please send me the link from where you have got this detail.
 

ds1307 block

I'm sorry but I have no link to my brain :):):(

Each alarm is defined as follow:
a) days of week it should be active
b) hour : can be defined as 0 to 12h and AM/PM bit or 0 to 24h
c) minute : any number between 0 and 59

So you have to store this data in RAM for every single alarm.

You can do it as follow:
First byte : days of week alarm active
Bit 0 : Monday
Bit 1 : Tuesday
Bit 2 : Wednesday
Bit 3 : Thursday
Bit 4 : Friday
Bit 5 : Saterday
Bit 6 : Sunday
Bit 7 : not used

Second byte : hour in 12h and AM/PM bit mode
Bit 0 to 3 : alarm hour, any number between 0 and 11
Bit 4 : AM/PM bit
Bit 5 to 7 : not used

Second byte : hour in 24h mode
Bit 0 to 4 : alarm hour, any number between 0 and 23
Bit 5 to 7 : not used

Third byte : minute : any number between 0 and 59
Bit 0 to 5 : alarm minute, any number between 0 and 59
Bit 6 & 7 : not used


Let say you store all your data from byte 10h in RAM of the RTC
10h : Alarm 1, days of week active
11h : Alarm 1, hour
12h : Alarm 1, minute
13h : Alarm 2, days of week active
14h : Alarm 2, hour
15h : Alarm 2, minute
16h : Alarm 3, days of week active
17h : Alarm 3, hour
18h : Alarm 3, minute
19h : Alarm 4, days of week active
1Ah : Alarm 4, hour
1Bh : Alarm 4, minute

Hope this new configuration is clear to you.


Now I realise that there's an error in my previous configuration.
The three bits for day of week allow only one day with alarm :(
So please forget about it.
 

    H_D_R

    Points: 2
    Helpful Answer Positive Rating
89s52 ds1307

I'm sorry but I have no link to my brain :):):(

great...!!! :eek:


Each alarm is defined as follow:
a) days of week it should be active
c) minute : any number between 0 and 59

b) hour : can be defined as 0 to 12h and AM/PM bit or 0 to 24h

i think something wrong is here..??:?:

So you have to store this data in RAM for every single alarm.

You can do it as follow:
First byte : days of week alarm active
Bit 0 : Monday
Bit 1 : Tuesday
Bit 2 : Wednesday
Bit 3 : Thursday
Bit 4 : Friday
Bit 5 : Saterday
Bit 6 : Sunday
Bit 7 : not used

how can i access it..?? i have only four keys.
by the way i have implemented for storing day,
in which it is comparing day with 1 to 7 and start from sunday to saturday.
and its working perfectly too..
but if i am using same code with different RAM loacation to store it as
Alarm On-Day and Alarm Off-Day then its not working..??:cry:

Second byte : hour in 12h and AM/PM bit mode
Bit 0 to 3 : alarm hour, any number between 0 and 11
Bit 4 : AM/PM bit
Bit 5 to 7 : not used

i have to take alook for some details if i could get on net..

Second byte : hour in 24h mode
Bit 0 to 4 : alarm hour, any number between 0 and 23
Bit 5 to 7 : not used

Third byte : minute : any number between 0 and 59
Bit 0 to 5 : alarm minute, any number between 0 and 59
Bit 6 & 7 : not used

understand clearly and already implemented in my code too not same but little bit same.


Let say you store all your data from byte 10h in RAM of the RTC
10h : Alarm 1, days of week active
11h : Alarm 1, hour
12h : Alarm 1, minute
13h : Alarm 2, days of week active
14h : Alarm 2, hour
15h : Alarm 2, minute
16h : Alarm 3, days of week active
17h : Alarm 3, hour
18h : Alarm 3, minute
19h : Alarm 4, days of week active
1Ah : Alarm 4, hour
1Bh : Alarm 4, minute

i am thinking in same way but first atleast one alarm should work..

Hope this new configuration is clear to you.
thanks for replying..

Now I realise that there's an error in my previous configuration.
The three bits for day of week allow only one day with alarm :(
So please forget about it.
i have implemented and its working perfectly..
 

89s52 ds1307 i2c

H_D_R said:
So you have to store this data in RAM for every single alarm.

You can do it as follow:
First byte : days of week alarm active
Bit 0 : Monday
Bit 1 : Tuesday
Bit 2 : Wednesday
Bit 3 : Thursday
Bit 4 : Friday
Bit 5 : Saterday
Bit 6 : Sunday
Bit 7 : not used

how can i access it..?? i have only four keys.
by the way i have implemented for storing day,
in which it is comparing day with 1 to 7 and start from sunday to saturday.
and its working perfectly too..
but if i am using same code with different RAM loacation to store it as
Alarm On-Day and Alarm Off-Day then its not working..??:cry:

The problem with a number from 1 to 7 for a day of week is that you need a lot of bytes.
Let say you want alarm 1 to be active on Tuesday, Thursday and Sunday. In this case you will need three bytes to tell the µC the active days. Each byte contains the number of the active day. In case the alarm is active for all days, you need 7 bytes.
You can of course always reserve 7 bytes but that's a waste of bits since each byte will contain only 1 or 0 (1 bit).

That's why I suggested 1 byte were each bit represents one day of week.


H_D_R said:
how can i access it..?? i have only four keys.
by the way i have implemented for storing day,
2 keys are enough :)
1 key to scroll through a menu with 7 items : the days of week
1 key to toggle the alarm status.

Declare a variable: Dummy
Dummy = Actual alarm data from alarm 1 (address 10h from DS)

When going through the menu apply these actions
state : Monday (Bit 0) user turn alarm on : Dummy= Dummy + 1 : user turn alarm off : Dummy= Dummy - 1 : user didn't change anything : no actions
state : Tuesday (Bit 1) user turn alarm on : Dummy= Dummy + 2 : user turn alarm off : Dummy= Dummy - 2 : user didn't change anything : no actions
state : Wednesday (Bit 2) user turn alarm on : Dummy= Dummy + 4 : user turn alarm off : Dummy= Dummy - 4 : user didn't change anything : no actions
state : Thursday (Bit 3) user turn alarm on : Dummy= Dummy + 8 : user turn alarm off : Dummy= Dummy - 8 : user didn't change anything : no actions
state : Friday (Bit 4) user turn alarm on : Dummy= Dummy + 16 : user turn alarm off : Dummy= Dummy - 16 : user didn't change anything : no actions
state : Saterday (Bit 5) user turn alarm on : Dummy= Dummy + 32 : user turn alarm off : Dummy= Dummy - 32 : user didn't change anything : no actions
state : Sunday (Bit 6) user turn alarm on : Dummy= Dummy + 64 : user turn alarm off : Dummy= Dummy - 64 : user didn't change anything : no actions

That routine can be standard for all alarms, so after leaving it store the value of Dummy in the correct RAM location of the RTC, according to my previous post:
10h : for Alarm 1, days of week active
13h : for Alarm 2, days of week active
16h : for Alarm 3, days of week active
19h : for Alarm 4, days of week active
 

    H_D_R

    Points: 2
    Helpful Answer Positive Rating
asm program to read write ds1307

hello mcs52mc Sir,

thank you so much for taking interest in my problem and replying me with pateince.

you logic is really helpful to save the bytes.
but i have to think and try your logic.
bcoz it still seem little bit complicated..

i'll be back with my result.

thank you again..:D :D
 

ds1307 rtc c code for 89s52

HI guys, I think almost everything is discussed over here regarding I2c drivers. I also worked on exactly DS1307 with 89c52. If you need any further details, you are free to contact me

And watchdog timer just complicates your code. Actually, Why we use watchdog timer is to prevent our system to go into a blocked mode due to damage in code while fetching through the bus. I hope a simple appli like this doesnot require a watchdog timer facility.

Read the protocol carefully and go through the code of I2c, You can easily get to know about NACK.

Check out http://wizkidkrishna.googlepages.com
 

    H_D_R

    Points: 2
    Helpful Answer Positive Rating
interfacing of rtc with 89c52 microcontroller

hello MCS51MC and Venkatta,

i am able to store the
alarm_on_min,
alarm_on_hour,
alarm_off_min,
alarm_off_hour.

and its working perfectly...

but as i am trying to add alarm_on_day, alarm_off_day in set alarm loop.
it gives some irregular outputs and not even stores the hour and min time too.

can you please help me..
may i put the code here, so you can check and reply me...??
 

led interfacing with 89s52

Why do you need "alarm_off_min" & "alarm_off_hour"?
I thought the user is supposed to turn the alarm off :)

H_D_R said:
i am able to store the
alarm_on_min,
alarm_on_hour,
alarm_off_min,
alarm_off_hour.

and its working perfectly...
Nice to hear that it's working perfectly.
But what's working perfectly? Storing in the DS?
How do you know it's working perfectly? By recalling it from the DS maybe...?


H_D_R said:
but as i am trying to add alarm_on_day, alarm_off_day in set alarm loop.
it gives some irregular outputs and not even stores the hour and min time too.
Now I'm really confused :eek:
What do you mean by "add" ?
You can't store anymore? Store what, where? At the start of the post you wrote : "and its working perfectly..."
You lost me completly :) :eek:


H_D_R said:
can you please help me..
may i put the code here, so you can check and reply me...??
You can put the code here or mail it to me, your choice...
But the code is not enough.
Explain clearly what the code is supposed to do.
 

    H_D_R

    Points: 2
    Helpful Answer Positive Rating
addressing ds1307

Thank you so much for replying immediately.

mcs51mc said:
Why do you need "alarm_off_min" & "alarm_off_hour"?
I thought the user is supposed to turn the alarm off :)

i am storing the alarm on-time and alarm off-time. so based on that alarm will work automatically.

i am able to store the
alarm_on_min,
alarm_on_hour,
alarm_off_min,
alarm_off_hour.

and its working perfectly...
Nice to hear that it's working perfectly.

But what's working perfectly? Storing in the DS?
How do you know it's working perfectly? By recalling it from the DS maybe...?

thanks.
i mean to say its storing the data in RTC properly and also recalling.
i came to know because i have connected LED and it glows on and off as per time stored in RTC.

H_D_R said:
but as i am trying to add alarm_on_day, alarm_off_day in set alarm loop .
it gives some irregular outputs and not even stores the hour and min time too.
Now I'm really confused :eek:
What do you mean by "add" ?
You can't store anymore? Store what, where? At the start of the post you wrote : "and its working perfectly..."
You lost me completely :) :eek:

i mean to say sir, above all operation is done in set_on_alarm loop and set_off_alarm loop respectively.
now time comes to store alarm_on_day and alarm_off_day in RTC via that Loop.
and as i am adding these sub-loop in those sub-main-loop respectively it won’t work.
even it does not update the LCD display so how can i say it is stored or not.?? :(

hope so now you got my problem..
if not yet then please let me know..
Thank you so much again..:D
 

compiler asm for 89s52

hello all,

i have tried a lot as per my best but still not got any success in this problem.
so, i have decided to skip this day storing feature for now.

and now i want to do next step means
i want to four alarm time(ON and OFF both) in RTC.

so can anybody tell how to it is possible..??
and how can i recall them at the alarm checking and comparing time..???
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top