Rules | Recent posts | topic RSS | Search | Register  | Log in

RTC DS1307 Interfacing with MCU 89S52
Goto page Previous  1, 2
 
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers
Author Message
H_D_R



Joined: 31 Jan 2008
Posts: 361
Helped: 17
Location: India


Post18 Feb 2008 13:52   Re: RTC DS1307 Interfacing with MCU 89S52

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

Quote:
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.

Quote:
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.

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


i have battery backup already.

Quote:
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.
Back to top
mcs51mc



Joined: 19 Jul 2007
Posts: 73
Helped: 16
Location: Belgium


Post18 Feb 2008 20:00   Re: RTC DS1307 Interfacing with MCU 89S52

I'm sorry but I have no link to my brain SmileSmileSad

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 Sad
So please forget about it.
Back to top
H_D_R



Joined: 31 Jan 2008
Posts: 361
Helped: 17
Location: India


Post19 Feb 2008 5:24   Re: RTC DS1307 Interfacing with MCU 89S52

Quote:
I'm sorry but I have no link to my brain SmileSmileSad


great...!!! Surprised


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

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


i think something wrong is here..??Question

Quote:

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..??Crying or Very sad

Quote:
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..

Quote:
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.


Quote:
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..

Quote:
Hope this new configuration is clear to you.

thanks for replying..

Quote:
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 Sad
So please forget about it.

i have implemented and its working perfectly..
Back to top
mcs51mc



Joined: 19 Jul 2007
Posts: 73
Helped: 16
Location: Belgium


Post19 Feb 2008 8:33   Re: RTC DS1307 Interfacing with MCU 89S52

H_D_R wrote:
Quote:
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..??Crying or Very sad


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 wrote:
how can i access it..?? i have only four keys.
by the way i have implemented for storing day,

2 keys are enough Smile
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


Last edited by mcs51mc on 19 Feb 2008 17:53; edited 1 time in total
Back to top
H_D_R



Joined: 31 Jan 2008
Posts: 361
Helped: 17
Location: India


Post19 Feb 2008 8:54   Re: RTC DS1307 Interfacing with MCU 89S52

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..Very Happy Very Happy
Back to top
Venkata Krishna



Joined: 31 Oct 2005
Posts: 33
Helped: 1
Location: NOIDA


Post19 Feb 2008 13:50   Re: RTC DS1307 Interfacing with MCU 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
Back to top
H_D_R



Joined: 31 Jan 2008
Posts: 361
Helped: 17
Location: India


Post21 Feb 2008 7:36   Re: RTC DS1307 Interfacing with MCU 89S52

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...??
Back to top
mcs51mc



Joined: 19 Jul 2007
Posts: 73
Helped: 16
Location: Belgium


Post21 Feb 2008 8:30   Re: RTC DS1307 Interfacing with MCU 89S52

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

H_D_R wrote:
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 wrote:
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 Surprised
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 Smile Surprised


H_D_R wrote:
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.
Back to top
H_D_R



Joined: 31 Jan 2008
Posts: 361
Helped: 17
Location: India


Post21 Feb 2008 8:57   Re: RTC DS1307 Interfacing with MCU 89S52

Thank you so much for replying immediately.

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


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

Quote:
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.

Quote:
H_D_R wrote:

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 Surprised
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 Smile Surprised


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.?? Sad

hope so now you got my problem..
if not yet then please let me know..
Thank you so much again..Very Happy
Back to top
H_D_R



Joined: 31 Jan 2008
Posts: 361
Helped: 17
Location: India


Post26 Feb 2008 13:10   Re: RTC DS1307 Interfacing with MCU 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..???
Back to top
ckshivaram



Joined: 21 Apr 2008
Posts: 316
Helped: 22
Location: korea


Post30 Apr 2008 8:36   RTC DS1307 Interfacing with MCU 89S52

Interfacing DS1307 is very easy with 89c52 or 89S52. Many of the answers are seeming to complicate the topic u have raised instead of giving u answer or simplifying your querry.
After so many answers please let me know where are you now in the project. So that i can help you further
Back to top
ckshivaram



Joined: 21 Apr 2008
Posts: 316
Helped: 22
Location: korea


Post30 Apr 2008 8:36   RTC DS1307 Interfacing with MCU 89S52

Interfacing DS1307 is very easy with 89c52 or 89S52. Many of the answers are seeming to complicate the topic u have raised instead of giving u answer or simplifying your querry.
After so many answers please let me know where are you now in the project. So that i can help you further
Back to top
king_cobraz_77



Joined: 06 Mar 2006
Posts: 18
Helped: 1


Post30 Apr 2008 19:03   Re: RTC DS1307 Interfacing with MCU 89S52

can't understand
Please first show your design
Back to top
H_D_R



Joined: 31 Jan 2008
Posts: 361
Helped: 17
Location: India


Post01 May 2008 4:48   Re: RTC DS1307 Interfacing with MCU 89S52

ckshivaram wrote:
Interfacing DS1307 is very easy with 89c52 or 89S52. Many of the answers are seeming to complicate the topic u have raised instead of giving u answer or simplifying your querry.
After so many answers please let me know where are you now in the project. So that i can help you further


Thanks for replying..

BTW, i have finished the project upto given task.
if further implemenation will be there and if i'll face any problem then i'll post again.

Thank you to you all...Very Happy Very Happy Very Happy
Back to top
NIDHI PATEL



Joined: 27 Feb 2008
Posts: 17


Post01 May 2008 7:21   Re: RTC DS1307 Interfacing with MCU 89S52

H_D_R wrote:
vietdung79 wrote:
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...???



i am having rtc assembly language code i am sending u try , may be it will help u, though i am not clearly getting which type of help u need.

Digital Clock with alarm using DS1307
;
; For Keil/ A51 Macro Assembler




