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.

DS1302 RTC interfacing with 8051

Status
Not open for further replies.
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
 

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.
 

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
 

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
 

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top