Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

DS1302 RTC interfacing with 8051

Status
Not open for further replies.

ebenni

Advanced Member level 4
Joined
Jan 30, 2002
Messages
105
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Turkey
Activity points
545
ds1302 rtc

hi,
C code.
 

Bus Master

Full Member level 3
Joined
Dec 9, 2001
Messages
187
Helped
9
Reputation
18
Reaction score
3
Trophy points
1,298
Location
Just behind You ;-)
Activity points
1,462
rtc ds1302

A very important point for the design accuracy is to use a 'Matched Capacitance Crystal" of 6pF, i've tried to use a non-matched capacitance crystal (at the same 32768 Hz) and had a time latencey of about 2-3 minutes a day.

Matched crystals can easily be found, e.g., wxw.dontronics.com
 

Nick C.

Full Member level 5
Joined
Dec 19, 2002
Messages
281
Helped
33
Reputation
66
Reaction score
25
Trophy points
1,308
Activity points
2,213
ds1302 c code

Yeah, it pays to read the datasheet! I spent two
days trying to figure out why this RTC wasn't
keeping proper time. Silly me - I was using a
12.5pf crystal.
 

mbyka

Full Member level 5
Joined
May 12, 2002
Messages
296
Helped
12
Reputation
24
Reaction score
10
Trophy points
1,298
Location
from istanbul in TURKEY
Activity points
2,031
ds1302 programing

DS1302 AND PBP RTC CODE

'***************************************************
'***** MBYKA **********
'***************************************************
' DS1302 RTC use

Include "MODEDEFS.BAS"

Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 0
Define LCD_EREG PORTB
Define LCD_EBIT 1

'pins
RST var PORTA.0
IO var PORTA.1
SCLK var PORTA.2

'variables
rtcyear var byte
rtcday var byte
rtcmonth var byte
rtcdate var byte
rtchr var byte
rtcmin var byte
rtcsec var byte
rtccontrol var byte


Main:
Low RST ' Reset RTC
Low SCLK
' saat Set 13:42:00 04/13/02
rtcyear = $02
rtcday = $06
rtcmonth = $04
rtcdate = $13
rtchr = $13
rtcmin = $42
rtcsec = $00
Gosub SetTime
Goto Main_Loop

Main_Loop:
Gosub gettime ' saati oku
Lcdout $fe, 1 '1.satır
lcdout hex2 rtcmonth, "/", hex2 rtcdate, "/" , hex2 rtcyear
lcdout $fe,$c0
lcdout hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec
Pause 300 ' 0.3 saniye bekle
Goto Main_Loop




SetTime:
RST = 1 ' Ready for transfer
' Enable write
Shiftout IO, SCLK, LSBFIRST, [$8e, 0]
RST = 0 ' Reset RTC
RST = 1 ' Ready for transfer
' Write all 8 RTC registers in burst mode
Shiftout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0]
RST = 0 ' Reset RTC
Return


GetTime: ' Subroutine to read time from RTC
RST = 1 ' Ready for transfer
Shiftout IO, SCLK, LSBFIRST, [$bf] ' Read all 8 RTC registers in burst mode
Shiftin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]
RST = 0 ' Reset RTC
Return

End
 

Fragrance

Advanced Member level 4
Joined
Jul 26, 2002
Messages
1,191
Helped
247
Reputation
494
Reaction score
198
Trophy points
1,343
Location
East Of Earth
Activity points
8,916
c code for ds1302

mbyka said:
DS1302 AND PBP RTC CODE

'***************************************************
'***** MBYKA **********
'***************************************************
' DS1302 RTC use

Include "MODEDEFS.BAS"

Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 0
Define LCD_EREG PORTB
Define LCD_EBIT 1

'pins
RST var PORTA.0
IO var PORTA.1
SCLK var PORTA.2

'variables
rtcyear var byte
rtcday var byte
rtcmonth var byte
rtcdate var byte
rtchr var byte
rtcmin var byte
rtcsec var byte
rtccontrol var byte


Main:
Low RST ' Reset RTC
Low SCLK
' saat Set 13:42:00 04/13/02
rtcyear = $02
rtcday = $06
rtcmonth = $04
rtcdate = $13
rtchr = $13
rtcmin = $42
rtcsec = $00
Gosub SetTime
Goto Main_Loop

Main_Loop:
Gosub gettime ' saati oku
Lcdout $fe, 1 '1.satır
lcdout hex2 rtcmonth, "/", hex2 rtcdate, "/" , hex2 rtcyear
lcdout $fe,$c0
lcdout hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec
Pause 300 ' 0.3 saniye bekle
Goto Main_Loop




SetTime:
RST = 1 ' Ready for transfer
' Enable write
Shiftout IO, SCLK, LSBFIRST, [$8e, 0]
RST = 0 ' Reset RTC
RST = 1 ' Ready for transfer
' Write all 8 RTC registers in burst mode
Shiftout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0]
RST = 0 ' Reset RTC
Return


GetTime: ' Subroutine to read time from RTC
RST = 1 ' Ready for transfer
Shiftout IO, SCLK, LSBFIRST, [$bf] ' Read all 8 RTC registers in burst mode
Shiftin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]
RST = 0 ' Reset RTC
Return

End
good and great nice work mybka i used the timming crystal which is best i think come from old digital rest watch they work good and no matching problem accuracy is fine, in a month 1 second error in time

regards
Fragrance
 

Alyaa

Newbie level 1
Joined
Jul 10, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
programming pc rtc

hi there,
I tried compiling the code posted by ebenni on MPLAB IDE (MCC18) with PIC 18F452

I got the following error
Error [1027] unable to locate 'intrins.h'
Error [1027] unable to locate 'reg51.h'
Error [1027] unable to locate 'geral.h'

I was wondering if anyone can attach these header files or tell me where I can find it.

thanks in advance,
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top