hold macro ;delay macro for I2C
nop
nop
nop
endm

disp_str macro string ;Macro for sending string to LCD
irpc char, <string>
if nul 'char'
exitm
endif
mov a,#'char'
lcall data_in
endm
endm

build_char macro P1,P2,P3,P4,P5,P6,P7,P8 ;Macro for building a custom character
irp arg, <P1,P2,P3,P4,P5,P6,P7,P8>
mov a,#arg
acall data_in
endm
endm

sec equ 30h ;second register
min equ 31h ;minutes register
hour equ 32h ;hour register
days equ 33h ;days register
date equ 34h ;date register
month equ 35h ;month register
year equ 36h ;year register
alarm equ 37h ;alarm register
sig equ 38h ;signature for data checking in RTC RAM
ahour equ 39h ;alarm hour register
amin equ 3Ah ;alarm minute register
sda equ P1.1 ;Serial data pin
scl equ P1.0 ;Serial clock pin
rw equ p3.6 ;read write pin of LCD
en equ p3.5 ;enable pin of LCD
rs equ p3.7 ;register select pin of LCD
alarm_key equ p3.3 ;Alarm set key
time_key equ p3.2 ;Time ser key
increment equ p1.3 ;Increment value
decrement equ p1.2 ;Decrement Value
alarm_port equ p1.4 ;Alarm Buzzer port
alarm_flag equ 20h ;flag for alarm
time_flag equ 21h ;flag for time
ampm_flag equ 22h ;am/pm flag
alarm_on equ 23h ;Alarm on flag
alarm_off equ 24h ;alarm off flag
alarm_ring equ 25h ;alarm ring flag
alarm_hrs equ 58h ;Alarm hour register
alarm_min equ 59h ;Alarm Minutes register
alarm_chk_hour equ 5Ah ;Alarm hour check register
alarm_chk_min equ 5Bh ;Alarm min check register
ampm equ 61h ;AM/PM register
BELL equ 0h ;Bell icon
SPEAKER_OFF equ 1h ;speaker off icon
SPEAKER_ON equ 2h ;speaker on icon
CLOCK equ 3h ;clock icon
OK equ 4h ;ok icon
HEART equ 5h ;heart icon
MUSIC equ 6h ;music icon

org 0000h ;Starting of main program
ljmp start

org 03h ;interrupt for set time
setb time_flag
reti

org 13h ;Interrupt for set alarm
setb alarm_flag ;and switch off the alarm if on
jnb alarm_off,hmmm
setb alarm_port
mov a,#1h
lcall command
mov a,#81h
lcall command
mov a,#OK
acall data_in
mov r7,#35
disp_str < Alarm Off!>
setb tr0
loooop: jnb tf0,$
clr tf0
djnz r7,loooop
clr tr0
mov a,#1h
acall command
acall disp_const
setb alarm_off
setb alarm_on
clr alarm_flag
clr alarm_flag
clr alarm_on
setb alarm_port
clr alarm_off
clr alarm_flag
clr alarm_ring
hmmm: reti

start: mov tmod,#1h ;start routine
mov sp,#10h
acall initial
acall build
mov a,#80h
acall command
mov a,#CLOCK
acall data_in
disp_str < Digital Clock > ;Name display
mov r7,#70
setb tr0
wloop: jnb tf0,$
clr tf0
djnz r7,wloop
clr time_flag
clr alarm_flag
clr alarm_on
clr ampm_flag
setb alarm_port
mov ie,#85h
acall startc ;Reading signature byte if same then no need
mov a,#0d0h ;of initialization else initialize the RTC
acall send
mov a,#08h
acall send
acall startc
mov a,#0d1h
acall send
acall recv
acall stop
cjne a,#'~',done
sjmp run
done: acall initial
acall disp_const
mov sec,#00h ;For more information about the RTC DS1307
mov min,#0h ;Please refer to the datasheet
mov hour,#52h ;21h for 24 hour format
mov days,#01h
mov date,#1h
mov month,#1h
mov year,#05h
mov alarm,#0
mov sig,#'~'
mov ahour,#0
mov amin,#0
mov r6,#0bh
mov r0,#30h
mov r1,#00h
acall rtc_ini ;initializing RTC if required
run: acall initial
acall disp_const
run1: acall startc ;Actual Starting
mov a,#0d0h
acall send
mov a,#00h
acall send
mov r6,#3fh
acall startc ;Reading the RCT content
mov a,#0d1h
acall send
mov r0,#40h
here: acall recv
djnz r6,here
acall stop
acall display ;Display RTC
jnb time_flag,noset ;check for time flag if set the set the clock
clr time_flag
clr ea
acall time_set
clr time_flag
mov r6,#09h
mov r0,#30h
mov r1,#00h
acall rtc_ini
clr time_flag
mov a,#1h
acall command
mov a,#81h
acall command
mov a,#OK
acall data_in
disp_str < Time Set!>
mov r7,#35
setb tr0
looooop:jnb tf0,$
clr tf0
djnz r7,looooop
clr tr0
mov a,#1h
acall command
acall disp_const
setb ea
noset:
jnb alarm_flag,noset1 ;check for alarm flag if set then set alarm
clr alarm_flag
clr ea
lcall alarm_set
setb ea
setb alarm_on
clr alarm_flag
setb alarm_on
noset1:
jnb alarm_ring,noset2 ;check if alarm ring flag is set
lcall alarm_alarm ;if set then ring the alarm
noset2: ljmp run1 ;Do everything again

startc: ;I2C atart condition subroutine
clr scl
setb sda
hold
setb scl
clr sda
hold
ret
send: ;Sending data to I2C bus
mov r7,#08
back:
clr scl
hold
rlc a
mov sda,c
setb scl
hold
clr scl
hold
djnz r7,back
setb sda
setb scl
hold
clr scl
hold
ret

