From PICLIST@MITVMA.MIT.EDU Thu Nov 14 17:01:02 2002 Received: from cherry.ease.lsoft.com [209.119.0.109] by dpmail10.doteasy.com with ESMTP (SMTPD32-7.13) id A74E11AC0084; Thu, 14 Nov 2002 17:01:02 -0800 Received: from PEAR.EASE.LSOFT.COM (209.119.0.19) by cherry.ease.lsoft.com (LSMTP for Digital Unix v1.1b) with SMTP id <0.007DA340@cherry.ease.lsoft.com>; Thu, 14 Nov 2002 19:21:06 -0500 Received: from MITVMA.MIT.EDU by MITVMA.MIT.EDU (LISTSERV-TCP/IP release 1.8d) with spool id 4761 for PICLIST@MITVMA.MIT.EDU; Thu, 14 Nov 2002 19:20:53 -0500 Received: from MITVMA (NJE origin SMTP@MITVMA) by MITVMA.MIT.EDU (LMail V1.2d/1.8d) with BSMTP id 5920; Thu, 14 Nov 2002 19:20:23 -0500 Received: from maple.websurf.net [216.206.73.2] by mitvma.mit.edu (IBM VM SMTP Level 320) via TCP with ESMTP ; Thu, 14 Nov 2002 19:20:22 EST X-Comment: mitvma.mit.edu: Mail was sent by maple.websurf.net Received: from p4.DOMAIN (ict-dialup-25.websurf.net [65.113.4.152] (may be forged)) by maple.websurf.net (8.11.1/8.11.1) with SMTP id gAF0KKG26433 for ; Thu, 14 Nov 2002 18:20:20 -0600 Received: from p4.DOMAIN ([192.168.3.12]) by p4.DOMAIN (602Pro LAN SUITE v. 2000A) id 2ce8527f for PICLIST@MITVMA.MIT.EDU; Thu, 14 Nov 2002 18:19:54 -0600 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4024 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal Message-ID: <000801c28c3c$b8db6e70$0c03a8c0@DOMAIN> Date: Thu, 14 Nov 2002 18:19:54 -0600 Reply-To: pic microcontroller discussion list Sender: pic microcontroller discussion list From: techhead Subject: Re: [PIC]: interfacing with the DS1302 RTC To: PICLIST@MITVMA.MIT.EDU In-Reply-To: <1076814cef.14cef10768@shaw.ca> X-RCPT-TO: Status: R X-UIDL: 277600550 X-Evolution-Source: pop://mailinglist%40farcite.net@mail.farcite.net/ X-Evolution: 00000709-0000 Here's some code I just finished. Include "MODEDEFS.BAS" ' Include Shiftin/out modes DEFINE OSC 4 ' Alias pins RST var PORTB.4 IO var PORTB.1 SCLK var PORTB.3 Lout var PORTB.2 ' Allocate 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 w1 var byte tens var byte ones var byte Low RST ' Reset RTC Low SCLK OPTION_REG.7 = 0 ' Enable PORTB pullups Pause 10 ' Wait for LCD to startup ' Set initial time to 8:00:00AM 06/06/02 rtcyear = $02 rtcday = $06 rtcmonth = $06 rtcdate = $06 rtchr = $08 rtcmin = 0 rtcsec = 0 Gosub settime ' Set the time Goto mainloop ' Skip subroutines ' Subroutine to write time to RTC 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 ' Subroutine to read time from RTC gettime: 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] 'Convert Time from BCD to decimal w1 = rtcsec Tens = w1 & %11110000 Tens = Tens >> 4 Tens = Tens * 10 Ones = w1 & %00001111 w1 = Tens + ones rtcsec = w1 w1 = rtcmin Tens = w1 & %11110000 Tens = Tens >> 4 Tens = Tens * 10 Ones = w1 & %00001111 w1 = Tens + ones rtcmin = w1 w1 = rtchr Tens = w1 & %11110000 Tens = Tens >> 4 Tens = Tens * 10 Ones = w1 & %00001111 w1 = Tens + ones rtchr = w1 RST = 0 ' Reset RTC Return ' Main program loop - in this case, it only updates the LCD with the time mainloop: Gosub gettime ' Read the time from the RTC ' Display time on LCD Serout lout,N9600,[254,1] ' Clear Display 'Serout lout,N9600,[254,128,"hello"] Serout lout,N9600,[254,128,#rtcmonth,"/",#rtcdate,"/",#rtcyear] Serout lout,N9600,[254,192,#rtchr,":",#rtcmin,":",#rtcsec] 'Lcdout $fe, 1, hex2 rtcmonth, "/", hex2 rtcdate, "/" , hex2 rtcyear,_" ", hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec Pause 300 ' Do it about 3 times a second Goto mainloop ' Do it forever End -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU] On Behalf Of Brendan Moran Sent: Thursday, November 14, 2002 6:12 PM To: PICLIST@MITVMA.MIT.EDU Subject: [PIC]: interfacing with the DS1302 RTC Hi, I'm wondering if anyone knows what the protocol for interfacing with the Dallas DS1302 RTC. It has a 2-wire serial interface (3, including #RESET), so it looks like an I2C interface, but with the requirement of the #RESET line, it looks like a modified SPI. Does anyone know how to use this device? TIA --Brendan -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics