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.

RTC DS1307 Interfacing with MCU 89S52

Status
Not open for further replies.
timer basic code ds1307

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
 

89s52+ds1307

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
 

asm send data to at24c02

can't understand
Please first show your design
 

o/p port status on reset for 89s52

ckshivaram said:
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...:D :D :D
 

set de instrucciones del 89s52

H_D_R said:
vietdung79 said:
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 said:
H_D_R said:
vietdung79 said:
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
 

i2c+rtc+mcu+asm

hi..
is there any circuit which automatically reset the uC when it hangs??..can i use 555timer for reset the uC???
any alternative of WDT??

Thank you
 


hi all...
iam having trobble with rtc(ds1307) to,i tried to make 7-seg led clock using atmega8 and rtc but i can understand how to read/write & put the data from rtc to segment did anyone here have a sample code in bascom? plz. the conection for the uC is portd = segment array,portb=common of the seg(multiplexed),portc=switch button for time&date setting,portc.4=sda,portc.5=scl thanks in advance
 

Re: isd2560 16 keypad matrix

// 7 seg clock using ds 1307
// change for pcb_2051 clock
// 13-11-2009
// syed rizwan shah
#include <reg2051.h>
//#include <reg51.h>
#include "i2c_clk.h"
#include <stdio.h>

unsigned int b2,b3,b4,b5,b6,cont,riz1,riz2,buffer[5],digit1,digit2,digit3,digit4,digit0,min_s,hor_s;
unsigned char flag1,time[5],week,date,month,year,control,sec_r,sec_l,min_r,min_l,hor_r,hor_l,b1,addr,decimal,key;
//char key,delay;
//char convert[16] = {0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6, };

//char convert[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,} ;
// 0 1 2 3 4 5 6 7 8 9
char convert[10] = {0xed, 0x88, 0x79, 0xd9, 0x9c, 0xd5, 0xf5, 0x89, 0xfd, 0xdd,} ;
/*
//char convert[10] = {
// edcbgaxf
011110101, //0
000110000, //1
011011100, //2
001111100, //3
000111001, //4
001101101, //5
011101101, //6
000110100, //7
011111101, //8
001111101, //9
}; */


//sbit dx=P1^1;
//sbit hkey=P3^2;
//sbit mkey=P3^2;
sbit d0 = P3^0;
sbit d1 = P3^1;
sbit d2 = P3^3;
sbit d3 = P3^4;
sbit setkey=P3^2;
void pause(int);
void scanLED(int);
void digitsToBuffer();
void read_clk();
void write_clk();
//void keyexe();
//void set_hour();
//void set_min();
//void keydelay();
void key1();
//=============================================================================

void main (void)
{


while(1) // run continuously

{


digitsToBuffer(); // put digits in buffer
scanLED(1); // and scan four digits continuously
key1();
//keydelay();
cont++;
if(cont==1)
{
cont=0;
read_clk();

}
}
}
//============================================================================

void digitsToBuffer()
{
decimal= time[0] & 0x01;
/*
buffer[0] = convert[2];//[min_r]; // convert bcd digit to
buffer[1] = convert[1];//[min_l]; // seven segments display code
buffer[2] = convert[3];//[hor_r];
buffer[3] = convert[key];//[hor_r];
//buffer[4] = convert[4];//[hor_r]; */


buffer[3] = convert[min_r]; // convert bcd digit to
buffer[2] = convert[min_l]; // seven segments display code
buffer[0] = convert[hor_r];
//////////////////////////for blink sec or decimal///////////////////////////////
if(decimal ==0x01)
buffer[0] = buffer[0] | 0x02;
////////////////////////////////////////////////////////////////////////////////
buffer[1] = convert[hor_l];
/////////////////////////////blank on zero//////////////////////////////////////
if(hor_l==0)
buffer[1]=0;
/////////////////////////////////////////////////////////////////////////////////


}
void scanLED(j) // scan 4-digit LED
{

int i;
for( i = 0; i < 4; i++) // 4-DIGIT scanning
{
//*************************
switch(i){
case (0):
d0=1;
if(setkey==0)
key=1;
break;
//**************************
case (1):
d0=0;
d1=1;
if(setkey==0)
key=2;
break;
//************************** case (2):
case (2):
d1=0;
d2=1;
break;
//**************************
case (3):
d2=0;
d3=1;
}
//**************************
P1 = buffer; // turn on segments
pause(100); // delay a while
P1 = 0x00; // turn off display
d3=0;
}}
void pause(j)
int j;
{
int i;
for (i = 0; i < 50; i++); // delay of 'j' cpu cycles
}

//////////////////////////////////////////////////////////////////////////////////
void read_clk()
{
addr=0x00;
i2c_start(); /* Start i2c bus */

i2c_write(eeproms_id); /* Connect to RTC */

i2c_write(addr&0x00); /* Request RAM address*/

i2c_start(); /* Start i2c bus */

i2c_write(eeproms_id+1);/* Connect to RTC for Read */

time[0] = i2c_read(); /* Receive data */
i2c_ack();
time[1] = i2c_read(); /* Receive data */
i2c_ack();
time[2] = i2c_read(); /* Receive data */
i2c_ack();
week = i2c_read();
i2c_ack();
date = i2c_read();
i2c_ack();
month = i2c_read();
i2c_ack();
year = i2c_read();
i2c_ack();
control = i2c_read();
i2c_noack();

i2c_stop(); /* Stop i2c bus */

b1=0x0f;
b1=b1& time[0];
sec_r=b1;


b1=0x70;
b1=b1& time[0];
b1>>=4;
sec_l=b1;

b1=0x0f;
b1=b1& time[1];
// b1>>=4;
min_r=b1;

b1=0x70;
b1=b1& time[1];
b1>>=4;
min_l=b1;

b1=0x0f;
b1=b1& time[2];
// b1>>=4;
hor_r=b1;

b1=0x10;
b1=b1& time[2];
b1>>=4;
hor_l=b1;

}
//////////////////////////////////////////////////////////////////////////////////////////////////////
void write_clk()
{
addr=0x00;
i2c_start(); /* start i2c bus */
i2c_write(eeproms_id); /* Connect to RTC */

i2c_write(addr&0x00); /* Request RAM address */

i2c_write(0x00); /* Write sec on RAM specified address */
i2c_write(time[1]); /* Write minute on RAM specified address */
i2c_write(time[2]); /* Write hour on RAM specified address */
i2c_write(0x07); /* Write day on RAM specified address */
i2c_write(0x25); /* Write date on RAM specified address */
i2c_write(0x07); /* Write month on RAM specified address */
i2c_write(0x08); /* Write year on RAM specified address */
i2c_write(0x10); /* Write control out put on RAM specified address */
i2c_stop();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////

void key1()
{

if(key==1)
{
b4++;
if(b4==300)
{
b4=0;
hor_s = hor_l*10+hor_r;
hor_s++;
if(hor_s==13)
hor_s=1;
hor_l=hor_s/10;
hor_r=hor_s%10;
hor_l=hor_l<<4;
time[2]=hor_l | hor_r;
time[2]=time[2] | 0x40 ; //for 12 hour
write_clk();
read_clk();
scanLED(1);
key=0;
}
}
if(key==2)
{
b5++;
if(b5==200)
{
b5=0;
min_s = min_l*10+min_r;
min_s++;
if(min_s==60)
min_s=0;
min_l=min_s/10;
min_r=min_s%10;
min_l=min_l<<4;
time[1]=min_l | min_r;
write_clk();
read_clk();
scanLED(1);
key=0;
}
}

}

---------- Post added at 20:52 ---------- Previous post was at 20:48 ----------

// using KEIL compiler
// #include "i2c_clk.h" file here
sbit sda =P3^5; /* Set P2.7 = SDA */
//sbit sda =P1^3; /* Set P2.7 = SDA */
sbit scl= P3^7; /* Set P2.6 = SCL */
// unsigned char time[5];
#define i2c_dly 0x01 /* For delay i2c bus */
#define eeproms_id 0xd0 /* Microchip 24xx512 */

void i2c_delay();
void i2c_clock();
void i2c_start();
void i2c_stop();

bit i2c_write(unsigned char dat);
unsigned char i2c_read();

void i2c_delay()
{
unsigned char i;

for(i=0; i<i2c_dly; i++);
}

void i2c_clock()
{
// scanLED(1); // and scan four digits continuously
i2c_delay();
// scanLED(1); // and scan four digits continuously
scl = 1; // generate clock pulse
// scanLED(1); // and scan four digits continuously
i2c_delay();

scl = 0;
}

void i2c_start()
{
if(scl)
scl = 0; /* Clear SCL */

sda = 1; /* Set SDA */
scl = 1; /* Set SCL */
// scanLED(1); // and scan four digits continuously
i2c_delay();

sda = 0; /* Clear SDA */
// scanLED(1); // and scan four digits continuously
i2c_delay();

scl = 0; /* Clear SCL */
}

void i2c_stop()
{
if(scl)
scl = 0; /* Clear SCL */

sda = 0; /* Clear SDA */
i2c_delay();
// scanLED(1); // and scan four digits continuously
scl = 1; /* Set SCL */

i2c_delay();

sda = 1; /* Set SDA */
}

bit i2c_write(unsigned char dat)
{
bit data_bit;
unsigned char i;

for(i=0;i<8;i++) /* For loop 8 time(send data 1 byte) */
{
data_bit = dat & 0x80; /* Filter MSB bit keep to data_bit */
sda = data_bit; /* Send data_bit to SDA */

i2c_clock(); /* Call for send data to i2c bus */

dat = dat<<1;
}

sda = 1; /* Set SDA */
// scanLED(1); // and scan four digits continuously
i2c_delay();

scl = 1; /* Set SCL */
// scanLED(1); // and scan four digits continuously
i2c_delay();

data_bit = sda; /* Check acknowledge */
scl = 0; /* Clear SCL */
// scanLED(1); // and scan four digits continuously
i2c_delay();

return data_bit; /* If send_bit = 0 i2c is valid */
}

unsigned char i2c_read()
{
bit rd_bit;
unsigned char i, dat;

dat = 0x00;

for(i=0;i<8;i++) /* For loop read data 1 byte */
{
i2c_delay();
// scanLED(1); // and scan four digits continuously
scl = 1; /* Set SCL */

i2c_delay();
// scanLED(1); // and scan four digits continuously
rd_bit = sda; /* Keep for check acknowledge */
dat = dat<<1;
dat = dat | rd_bit; /* Keep bit data in dat */

scl = 0; /* Clear SCL */
}

return dat;
}

void i2c_ack()
{
sda = 0; /* Clear SDA */

i2c_delay();
// scanLED(1); // and scan four digits continuously
i2c_clock(); /* Call for send data to i2c bus */

sda = 1; /* Set SDA */
}

void i2c_noack()
{
sda = 1; /* Set SDA */

i2c_delay();
// scanLED(1); // and scan four digits continuously
i2c_clock(); /* Call for send data to i2c bus */

scl = 1; /* Set SCL */
}
 

thanks for the source code but how can i convert the code using bascom language coz i don't understain c language thanks again
 

Re: isd2560 16 keypad matrix

check this for details on RTC **broken link removed**
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top