stop: hold ;I2C stop Condition
clr sda
setb scl
nop
setb sda
hold
clr scl
ret

recv: ;Recieving data from I2C bus
mov r7,#08
back2:
setb sda
setb scl
hold
mov c,sda
rlc a
clr scl
hold
djnz r7,back2
setb sda
clr scl
hold
clr sda
setb scl
hold
clr scl
hold
mov @r0,a
inc r0
ret

rtc_ini:acall startc ;RTC initialization subroutine
mov a,#0d0h
acall send
mov a,r1
acall send
mov a,@r0
acall send
inc r0
inc r1
acall stop
djnz r6,rtc_ini
acall stop
ret

initial:mov a,#38h ;LCD initialization subroutine
acall command
mov a,#0ch
acall command
mov a,#01h
acall command
mov a,#06h
acall command
ret

build: mov a,#40h ;Building custom character routine
acall command
build_char 4h,0eh,0eh,0eh,1fh,0h,4h,0h ;BELL
build_char 1h,3h,0fh,0fh,0fh,3h,1h,0h ;SPEAKER OFF
build_char 8h,10h,0h,18h,0h,10h,8h,0h ;SPEAKER ON
build_char 0h,0eh,15h,17h,11h,0eh,0h,0h ;CLOCK
build_char 0h,1h,3h,16h,1ch,8h,0h,0h ;OK
build_char 0ah,1fh,1fh,1fh,0eh,4h,0h,0h ;HEART
build_char 2h,3h,2h,0eh,1eh,0ch,0h,0h ;MUSIC
ret

display:mov r1,#40h ;Displaying RTC content
mov a,#0Cah
acall command
mov a,@r1
mov 50h,@r1
acall disp_val
PASS: inc r1
mov a,#0C7h
acall command
mov a,@r1
mov 51h,@r1
mov alarm_chk_min,@r1
acall disp_val
PASS1: inc r1
mov a,#0c4h
acall command
mov a,@r1
mov 52h,@r1
mov alarm_chk_hour,@r1
mov r4,a
anl a,#1fh
acall disp_val
mov a,r4
anl a,#20h
cjne a,#00h,pm
mov a,#0cdh
acall command
disp_str <am>
sjmp pass2
pm: mov a,#0cdh
acall command
disp_str <pm>
PASS2: inc r1
mov a,#80h
acall command
mov a,@r1
mov 53h,@r1
acall day
PASS3: inc r1
mov a,#88h
acall command
mov a,@r1
mov 54h,@r1
acall disp_val
PASS4: inc r1
mov a,#8bh
acall command
mov a,@r1
mov 55h,@r1
acall disp_val
PASS5: inc r1
mov a,#8eh
acall command
mov a,@r1
mov 56h,@r1
acall disp_val
jnb alarm_on,PASS6
inc r1
inc r1
inc r1
mov a,@r1
cjne a,52h,PASS6
inc r1
mov a,@r1
cjne a,51h,PASS6
setb alarm_ring
setb alarm_ring
PASS6: ret

disp_val: ;Display 8-bit Decimal Value
push acc
mov r5,a
anl a,#0f0h
swap a
mov dptr,#ascii
movc a,@a+dptr
acall data_in
mov a,r5
anl a,#0fh
movc a,@a+dptr
acall data_in
pop acc
ret

disp_const: ;Display constant characters
mov a,#8ah
acall command
mov a,#'/'
acall data_in
mov a,#8dh
acall command
mov a,#'/'
acall data_in
mov a,#0c6h
acall command
mov a,#':'
acall data_in
mov a,#0c9h
acall command
mov a,#':'
acall data_in
mov a,#0c0h
acall command
mov a,#BELL
acall data_in
mov a,#SPEAKER_OFF
acall data_in
ret

command:acall busy ;Sending command to LCD
MOV P2,A
CLR rs
CLR rw
SETB en
CLR en
RET

data_in:acall busy ;Sending data to LCD
SETB rs
MOV P2,A
CLR rw
SETB en
CLR en
RET

busy: SETB P2.7 ;Checking Busy flag
CLR rs
SETB rw
wait: CLR en
SETB en
JB P2.7,wait
RET

day: push acc ;Displaying day subroutine for RTC
cjne a,#01,skip
disp_str < *Sun*>
ljmp exit
skip: cjne a,#02,skip2
disp_str < *Mon*>
ljmp exit
skip2: cjne a,#03,skip3
disp_str < *Tue*>
ljmp exit
skip3: cjne a,#04,skip4
disp_str < *Wed*>
sjmp exit
skip4: cjne a,#05,skip5
disp_str< *Thu*>
sjmp exit
skip5: cjne a,#06,skip6
disp_str < *Fri*>
sjmp exit
skip6: disp_str < *Sat*>
exit: pop acc
ret

time_set: ;Setting time subroutine
jnb time_key,$
mov a,#1
acall command
mov a,#80h
acall command
mov a,#CLOCK
acall data_in
disp_str < set minutes:>
mov a,#0c5h
acall command
mov a,51h
acall disp_val
lcall hexdec
key: push acc
mov a,#0c5h
acall command
pop acc
jb increment,chk1
inc a
cjne a,#60,ok1
mov a,#0
ok1: jnb increment,$
lcall dechex
acall disp_val
lcall hexdec
sjmp key
chk1: jb decrement,chk2
dec a
cjne a,#0ffh,ok2
mov a,#59
ok2: jnb decrement,$
lcall dechex
acall disp_val
lcall hexdec
sjmp key
chk2: jb time_key,key

lcall dechex
mov min,a
jnb time_key,$

