| Author |
Message |
garg29
Joined: 17 Nov 2004 Posts: 352 Helped: 10
|
05 Nov 2005 4:49 ds1302 8051 |
|
|
|
|
Hi friends,
I have recently designed a digital clock with calendar using RTC
DS1302, 89c51 and LCD. The ciruit and program are working fine. Till
now i haven't included the switches to set the Date and Time. Now, my
problem is, how to check whether the user is setting proper date or
not, i.e. if the user sets 31st Feb the program should display "Invalid
Date", now for this whether i need to design a function or does DS1302
has some inbuilt function to do this.
With best regards,
Garg
|
|
| Back to top |
|
 |
IanP
Joined: 05 Oct 2004 Posts: 6490 Helped: 1542 Location: West Coast
|
05 Nov 2005 5:21 ds1302 |
|
|
|
|
The DS1302 will not correct data that is written to its registers; it has certain ranges, for example for months (0-30, 0-31, 0-28 or 0-29 with leap year correction) and some bits in registers are just 0, so you can not wite a 1 to them ..
But, this will not prevent attempts of writing wrong numbers ..
This has to be done in your software ..
One option in writing DATE, for example, is to star with YEAR then MONTH and then DAY ..
As soon as you type as MONTH --> 02=FEB allow only 2 for tens of days and then 8 or 9, depending on the year.
For that you can use LeapYears_LookUpTable (00h, 04h, 08h , ....)
For other months use Months_LookUpTable (31h, 28h, 31h, 30h, ...) and verify, or not allow wrong numbers ..
Regards,
IanP
|
|
| Back to top |
|
 |
garg29
Joined: 17 Nov 2004 Posts: 352 Helped: 10
|
05 Nov 2005 5:31 date setting in ds1302 |
|
|
|
|
Thanks Ianp for replying. That was really a good help. I haven't used lookup tables till now. If you can provide me internet address where i can find a example of look table i would really be very thankful to you, even a small example will do,
Thanks once again and with best regards
Garg
|
|
| Back to top |
|
 |
VVV
Joined: 26 Nov 2004 Posts: 1584 Helped: 290
|
05 Nov 2005 6:16 ds1302 init |
|
|
|
|
A typical example involves the MOVC A, @A+PC.
Before calling the subroutine you make sure A is loaded with the correct month.
You also must make sure first that the month is correct, i.e, 1 to 12.
| Code: |
MOV A, #MONTH ;make sure A contains the month, from 1 to 12, either
;you load it here or it gets loaded somewhere else
CALL MONTH_END ;call subroutine that returns the last valid day
;for that month
; do the comparison here, if the date entered is greater, display error.
.
.
.
MONTH_END: MOVC A, @A+PC ; return in A the byte at PC+ initial A
RET ;
;the actual table with the correct dates is here
DB 31 ;for January
DB 29 ;for february
DB 31
DB 30
DB 31
|
Be careful, no other bytes should exist between RET and the first DB. If bytes exist, their number must be added to A before executing the MOVC A, @A+PC instruction. Also, in your case the first number is 1, but if it has to be zero, the first instruction of the MONTH_END subroutine must be INC A, to jump over the RET.
Of course, each month begins with day 1, so alway make sure the day entered is at least 1.
|
|
| Back to top |
|
 |
IanP
Joined: 05 Oct 2004 Posts: 6490 Helped: 1542 Location: West Coast
|
05 Nov 2005 9:36 8051 ds1302 |
|
|
|
|
Other option is to employ the DPTR ..
Perhaps it is more flexible option than using MOVC A, @A+PC ..
Have a look at this example:
MOV DPTR, #Months_LookUpTable
MOV A, Month
MOVC A, @A+DPTR
..
Months_LookUpTable: DB 00h, 31h, 28h, 31h, 30h, .......
In this case the table can be located enywhere in your program, usually in it's end (if you prefer not to mix code with tables) ..
The first byte is 00h as Months will always start from 01h, or, after loading A with Months you can insert DEC A instruction and start the table with 31h ..
Regards,
IanP
|
|
| Back to top |
|
 |
garg29
Joined: 17 Nov 2004 Posts: 352 Helped: 10
|
07 Nov 2005 20:34 ds1302 rtc software |
|
|
|
|
hi friends,
what does the lower line means,
DB CR,LF,’******* DALLAS SEMICONDUCTOR ******* ’
Regards,
Garg
|
|
| Back to top |
|
 |
Google AdSense

|
07 Nov 2005 20:34 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
IanP
Joined: 05 Oct 2004 Posts: 6490 Helped: 1542 Location: West Coast
|
08 Nov 2005 1:43 rtc ds1302 |
|
|
|
|
| Quote: |
| DB CR,LF,’******* DALLAS SEMICONDUCTOR ******* ’ |
CR = carriage return (0Dh)
LF = line feed (0Ah)
Most likely someone wants the name "***DALLAS SEMICONDUCTORS***" to be sent through a serial port and displayed from the beginning (CR) the next line (LF) on a PC screen ..
It is just declaration of a string of ASCII characters ..
Regards,
IanP
|
|
| Back to top |
|
 |
jetmira
Joined: 20 May 2009 Posts: 1
|
20 May 2009 17:49 ds1302 89s52 |
|
|
|
|
MOV A,#03H
MOVC A,@A+PC
RET
DB 10H,20H,30H,40H,50H,60H,70H,80H
the value of A,is?
|
|
| Back to top |
|
 |
sn_burki
Joined: 18 Feb 2003 Posts: 220 Helped: 4
|
25 May 2009 20:44 ds1302 clock with 8051 |
|
|
|
|
Hi all,
I have also made DS1302 RTC AT 89S52 with atmel. every thing is working fine but the timing in DS1302 RTC is very fast. I have checked the crystal 32k but could not understand why this problem occures? if any one could help plz.
regards
|
|
| Back to top |
|
 |
kulkarni_sayo
Joined: 30 Sep 2009 Posts: 1
|
30 Sep 2009 12:04 DS1302 & 8051 |
|
|
|
|
| can you please mail me the code for 1302 and 89C51 interfacing along with a circuit diagram?
|
|
| Back to top |
|
 |