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.

How to set the real time in RTC with Assembly code (ds1307)

Status
Not open for further replies.

jandreas

Member level 3
Joined
Nov 30, 2007
Messages
60
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,774
well, i'm a little confuse about how to set the real time in rtc by assembly code that i want.... 'coz from i read , we have to set the time before we use ds1307... If someone has the code, could you show it in this topic?? it will great if commented...thank you

RGDS jandreas
 

Re: RTC ds1307

jandreas said:
well, i'm a little confuse about how to set the real time in rtc by assembly code that i want.... 'coz from i read , we have to set the time before we use ds1307... If someone has the code, could you show it in this topic?? it will great if commented...thank you

RGDS jandreas

please read datasheet carefully..
every thing is given there..

please post your work...

so people can understand where exactly confused and you will get help..
 

RTC ds1307

If I give you the code I wrote, I will still have to explain how to splice it to your application. You will take just as long to write your own.

As for the RTC, it is inert until activated. There is a bit in one of the registers that controls whether the clock is running or not. Once that is done, you also need to write the current time to it elsewise it will continue from whatever value was there at power-up.

Sorry, I don't mean to rain on your parade.
 

Re: RTC ds1307

okay, i have read the sheet, i just want to ask , are all of the I2c bus sytem have same code each other like start, write,read, stop,ack??? i mean how we write and read is the code same each other... i'm sorry if my english is bad, i/m from indonesia

rgds jandreas
 

Re: RTC ds1307

jandreas said:
okay, i have read the sheet, i just want to ask , are all of the I2c bus sytem have same code each other like start, write,read, stop,ack??? i mean how we write and read is the code same each other... i'm sorry if my english is bad, i/m from indonesia

rgds jandreas

good..
those are main fnction for I2C communication.

now for comuincation,

-> set the start condition

-> first you have to send the address and select device (if your are using multiple devices) then the device will send the reply of ACK in reply of it.

-> then you have to send memory address where you want to store data.

-> then send the data for writing in that location.
if you are reading data then you have to read data from here and save it in MCU's RAM location.(mostly ACC.)

-> set the stop condition
thats it...

for start and stop condition you have to follow the timing diagram and make code as per shown in datasheet.

that's why i was saying please read datasheet carefully. if not yet then please read it again. because you will not be able to undersatnd communication from readymade code untill you know the basics of I2C.
 

Re: RTC ds1307

Thank you H_D_R, i have read the sheet, and i understand about it a little... and i tried to make some code related to the sheet. The code is about how to set the time in RTC... nah, can you check it, whether it is right or not???? here is the code:

;---------------STORE THE TIME-----------------;


EE_WRITE:
LCALL EE_START ; SEND A START FLAG TO THE RTC ..
MOV A,#0D0H ; SPECIFY A WRITE RTC
LCALL SH_OUT ; SHIFT OUT THE DEVICE ADDRESS ..
JC WR_ABORT ; ABORT IF NO ACK FROM RTC ..
MOV A,00H ; GET RTC MEMORY ADDRESS ..
LCALL SH_OUT ; SHIFT OUT THE MEMORY ADDRESS ..
JC WR_ABORT ; ABORT IF NO ACK FROM RTC ..
MOV A,SECS ; WRITE THE SECONDS DATA ..
LCALL SH_OUT ; SHIFT OUT THE DATA ..
JC WR_ABORT
MOV A,MINS ; WRITE THE MINUTES DATA..
LCALL SH_OUT ; SHIFT OUT THE MEMORY ADDRESS ..
JC WR_ABORT ; ABORT IF NO ACK FROM RTC ..
MOV A,HOURS ; WRITE THE HOURS DATA ..
LCALL SH_OUT ; SHIFT OUT THE DATA ..
JC WR_ABORT
MOV A,DAY ; WRITE THE DAY DATA ..
LCALL SH_OUT ; SHIFT OUT THE MEMORY ADDRESS ..
JC WR_ABORT ; ABORT IF NO ACK FROM RTC ..
MOV A, DATE ; WRITE THE DATE DATA ..
LCALL SH_OUT ; SHIFT OUT THE DATA ..
JC WR_ABORT
MOV A,MONTH ; WRITE THE MONTH DATA ..
LCALL SH_OUT ; SHIFT OUT THE MEMORY ADDRESS ..
JC WR_ABORT ; ABORT IF NO ACK FROM RTC ..
MOV A, YEAR ; WRITE THE YEAR DATA ..
LCALL SH_OUT ; SHIFT OUT THE DATA ..
JC WR_ABORT
CLR C
WR_ABORT:
LCALL EE_STOP ; SEND STOP CONDITION TO RTC ..