mov a,#1
acall command
mov a,#80h
acall command
mov a,#CLOCK
acall data_in
disp_str < set hours:>
mov a,#0c5h
acall command
mov a,52h
anl a,#1fh
acall disp_val
lcall hexdec
key1: push acc
mov a,#0c5h
acall command
pop acc
jb increment,chk3
inc a
cjne a,#13,ok3
mov a,#1
ok3: jnb increment,$
lcall dechex
acall disp_val
lcall hexdec
sjmp key1
chk3: jb decrement,chk4
dec a
cjne a,#0,ok4
mov a,#12
ok4: jnb decrement,$
lcall dechex
acall disp_val
lcall hexdec
sjmp key1
chk4: jb time_key,key1

lcall dechex
mov hour,a
jnb time_key,$

mov a,#1
acall command
mov a,#80h
acall command
mov a,#CLOCK
acall data_in
disp_str < set am/pm:>
mov a,52h
anl a,#20h
cjne a,#00h,pm1
mov a,#0c5h
acall command
disp_str <am>
setb ampm_flag
sjmp key2
pm1: mov a,#0c5h
acall command
disp_str <pm>
clr ampm_flag

key2: mov a,#0c5h
acall command
jb increment,chk5
jb ampm_flag,ok5
setb ampm_flag
disp_str <am>
hold
jnb increment,$
sjmp key2
ok5: clr ampm_flag
disp_str <pm>
hold
jnb increment,$
sjmp key2
chk5: jb decrement,chk6
jb ampm_flag,ok6
setb ampm_flag
disp_str <am>
hold
jnb decrement,$
sjmp key2
ok6: clr ampm_flag
disp_str <pm>
hold
jnb decrement,$
sjmp key2
chk6: jb time_key,key2

jnb ampm_flag,noam
mov a,hour
add a,#40h
sjmp nopm
noam: mov a,hour
add a,#60h
nopm: mov hour,a
jnb time_key,$

mov a,#1
acall command
mov a,#80h
acall command
mov a,#CLOCK
acall data_in
disp_str < set days:>
mov a,#0c5h
lcall command
mov a,53h
push acc
lcall day
pop acc
key3: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,chk7
inc a
cjne a,#8,ok7
mov a,#1
ok7: jnb increment,$
push acc
lcall day
pop acc
sjmp key3
chk7: jb decrement,chk8
dec a
cjne a,#0,ok8
mov a,#7
ok8: jnb decrement,$
push acc
lcall day
pop acc
sjmp key3
chk8: jb time_key,key3

mov days,a
jnb time_key,$

mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#CLOCK
lcall data_in
disp_str < set date:>
mov a,#0c5h
lcall command
mov a,54h
lcall disp_val
lcall hexdec
key4: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,chk9
inc a
cjne a,#32,ok9
mov a,#1
ok9: jnb increment,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key4
chk9: jb decrement,chk10
dec a
cjne a,#0,ok10
mov a,#31
ok10: jnb decrement,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key4
chk10: jb time_key,key4

lcall dechex
mov date,a
jnb time_key,$

mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#CLOCK
lcall data_in
disp_str < set month:>
mov a,#0c5h
lcall command
mov a,55h
lcall disp_val
lcall hexdec
key5: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,chk11
inc a
cjne a,#13,ok11
mov a,#1
ok11: jnb increment,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key5
chk11: jb decrement,chk12
dec a
cjne a,#0,ok12
mov a,#12
ok12: jnb decrement,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key5
chk12: jb time_key,key5

lcall dechex
mov month,a
jnb time_key,$

mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#CLOCK
lcall data_in
disp_str < set year:>
mov a,#0c5h
lcall command
mov a,56h
lcall disp_val
lcall hexdec
key6: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,chk13
inc a
cjne a,#100,ok13
mov a,#0
ok13: jnb increment,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key6
chk13: jb decrement,chk14
dec a
cjne a,#0ffh,ok14
mov a,#99
ok14: jnb decrement,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key6
chk14: jb time_key,key6

jnb time_key,$
lcall dechex
mov year,a
mov alarm,#00
mov sig,#'~'
clr time_flag
clr time_flag
ret

alarm_set: ;Setting Alarm Subroutine
jnb alarm_key,$
mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#BELL
lcall data_in
disp_str < set minutes:>
mov a,#0c5h
lcall command
mov a,#30h
lcall disp_val
lcall hexdec
akey: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,achk1
inc a
cjne a,#60,aok1
mov a,#0
aok1: jnb increment,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp akey
achk1: jb decrement,achk2
dec a
cjne a,#0ffh,aok2
mov a,#59
aok2: jnb decrement,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp akey
achk2: jb alarm_key,akey

lcall dechex
mov alarm_min,a
jnb alarm_key,$

mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#BELL
lcall data_in
disp_str < set hours:>
mov a,#0c5h
lcall command
mov a,#44h
anl a,#1fh
lcall disp_val
lcall hexdec
akey1: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,achk3
inc a
cjne a,#13,aok3
mov a,#1
aok3: jnb increment,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp akey1
achk3: jb decrement,achk4
dec a
cjne a,#0,aok4
mov a,#12
aok4: jnb decrement,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp akey1
achk4: jb alarm_key,akey1

lcall dechex
mov alarm_hrs,a
jnb alarm_key,$

mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#BELL
lcall data_in
disp_str < set am/pm:>
mov a,#0c5h
lcall command
mov a,alarm_hrs
anl a,#20h
cjne a,#20h,its_pm
disp_str <am>
setb ampm_flag
sjmp akey2
its_pm: disp_str <pm>
clr ampm_flag
akey2: mov a,#0c5h
lcall command
jb increment,achk5
jb ampm_flag,aok5
setb ampm_flag
disp_str <am>
hold
jnb increment,$
sjmp akey2
aok5: clr ampm_flag
disp_str <pm>
hold
jnb increment,$
sjmp akey2
achk5: jb decrement,achk6
jb ampm_flag,aok6
setb ampm_flag
disp_str <am>
hold
jnb decrement,$
sjmp akey2
aok6: clr ampm_flag
disp_str <pm>
hold
jnb decrement,$
sjmp akey2
achk6: jb alarm_key,akey2
jnb alarm_key,$
mov a,alarm_hrs
jb ampm_flag,anoam
add a,#60h
sjmp anopm
anoam: mov a,alarm_hrs
add a,#40h
anopm: mov alarm_hrs,a
mov ahour,alarm_hrs
mov amin,alarm_min
mov r6,#02h
mov r0,#39h
mov r1,#09h
lcall rtc_ini
mov a,#1h
lcall command
mov a,#81h
lcall command
mov a,#OK
lcall data_in
disp_str < Alarm On!>
mov a,#0c4h
lcall command
mov a,alarm_hrs
anl a,#1fh
lcall disp_val
mov a,#':'
lcall data_in
mov a,alarm_min
lcall disp_val
mov a,alarm_hrs
anl a,#20h
cjne a,#00h,ppm
disp_str < am>
sjmp ppass2
ppm: disp_str < pm>
ppass2: mov r7,#35
setb tr0
looop: jnb tf0,$
clr tf0
djnz r7,looop
clr tr0
mov a,#1h
lcall command
lcall disp_const
mov a,#SPEAKER_ON
lcall data_in
setb alarm_off
setb alarm_on
clr alarm_flag
clr alarm_flag
ret

alarm_alarm: ;Alarm Ring subroutine
clr alarm_port
mov r3,#0ffh
a_loop: mov r4,#0ffh
djnz r4,$
djnz r3,a_loop
setb alarm_port
mov r3,#0ffh
a_loop1:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop1
clr alarm_port
mov r3,#0ffh
a_loop2:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop2
setb alarm_port
mov r3,#0ffh
a_loop3:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop3
clr alarm_port
mov r3,#0ffh
a_loop4:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop4
setb alarm_port
mov r3,#0ffh
a_loop5:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop5
clr alarm_port
mov r3,#0ffh
a_loop6:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop6
setb alarm_port
ret

dechex: mov b,#0ah ;Decimal to Hexadecimal conversion
div ab
mov 60h,b
mov b,#10h
mul ab
add a,60h
ret

hexdec: mov b,#10h ;Hexadecimal to deciaml conversion
div ab
mov 60h,b
mov b,#0ah
mul ab
add a,60h
ret

ascii: ;ASCII lookup table
db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h

end

Added after 6 minutes:

NIDHI PATEL wrote:
H_D_R wrote:
vietdung79 wrote:
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...???



i am having rtc assembly language code i am sending u try , may be it will help u, though i am not clearly getting which type of help u need.

Digital Clock with alarm using DS1307
;
; For Keil/ A51 Macro Assembler




hold macro ;delay macro for I2C
nop
nop
nop
endm

disp_str macro string ;Macro for sending string to LCD
irpc char, <string>
if nul 'char'
exitm
endif
mov a,#'char'
lcall data_in
endm
endm

build_char macro P1,P2,P3,P4,P5,P6,P7,P8 ;Macro for building a custom character
irp arg, <P1,P2,P3,P4,P5,P6,P7,P8>
mov a,#arg
acall data_in
endm
endm

sec equ 30h ;second register
min equ 31h ;minutes register
hour equ 32h ;hour register
days equ 33h ;days register
date equ 34h ;date register
month equ 35h ;month register
year equ 36h ;year register
alarm equ 37h ;alarm register
sig equ 38h ;signature for data checking in RTC RAM
ahour equ 39h ;alarm hour register
amin equ 3Ah ;alarm minute register
sda equ P1.1 ;Serial data pin
scl equ P1.0 ;Serial clock pin
rw equ p3.6 ;read write pin of LCD
en equ p3.5 ;enable pin of LCD
rs equ p3.7 ;register select pin of LCD
alarm_key equ p3.3 ;Alarm set key
time_key equ p3.2 ;Time ser key
increment equ p1.3 ;Increment value
decrement equ p1.2 ;Decrement Value
alarm_port equ p1.4 ;Alarm Buzzer port
alarm_flag equ 20h ;flag for alarm
time_flag equ 21h ;flag for time
ampm_flag equ 22h ;am/pm flag
alarm_on equ 23h ;Alarm on flag
alarm_off equ 24h ;alarm off flag
alarm_ring equ 25h ;alarm ring flag
alarm_hrs equ 58h ;Alarm hour register
alarm_min equ 59h ;Alarm Minutes register
alarm_chk_hour equ 5Ah ;Alarm hour check register
alarm_chk_min equ 5Bh ;Alarm min check register
ampm equ 61h ;AM/PM register
BELL equ 0h ;Bell icon
SPEAKER_OFF equ 1h ;speaker off icon
SPEAKER_ON equ 2h ;speaker on icon
CLOCK equ 3h ;clock icon
OK equ 4h ;ok icon
HEART equ 5h ;heart icon
MUSIC equ 6h ;music icon

org 0000h ;Starting of main program
ljmp start

org 03h ;interrupt for set time
setb time_flag
reti

org 13h ;Interrupt for set alarm
setb alarm_flag ;and switch off the alarm if on
jnb alarm_off,hmmm
setb alarm_port
mov a,#1h
lcall command
mov a,#81h
lcall command
mov a,#OK
acall data_in
mov r7,#35
disp_str < Alarm Off!>
setb tr0
loooop: jnb tf0,$
clr tf0
djnz r7,loooop
clr tr0
mov a,#1h
acall command
acall disp_const
setb alarm_off
setb alarm_on
clr alarm_flag
clr alarm_flag
clr alarm_on
setb alarm_port
clr alarm_off
clr alarm_flag
clr alarm_ring
hmmm: reti

