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 check whether the user is setting proper date in a digital clock?

Status
Not open for further replies.

garg29

Advanced Member level 1
Advanced Member level 1
Joined
Nov 17, 2004
Messages
443
Helped
25
Reputation
50
Reaction score
10
Trophy points
1,298
Activity points
3,593
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
 

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
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
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
 

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.
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
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
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
ds1302 rtc software

hi friends,
what does the lower line means,

DB CR,LF,’******* DALLAS SEMICONDUCTOR ******* ’

Regards,
Garg
 

rtc ds1302

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
 

ds1302 89s52

MOV A,#03H
MOVC A,@A+PC
RET
DB 10H,20H,30H,40H,50H,60H,70H,80H

the value of A,is?
 

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
 

DS1302 & 8051

can you please mail me the code for 1302 and 89C51 interfacing along with a circuit diagram?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top