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
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
thats it...-> 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
;---------------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
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???
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
H_D_R said:segmex said:can we set DS1307 to count down ??
can you please describe your question in detail please..??
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
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
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?