Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Dallas Real-Time Clock Interface

 
Post new topic   Reply to topic    Forum Index -> Files
Author Message
spamiam



Joined: 13 Nov 2005
Posts: 664

Posted: 13 November 2005, 14:26 PM    Post subject: Dallas Real-Time Clock Interface Reply with quote

Here is API code to utilise the hardware I2C functions of the ZX-24 hardware and interface with the DS3231 precision real-time clock. THis is a nice piece of hardware which combines an extremely precise industrial-range temperature compensated oscillator with a real-time clock.

This code will also work with the more simple DS1337 RTC. The commands for the 1337 are a subset of those for the 3231.

Not all 3231 functions are fully supported in this API, just those I needed when I wrote the code. I will be writing some code to read the temperature of the oscillator, but this is not complete yet....

-Tony



DS3231_API.bas
 Description:

Download
 Filename:  DS3231_API.bas
 Filesize:  23.02 KB
 Downloaded:  3466 Time(s)

Back to top
spamiam



Joined: 13 Nov 2005
Posts: 664

Posted: 13 November 2005, 15:06 PM    Post subject: Reply with quote

Here is a program to use the DS3231. It was assembled just now from a more complex program with cuts and pastes. It might need a little tuning.





Private Const RTC_I2C_Channel as Byte = 0 'hardware!

Public Sub main()
Dim year as Byte
Dim month as Byte
Dim Mday as Byte
Dim hour as Byte
Dim minute as Byte
Dim second as Byte
Dim Success as Integer

Dim C_hour as Byte
Dim C_Minute as Byte
Dim C_second as Single
Dim C_Tick as Integer

Dim last_second as Byte


year = 05
month = 09
MDay = 17
hour = 20
minute = 21
second = 22
Success = 1
Last_second = 60

'Call LCDInitialize(LCDPort, 9600, LCDInputPin, LCDOutputPin)

Call OpenI2C(RTC_I2C_Channel,0,0,I2CMAX) 'open hardware I2C port at 409K bps

'otherwise use I2C400K


Call RTC_Set_Channel (RTC_I2C_Channel)
'Call FRAM_Set_Channel (RTC_I2C_Channel) 'They can be on the same channel



If (RTC_Osc_Stopped) Then 'the clock is wrong
Call RTC_Initialize ( RTC_I2C_Channel, _
RTC_Bat_Clk_On, _
RTC_Bat_SQW_Off, _
RTC_SQW_1KHz, _
RTC_SQW_Enable, _
RTC_Alm1_Disable, _
RTC_Alm2_Disable, _
RTC_32KHz_Enable)
Call RTC_PutTimeStamp (5,9,18,1,2,58, Success)
Call PutTimestamp(5,9,18,1,2,58.0)
Call LCDmovecursor(4,1)
Call LCDPutStr("Time lost")
Else 'the clock has not stopped
Call RTC_GetTime (hour, minute, second, Success)
last_second = second
'set all the settings to a known state (may have been different even with "good time")
Call RTC_Initialize ( RTC_I2C_Channel, _
RTC_Bat_Clk_On, _
RTC_Bat_SQW_Off, _
RTC_SQW_1KHz, _
RTC_SQW_Enable, _
RTC_Alm1_Disable, _
RTC_Alm2_Disable, _
RTC_32KHz_Enable)
Call LCDmovecursor(4,1)
Call LCDPutStr("No time lost")
'wait For the top of a second
do
Call RTC_GetTime (hour, minute, second, Success)
loop while (second = last_second)
'now set the cpu time
Call PutTime(hour, minute, CSng(second))
End If

End Sub
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> Files Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group