RET ; GO BACK TO MAIN PROGRAM ..


;--------------- EE_START BIT-BANGS A START SEQUENCE TO RTC (HI-TO-LOW SDA TRANSITION WITH SCL HIGH) ..
EE_START:
SETB SDAPin
SETB SCLPin ; SET BOTH BITS ..
NOP ; DELAY ..
CLR SDAPin ; START CONDITION - SDA HI TO LOW TRANSITION ..
NOP
NOP ; RTC ACCESS TIME DELAY ..
CLR SCLPin
CLR C ; CLEAR ERROR FLAG ..
RET ; ALL DONE ..
;--------------- EE_STOP SENDS A STOP SEQUENCE TO THE RTC (LOW-TO-HIGH SDA TRANSITION WITH SCL HIGH) ..
EE_STOP:
CLR SDAPin
NOP
NOP
SETB SCLPin
NOP
NOP ; SETUP TIME DELAY ..
SETB SDAPin ; SEND A STOP CONDITION ..
RET

;--------------- SH_OUT SHIFTS DATA OUT TO THE RTC---------------------
SH_OUT:
PUSH B
MOV B,#8 ; SAVE B AND LOAD BIT COUNT ..
EE_OUT:
RLC A ; SHIFT BIT LEFT (RLC=ROTATE LEFT THROUGH CARRY) ..
MOV SDAPin, C ; GET DATA BIT FROM CARRY ..
NOP
SETB SCLPin ; CLOCK IN 1-BIT ..
NOP ; CLOCK HIGH TIME ..
CLR SCLPIN ; CLOCK IS NOW LOW ..
DJNZ B, EE_OUT ; DO IT 8 TIMES ..
SETB SDAPin ; RELEASE SDA FOR ACK ..
NOP
NOP
SETB SCLPin ; ACK CLOCK ..
NOP
MOV C, SDAPin ; GET THE ACK ..
CLR SCLPin ; CLEAR THE CLOCK BIT ..
POP B ; RESTORE WHATEVER B WAS ..
RET


;--------------- ACK SENDS AN EEPROM ACKNOWLDEGE----------------------
ACK:
CLR SDAPin
NOP
NOP
SETB SCLPin ; CLOCK THE ACK ..
NOP
CLR SCLPin ; BRING CLOCK LOW ..
RET

;--------------- NAK SENDS A NO ACKNOWLEDGE----------------------------
NAK:
SETB SDAPin
NOP
NOP
SETB SCLPin ; CLOCK THE NAK ..
NOP
CLR SCLPin ; BRING CLOCK LOW ..
RET

that is the code.. hope you guys check it, and tell me if there is something wrong in it..... Thank you


RGDS jandreas:D
 

Re: RTC ds1307

Good Efforts my friend,..

i have checked your code but i need to do lots of changes there.

-> like no need to get ACK after each instruction.
-> we can use directly the RTC etc etc.

so, better way, i am attaching the code used in my project.
its easy to understand also.
please read it and see how the things are done.

if you have any doubts then you can ask any time..
all the best..!!!:D
 

Re: RTC ds1307

thank you very much HDR... i have read yours... but in your code, it doesn't has how to read the rtc.. do you have one how to read the rtc???


previously you said that rtc doesn't need ack... but in the datasheet i read when micro get the data, rtc should give ack.. how you explain that???


thank you..
RGDS jandreas
 

Re: RTC ds1307

jandreas said:
thank you very much HDR... i have read yours... but in your code, it doesn't has how to read the rtc.. do you have one how to read the rtc???

i have sent you just functions.
you can use them.
but the programming that you only have to do.

have you seen that RTC registers, how it stores the calender and clock data.??


previously you said that rtc doesn't need ack... but in the datasheet i read when micro get the data, rtc should give ack.. how you explain that???