start: mov tmod,#1h ;start routine
mov sp,#10h
acall initial
acall build
mov a,#80h
acall command
mov a,#CLOCK
acall data_in
disp_str < Digital Clock > ;Name display
mov r7,#70
setb tr0
wloop: jnb tf0,$
clr tf0
djnz r7,wloop
clr time_flag
clr alarm_flag
clr alarm_on
clr ampm_flag
setb alarm_port
mov ie,#85h
acall startc ;Reading signature byte if same then no need
mov a,#0d0h ;of initialization else initialize the RTC
acall send
mov a,#08h
acall send
acall startc
mov a,#0d1h
acall send
acall recv
acall stop
cjne a,#'~',done
sjmp run
done: acall initial
acall disp_const
mov sec,#00h ;For more information about the RTC DS1307
mov min,#0h ;Please refer to the datasheet
mov hour,#52h ;21h for 24 hour format
mov days,#01h
mov date,#1h
mov month,#1h
mov year,#05h
mov alarm,#0
mov sig,#'~'
mov ahour,#0
mov amin,#0
mov r6,#0bh
mov r0,#30h
mov r1,#00h
acall rtc_ini ;initializing RTC if required
run: acall initial
acall disp_const
run1: acall startc ;Actual Starting
mov a,#0d0h
acall send
mov a,#00h
acall send
mov r6,#3fh
acall startc ;Reading the RCT content
mov a,#0d1h
acall send
mov r0,#40h
here: acall recv
djnz r6,here
acall stop
acall display ;Display RTC
jnb time_flag,noset ;check for time flag if set the set the clock
clr time_flag
clr ea
acall time_set
clr time_flag
mov r6,#09h
mov r0,#30h
mov r1,#00h
acall rtc_ini
clr time_flag
mov a,#1h
acall command
mov a,#81h
acall command
mov a,#OK
acall data_in
disp_str < Time Set!>
mov r7,#35
setb tr0
looooop:jnb tf0,$
clr tf0
djnz r7,looooop
clr tr0
mov a,#1h
acall command
acall disp_const
setb ea
noset:
jnb alarm_flag,noset1 ;check for alarm flag if set then set alarm
clr alarm_flag
clr ea
lcall alarm_set
setb ea
setb alarm_on
clr alarm_flag
setb alarm_on
noset1:
jnb alarm_ring,noset2 ;check if alarm ring flag is set
lcall alarm_alarm ;if set then ring the alarm
noset2: ljmp run1 ;Do everything again

startc: ;I2C atart condition subroutine
clr scl
setb sda
hold
setb scl
clr sda
hold
ret
send: ;Sending data to I2C bus
mov r7,#08
back:
clr scl
hold
rlc a
mov sda,c
setb scl
hold
clr scl
hold
djnz r7,back
setb sda
setb scl
hold
clr scl
hold
ret

stop: hold ;I2C stop Condition
clr sda
setb scl
nop
setb sda
hold
clr scl
ret

recv: ;Recieving data from I2C bus
mov r7,#08
back2:
setb sda
setb scl
hold
mov c,sda
rlc a
clr scl
hold
djnz r7,back2
setb sda
clr scl
hold
clr sda
setb scl
hold
clr scl
hold
mov @r0,a
inc r0
ret

rtc_ini:acall startc ;RTC initialization subroutine
mov a,#0d0h
acall send
mov a,r1
acall send
mov a,@r0
acall send
inc r0
inc r1
acall stop
djnz r6,rtc_ini
acall stop
ret

initial:mov a,#38h ;LCD initialization subroutine
acall command
mov a,#0ch
acall command
mov a,#01h
acall command
mov a,#06h
acall command
ret

build: mov a,#40h ;Building custom character routine
acall command
build_char 4h,0eh,0eh,0eh,1fh,0h,4h,0h ;BELL
build_char 1h,3h,0fh,0fh,0fh,3h,1h,0h ;SPEAKER OFF
build_char 8h,10h,0h,18h,0h,10h,8h,0h ;SPEAKER ON
build_char 0h,0eh,15h,17h,11h,0eh,0h,0h ;CLOCK
build_char 0h,1h,3h,16h,1ch,8h,0h,0h ;OK
build_char 0ah,1fh,1fh,1fh,0eh,4h,0h,0h ;HEART
build_char 2h,3h,2h,0eh,1eh,0ch,0h,0h ;MUSIC
ret

display:mov r1,#40h ;Displaying RTC content
mov a,#0Cah
acall command
mov a,@r1
mov 50h,@r1
acall disp_val
PASS: inc r1
mov a,#0C7h
acall command
mov a,@r1
mov 51h,@r1
mov alarm_chk_min,@r1
acall disp_val
PASS1: inc r1
mov a,#0c4h
acall command
mov a,@r1
mov 52h,@r1
mov alarm_chk_hour,@r1
mov r4,a
anl a,#1fh
acall disp_val
mov a,r4
anl a,#20h
cjne a,#00h,pm
mov a,#0cdh
acall command
disp_str <am>
sjmp pass2
pm: mov a,#0cdh
acall command
disp_str <pm>
PASS2: inc r1
mov a,#80h
acall command
mov a,@r1
mov 53h,@r1
acall day
PASS3: inc r1
mov a,#88h
acall command
mov a,@r1
mov 54h,@r1
acall disp_val
PASS4: inc r1
mov a,#8bh
acall command
mov a,@r1
mov 55h,@r1
acall disp_val
PASS5: inc r1
mov a,#8eh
acall command
mov a,@r1
mov 56h,@r1
acall disp_val
jnb alarm_on,PASS6
inc r1
inc r1
inc r1
mov a,@r1
cjne a,52h,PASS6
inc r1
mov a,@r1
cjne a,51h,PASS6
setb alarm_ring
setb alarm_ring
PASS6: ret