thank you..
RGDS jandreas

hello,

please Read that post properly..

I have not said that RTC doesnt need ACK. but I said it’s not necessary to receive ack after each instruction as you have written in your code...
Once you have set the communication then you can send a stream (Address, Data etc.) directly.
remember again, at the end of device address it will give you ack for device detection.
similarly at the end of data string it will gives ACK to indicate that string received.

When you will receive the ack from RTC for that please check the data transfer timing diagram.
and following timing diagram also..
 

RTC ds1307

can we set DS1307 to count down ??
 

Re: RTC ds1307

segmex said:
can we set DS1307 to count down ??

can you please describe your question in detail please..??
 

Re: RTC ds1307

H_D_R said:
segmex said:
can we set DS1307 to count down ??

can you please describe your question in detail please..??

sure i do


i need to design a timer to show the time but it must be count down NOT up
for instance if the time is 11:52:20 the next must be 11:52:19 and so on .
can i use ds1307 for this design !i!i!i
 

Re: RTC ds1307

segmex said:
sure i do

i need to design a timer to show the time but it must be count down NOT up
for instance if the time is 11:52:20 the next must be 11:52:19 and so on .
can i use ds1307 for this design !i!i!i

sorry, i dont have idea about that.....

but tell me one thing, you can do it by using MCU's internal counter then why you are looking in RTC.??
 

Re: RTC ds1307

umm sorry.. i have some trouble now.... the RTc give output in BCD format, and i want to display it in LCD... so is there any code that can change BCD to ASCII format???another problem is i use at24c64, is there any code that you guys have to access it??? the last but not least, someone said to me that i cannot share both rtc and at24c54 in same bus??? is it correct???

Thank you for your attention..

RGDS jandreas
 

Re: RTC ds1307

jandreas said:
umm sorry.. i have some trouble now.... the RTc give output in BCD format, and i want to display it in LCD... so is there any code that can change BCD to ASCII format???another problem is i use at24c64, is there any code that you guys have to access it??? the last but not least, someone said to me that i cannot share both rtc and at24c54 in same bus??? is it correct???

Thank you for your attention..

RGDS jandreas

i am not sure about that..
but accodring to me unless and untill you have no any other option you should connect it on different pins of MCU..
 

Re: RTC ds1307

Hi,
1. To get Ascii from BCD just add 30h to each BCD. Each digit will then be an ASCII byte.
2. In order to connect RTC and 24Cxx on same bus, choose a different device address by external jumpers for 24Cxx.

Regards,
Laktronics
 

Re: RTC ds1307

thank you lacktronics, i understand now to get the ASCII, but for the AT and RTC, did you mean that i need to set one of the pin A0,A1,A2 in AT24cxx to VCC???

i'm sorry if i'm not wrong, both RTC and AT doesn't have same initial address right???
i mean for AT it's a0h and for rtc it's D0h
so is it still need for me to set the external jumper of AT????

thank you
 

Re: RTC ds1307

Hi,
In any case you have to set the external address of 24xx to match with the LS three bits of the address byte. I could not find from the data sheet if the five bit control code will change under some conditions, so I suggested you to select an address different from RTC's address, using the external address. So long as the device addresses are different (lile A0 and D0) , they can work from the same bus. Since I still do not know what are the possible variations of the control code, I would advise you to provide a jumper on A0 of the address and ground A1 and A2 of the 24XX so that if need arises, you can always select a high level for A0 ( address A1h ) for 24xx device.

Regards,
Laktronics
 

Re: RTC ds1307

:cry::cry::cry:

i tried to access the at24c64, firstly i wrote some bytes into it, and then i tried to read it.. but there is nothing.... what is the problem??? in simulator it works fine, but when i tried by hardware... it is nothing... can somebody help me????

i read some article, it said that we have to write all the address in at24cxx with same byte before we use it... is it correct??? and is it okay if i don't use the ack signal?? because i'm affraid that the eeprom never give the ack when the data sent, because of that the result is nothing.....

please help me... thank you

RGDS jandreas
 

Re: RTC ds1307

Hi,
You must allow for the write delay. You must also get the ACK from chip. Read the data sheet carefully, you should get it OK.
Regards,
Laktronics
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top