disp_val: ;Display 8-bit Decimal Value
push acc
mov r5,a
anl a,#0f0h
swap a
mov dptr,#ascii
movc a,@a+dptr
acall data_in
mov a,r5
anl a,#0fh
movc a,@a+dptr
acall data_in
pop acc
ret

disp_const: ;Display constant characters
mov a,#8ah
acall command
mov a,#'/'
acall data_in
mov a,#8dh
acall command
mov a,#'/'
acall data_in
mov a,#0c6h
acall command
mov a,#':'
acall data_in
mov a,#0c9h
acall command
mov a,#':'
acall data_in
mov a,#0c0h
acall command
mov a,#BELL
acall data_in
mov a,#SPEAKER_OFF
acall data_in
ret

command:acall busy ;Sending command to LCD
MOV P2,A
CLR rs
CLR rw
SETB en
CLR en
RET

data_in:acall busy ;Sending data to LCD
SETB rs
MOV P2,A
CLR rw
SETB en
CLR en
RET

busy: SETB P2.7 ;Checking Busy flag
CLR rs
SETB rw
wait: CLR en
SETB en
JB P2.7,wait
RET

day: push acc ;Displaying day subroutine for RTC
cjne a,#01,skip
disp_str < *Sun*>
ljmp exit
skip: cjne a,#02,skip2
disp_str < *Mon*>
ljmp exit
skip2: cjne a,#03,skip3
disp_str < *Tue*>
ljmp exit
skip3: cjne a,#04,skip4
disp_str < *Wed*>
sjmp exit
skip4: cjne a,#05,skip5
disp_str< *Thu*>
sjmp exit
skip5: cjne a,#06,skip6
disp_str < *Fri*>
sjmp exit
skip6: disp_str < *Sat*>
exit: pop acc
ret

time_set: ;Setting time subroutine
jnb time_key,$
mov a,#1
acall command
mov a,#80h
acall command
mov a,#CLOCK
acall data_in
disp_str < set minutes:>
mov a,#0c5h
acall command
mov a,51h
acall disp_val
lcall hexdec
key: push acc
mov a,#0c5h
acall command
pop acc
jb increment,chk1
inc a
cjne a,#60,ok1
mov a,#0
ok1: jnb increment,$
lcall dechex
acall disp_val
lcall hexdec
sjmp key
chk1: jb decrement,chk2
dec a
cjne a,#0ffh,ok2
mov a,#59
ok2: jnb decrement,$
lcall dechex
acall disp_val
lcall hexdec
sjmp key
chk2: jb time_key,key

lcall dechex
mov min,a
jnb time_key,$

mov a,#1
acall command
mov a,#80h
acall command
mov a,#CLOCK
acall data_in
disp_str < set hours:>
mov a,#0c5h
acall command
mov a,52h
anl a,#1fh
acall disp_val
lcall hexdec
key1: push acc
mov a,#0c5h
acall command
pop acc
jb increment,chk3
inc a
cjne a,#13,ok3
mov a,#1
ok3: jnb increment,$
lcall dechex
acall disp_val
lcall hexdec
sjmp key1
chk3: jb decrement,chk4
dec a
cjne a,#0,ok4
mov a,#12
ok4: jnb decrement,$
lcall dechex
acall disp_val
lcall hexdec
sjmp key1
chk4: jb time_key,key1

lcall dechex
mov hour,a
jnb time_key,$

mov a,#1
acall command
mov a,#80h
acall command
mov a,#CLOCK
acall data_in
disp_str < set am/pm:>
mov a,52h
anl a,#20h
cjne a,#00h,pm1
mov a,#0c5h
acall command
disp_str <am>
setb ampm_flag
sjmp key2
pm1: mov a,#0c5h
acall command
disp_str <pm>
clr ampm_flag

key2: mov a,#0c5h
acall command
jb increment,chk5
jb ampm_flag,ok5
setb ampm_flag
disp_str <am>
hold
jnb increment,$
sjmp key2
ok5: clr ampm_flag
disp_str <pm>
hold
jnb increment,$
sjmp key2
chk5: jb decrement,chk6
jb ampm_flag,ok6
setb ampm_flag
disp_str <am>
hold
jnb decrement,$
sjmp key2
ok6: clr ampm_flag
disp_str <pm>
hold
jnb decrement,$
sjmp key2
chk6: jb time_key,key2

jnb ampm_flag,noam
mov a,hour
add a,#40h
sjmp nopm
noam: mov a,hour
add a,#60h
nopm: mov hour,a
jnb time_key,$

mov a,#1
acall command
mov a,#80h
acall command
mov a,#CLOCK
acall data_in
disp_str < set days:>
mov a,#0c5h
lcall command
mov a,53h
push acc
lcall day
pop acc
key3: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,chk7
inc a
cjne a,#8,ok7
mov a,#1
ok7: jnb increment,$
push acc
lcall day
pop acc
sjmp key3
chk7: jb decrement,chk8
dec a
cjne a,#0,ok8
mov a,#7
ok8: jnb decrement,$
push acc
lcall day
pop acc
sjmp key3
chk8: jb time_key,key3

mov days,a
jnb time_key,$

mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#CLOCK
lcall data_in
disp_str < set date:>
mov a,#0c5h
lcall command
mov a,54h
lcall disp_val
lcall hexdec
key4: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,chk9
inc a
cjne a,#32,ok9
mov a,#1
ok9: jnb increment,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key4
chk9: jb decrement,chk10
dec a
cjne a,#0,ok10
mov a,#31
ok10: jnb decrement,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key4
chk10: jb time_key,key4

lcall dechex
mov date,a
jnb time_key,$

mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#CLOCK
lcall data_in
disp_str < set month:>
mov a,#0c5h
lcall command
mov a,55h
lcall disp_val
lcall hexdec
key5: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,chk11
inc a
cjne a,#13,ok11
mov a,#1
ok11: jnb increment,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key5
chk11: jb decrement,chk12
dec a
cjne a,#0,ok12
mov a,#12
ok12: jnb decrement,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key5
chk12: jb time_key,key5

lcall dechex
mov month,a
jnb time_key,$

mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#CLOCK
lcall data_in
disp_str < set year:>
mov a,#0c5h
lcall command
mov a,56h
lcall disp_val
lcall hexdec
key6: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,chk13
inc a
cjne a,#100,ok13
mov a,#0
ok13: jnb increment,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key6
chk13: jb decrement,chk14
dec a
cjne a,#0ffh,ok14
mov a,#99
ok14: jnb decrement,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp key6
chk14: jb time_key,key6

jnb time_key,$
lcall dechex
mov year,a
mov alarm,#00
mov sig,#'~'
clr time_flag
clr time_flag
ret

alarm_set: ;Setting Alarm Subroutine
jnb alarm_key,$
mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#BELL
lcall data_in
disp_str < set minutes:>
mov a,#0c5h
lcall command
mov a,#30h
lcall disp_val
lcall hexdec
akey: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,achk1
inc a
cjne a,#60,aok1
mov a,#0
aok1: jnb increment,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp akey
achk1: jb decrement,achk2
dec a
cjne a,#0ffh,aok2
mov a,#59
aok2: jnb decrement,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp akey
achk2: jb alarm_key,akey

lcall dechex
mov alarm_min,a
jnb alarm_key,$

mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#BELL
lcall data_in
disp_str < set hours:>
mov a,#0c5h
lcall command
mov a,#44h
anl a,#1fh
lcall disp_val
lcall hexdec
akey1: push acc
mov a,#0c5h
lcall command
pop acc
jb increment,achk3
inc a
cjne a,#13,aok3
mov a,#1
aok3: jnb increment,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp akey1
achk3: jb decrement,achk4
dec a
cjne a,#0,aok4
mov a,#12
aok4: jnb decrement,$
lcall dechex
lcall disp_val
lcall hexdec
sjmp akey1
achk4: jb alarm_key,akey1

lcall dechex
mov alarm_hrs,a
jnb alarm_key,$

mov a,#1
lcall command
mov a,#80h
lcall command
mov a,#BELL
lcall data_in
disp_str < set am/pm:>
mov a,#0c5h
lcall command
mov a,alarm_hrs
anl a,#20h
cjne a,#20h,its_pm
disp_str <am>
setb ampm_flag
sjmp akey2
its_pm: disp_str <pm>
clr ampm_flag
akey2: mov a,#0c5h
lcall command
jb increment,achk5
jb ampm_flag,aok5
setb ampm_flag
disp_str <am>
hold
jnb increment,$
sjmp akey2
aok5: clr ampm_flag
disp_str <pm>
hold
jnb increment,$
sjmp akey2
achk5: jb decrement,achk6
jb ampm_flag,aok6
setb ampm_flag
disp_str <am>
hold
jnb decrement,$
sjmp akey2
aok6: clr ampm_flag
disp_str <pm>
hold
jnb decrement,$
sjmp akey2
achk6: jb alarm_key,akey2
jnb alarm_key,$
mov a,alarm_hrs
jb ampm_flag,anoam
add a,#60h
sjmp anopm
anoam: mov a,alarm_hrs
add a,#40h
anopm: mov alarm_hrs,a
mov ahour,alarm_hrs
mov amin,alarm_min
mov r6,#02h
mov r0,#39h
mov r1,#09h
lcall rtc_ini
mov a,#1h
lcall command
mov a,#81h
lcall command
mov a,#OK
lcall data_in
disp_str < Alarm On!>
mov a,#0c4h
lcall command
mov a,alarm_hrs
anl a,#1fh
lcall disp_val
mov a,#':'
lcall data_in
mov a,alarm_min
lcall disp_val
mov a,alarm_hrs
anl a,#20h
cjne a,#00h,ppm
disp_str < am>
sjmp ppass2
ppm: disp_str < pm>
ppass2: mov r7,#35
setb tr0
looop: jnb tf0,$
clr tf0
djnz r7,looop
clr tr0
mov a,#1h
lcall command
lcall disp_const
mov a,#SPEAKER_ON
lcall data_in
setb alarm_off
setb alarm_on
clr alarm_flag
clr alarm_flag
ret

alarm_alarm: ;Alarm Ring subroutine
clr alarm_port
mov r3,#0ffh
a_loop: mov r4,#0ffh
djnz r4,$
djnz r3,a_loop
setb alarm_port
mov r3,#0ffh
a_loop1:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop1
clr alarm_port
mov r3,#0ffh
a_loop2:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop2
setb alarm_port
mov r3,#0ffh
a_loop3:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop3
clr alarm_port
mov r3,#0ffh
a_loop4:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop4
setb alarm_port
mov r3,#0ffh
a_loop5:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop5
clr alarm_port
mov r3,#0ffh
a_loop6:mov r4,#0ffh
djnz r4,$
djnz r3,a_loop6
setb alarm_port
ret

dechex: mov b,#0ah ;Decimal to Hexadecimal conversion
div ab
mov 60h,b
mov b,#10h
mul ab
add a,60h
ret

hexdec: mov b,#10h ;Hexadecimal to deciaml conversion
div ab
mov 60h,b
mov b,#0ah
mul ab
add a,60h
ret

ascii: ;ASCII lookup table
db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h

end
Back to top
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers
Page 2 of 2 All times are GMT + 2 Hours
Goto page Previous  1, 2


Abuse
Administrator
Moderators
topic RSS 
sitemap