AppKit: Using the DS1302 Trickle Charge Timekeeping Chip

Similar documents
DS1302. Trickle Charge Timekeeping Chip FEATURES PIN ASSIGNMENT PIN DESCRIPTION

AIMMS Function Reference - Date Time Related Identifiers

DS1306. Serial Alarm Real Time Clock (RTC)

If It s Electronic, It Needs a Clock

DS1305EN. Serial Alarm Real-Time Clock

DS1305. Serial Alarm Real Time Clock (RTC) FEATURES PIN ASSIGNMENT ORDERING INFORMATION

DS1305EN. Serial Alarm Real-Time Clock

DS1305 Serial Alarm Real Time Clock (RTC)

DS1306 Serial Alarm Real-Time Clock

DS1305 Serial Alarm Real-Time Clock

INFORMATION TECHNOLOGY SPREADSHEETS. Part 1

Display Real Time Clock (RTC) On LCD. Version 1.2. Aug Cytron Technologies Sdn. Bhd.

CIMA Certificate BA Interactive Timetable

CIMA Asia. Interactive Timetable Live Online

CIMA Asia. Interactive Timetable Live Online

More on the 9S12 SPI Using the Dallas Semiconductor DS1302 Real Time Clock with the 9S12 SPI

Parallax BASIC Stamp IIsx

DS1216B. SmartWatch/RAM 16K/64K FEATURES PIN ASSIGNMENT PIN DESCRIPTION

MONITORING REPORT ON THE WEBSITE OF THE STATISTICAL SERVICE OF CYPRUS DECEMBER The report is issued by the.

MAKEVMA301 DS1302 REAL-TIME CLOCK MODULE USER MANUAL

Troop calendar

EE 308 Spring Using the 9S12 SPI

BS2p24 Demo Board (#45183)

Grade 4 Mathematics Pacing Guide

Scheduling. Scheduling Tasks At Creation Time CHAPTER

DS1673 Portable System Controller

NORTHWEST. Course Schedule: Through June 2018 MICROSOFT ACCESS. Access 2016 / Access 2010 / Last Revised: 11/13/2017

Commonwealth of the Northern Mariana Islands

INTERSIL SELECTION GUIDE. REAL TIME CLOCK ICs. High-Accuracy RTC Modules, Feature-Rich RTCs, Low-Cost, Low-Power RTCs

DS1670 Portable System Controller

Undergraduate Admission File

Freedom of Information Act 2000 reference number RFI

Calendar PPF Production Cycles Non-Production Activities and Events

BV4208. I2C-RTC & Temp. Sensor. Product specification. November 2008 V0.a. ByVac Page 1 of 5

CAUTION: TTL Only, Do Not Use ± 12 V RS-232

Hitachi H48C 3-Axis Accelerometer Module (#28026)

DIRRS+ Digital Infra-Red Ranging System Ideal for robotics projects. Singles (SKU # Pack (SKU #35100)

Raystar Microelectronics Technology Inc.

DATE OF BIRTH SORTING (DBSORT)

Example. Section: PS 709 Examples of Calculations of Reduced Hours of Work Last Revised: February 2017 Last Reviewed: February 2017 Next Review:

CS Programming I: Arrays

If You Need Help. Registering Your PAK-IV PAK-IV

DS1216 SmartWatch RAM DS1216B/C/D/H SmartWatch ROM DS1216E/F

DS1677 Portable System Controller

Section 1.2: What is a Function? y = 4x

DS1215. Phantom Time Chip FEATURES PIN ASSIGNMENT PIN DESCRIPTION

RTC Interface 89C51 DS M. Krishna Kumar MAM/M7/LU17/V1/ Vcc VCC 5 SDA P1.0 6 SCL P KHz 3 BAT 3.

ZX-17 Serial Real-Time Clock application board

Lecture 10: Boolean Expressions

NMOSE GPCD CALCULATOR

VMA301 DS1302 REAL-TIME CLOCK MODULE USER MANUAL

Conditional Formatting

DS1676 Total Elapsed Time Recorder, Erasable

Contents:


Schedule/BACnet Schedule

Low-Current, SPI-Compatible Real-Time Clock DS1347

Certification Program Schedule

Use the BS1 s Debug Output For Stamp-PC Communication

Home Security System with Remote Home Automation Control

ASSOCIATION OF CHARTERED CERTIFIED ACCOUNTANTS

Banana Pi Expansion Module User Manual

Training of BRs/NCs reviewers and experts for Biennial Update Reports technical analysis. 5 th BRs and NCs lead reviewers meeting

PT7C4563 Real-time Clock Module (I2C Bus)

WoTRS Master Calendar

Light Sensors. Measuring Light. The Phototransistor. Discharge Times. Measuring Light. Chapter 7: Measuring Light

Battery Protection IC for Single-cell Pack

Price Change Proposed. October 2018

OCT NOV DEC JAN FEB MAR APR MAY JUN JUL AUG SEP JAPAN MS YTD TOTAL

Basic Device Management

Pushing the Limits. ADSM Symposium Sheelagh Treweek September 1999 Oxford University Computing Services 1

DS1388 I2C RTC/Supervisor with Trickle Charger and 512 Bytes EEPROM

MC4181LV SERIES MASTER CLOCKS

DS1243Y 64K NV SRAM with Phantom Clock

I.A.C. - Italian Activity Contest.

Library. Summary Report

Microcontroller. BV523 32bit Microcontroller. Product specification. Jun 2011 V0.a. ByVac Page 1 of 8

Memory & Simple I/O Interfacing

Adafruit DS3231 Precision RTC Breakout

Infectious Diseases Media Kit. The Journal of. Advertising & Sales Contacts. Useful Information. jid.oxfordjournals.org

Information Extraction of Important International Conference Dates using Rules and Regular Expressions

SOUTH DAKOTA BOARD OF REGENTS. Board Work ******************************************************************************

Prop-2 Controller PN: 31102

Grid Code Planner EU Code Modifications GC0100/101/102/104

2019 Educational Courses Catalog

BatteryStats.com Page 1 of 9

DS1216 SmartWatch RAM (DS1216B/C/D/H); SmartWatch ROM (DS1216E/F)

For personal use only. Update Event & nearmap Solar

YTD OCT NOV DEC JAN FEB MAR APR MAY JUN JUL AUG SEP TOTAL

76 days Wed 8/24/16 Wed 12/7/16 Daniel Wang,Shreyas Makde,Madhavi Potluri,Roua 2 Requirements analysis 11 days Wed 8/24/16 Wed 9/7/16

SCHEDULED PROGRAMMES/COURSES APRIL 2017 MARCH 2018 (MIND KINGSTON / MANDEVILLE CAMPUSES & MONTEGO BAY)

Ambiflex MF820 OPERATOR S MANUAL

SOUTH DAKOTA BOARD OF REGENTS. Board Work ******************************************************************************

Smart Street Light Using 8052 Micro Controller

Multi-part functionality in PINES

The Microcontroller Idea Book

Nigerian Telecommunications Sector

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

Prop-1 Programming Basics

BASIC Stamp Activity Board: Features and Specifications

Transcription:

AppKit: Using the DS1302 Trickle Charge Timekeeping Chip This AppKit shows how to use the Dallas Semiconductor DS1302 Trickle Charge Timekeeping Chip with the Parallax BASIC Stamp II single-board computer or BASIC Stamp IIsx single-board computer. Codes for the BASIC Stamp Ilsx are included on the media that came in this kit. Description The DS1302 is a real-time clock / calendar with 31 bytes of static RAM. The real time clock counts seconds, minutes, hours, date of the month, month, day of the week, and year with leap year compensation. The DS1302 requires 2.5 5.5 volt full operation, and uses less than 300 na at 2.5 volts. The DS1302 communicates with a microcontroller such as Stamp through a three-wire serial connection. A temporary connection to a controller establishes the DS1302 s time. Thereafter, the chip can operate as a stand-alone clock. This AppKit shows how to program the time into the DS1302, and then allow the clock to operate independently while updating time to the BASIC Stamp. The DS1302 has dual power supply pins for primary and backup, the latter which may be powered by a super cap input or rechargeable battery. The projects relies on the chip s primary power supply input (VCC2). Hardware interface The DS1302 interfaces with controllers through a three-wire connection, consisting of a serial clock (SCLK) for data input, input/output line (I/O) for connection to the clock input, and reset (RST) for turning on control logic which accesses the shift register ad provides a method of terminating either single byte or multiple byte data transfer. The power supply pin (VCC2) and ground (GND) may be connected to the Stamps +5V and ground, respectively see figure 1.0. The DS1302 s X1 and X2 pins are connected to the leads of the 32.768 khz crystal. 1 The figure 1.0 shows how to connect the DS1302 to the Stamp for a demo program which programs the time into the chip, and may then be modified to debug the time to your PC screen. 1 The DS1302 chip (part #251-03230 priced at $6.00 for quantity one) and 32.768 khz crystals (part #251-03230 priced at $3.00 quantity one) may also be ordered individually from Parallax. pictech@parallainc.com stamptech@parallaxinc.com Page 1

The figure 1.1 shows how to connect the DS1302 to the Stamp for demo program DS1302_3 which programs the time into the chip, and will allow the user to setup the charging circuit that is built on the Ds1302. NOTE: USE ONLY SUPER CAPS OR NICKEL-CADMUIM BATTERIES. Software interface From a software standpoint, using the DS1302 requires only a few steps: (1) Identify clock starting time using different variable time registers. (2) Reset the chip and send it an instruction telling it the starting time. (3) Read the time from the chip and debug it to the PC. (4) Deactivate RST after each step by taking it low. The program listings and data sheets show these processes in detail. Tips for using the DS1302 If you are going to use a capacitor or rechargeable battery to operate the chip. You will power the chip on the power supply pin (VCC2). Connect VCC1 to a the + lead of the capacitor/ rechargeable battery, and connect the negative lead of the capacitor/ rechargeable battery to ground. In software you will set the number of diodes and amount of resistance you need see code DS1302_3. The DS1302 charges the capacitor/ rechargeable battery at the state you set. Why the power is removed the capacitor/ rechargeable battery will power the DS1302. Depending on the size of the capacitor/ rechargeable battery the charge could last for a few days. Use the DS1302 s RAM as extra storage space for the Stamp. The 31 bytes could be used for variable storage, and with the cap circuit described above this could be battery backed-up RAM (though it s not non-volatile). The DS1302 s clock calculates leap years up the year 2100. In order to make this work you must set the day of the week properly to handle the date compensation. pictech@parallainc.com stamptech@parallaxinc.com Page 2

Solder the crystal leads very close to the DS1302 the chip since any additional lead capacitance will change the timing and make the clock either fast or slow. Always use either of the two crystals recommended by Dallas in the attached data sheet. BASIC Stamp II (BS2-IC) Program Listing #1 '*************************************************************************** '* Title: DS1302_1.BS2 Author: Jeff A Martin Date: 5/18/98 * '* * '* Description: This BASIC Stamp II program interfaces to the Dallas Semi. * '* DS1302 Real Time Clock (RTC) chip. The date and time is * '* read and displayed in long and short formats on the debug * '* screen. * '* * '* Notes: This program can be modified to fit into a smaller code space. * '* It is not written as compact as possible to make it more readable * '* and to demonstrate all the useful functions of the chip. * '* The DS1302 features seconds, minutes, hours (AM/PM-12/24 modes), * '* date of month, month, day of week and year time-keeping with * '* leap year compensation valid up to 2100. Scratchpad RAM memory * '* (31 bytes), single-byte and multi-byte reads and writes, software * '* clock-halt, software write-protection, trickle charge and * '* operation down to 2.0 volts @ 300 na are other notable features. * '*************************************************************************** 'Define I/O pins and RTC variables Clk CON 0 Dta CON 1 RTCCS CON 2 RTCCmd VAR BYTE Value VAR BYTE Seconds VAR BYTE Minutes VAR BYTE Hours VAR BYTE Date VAR BYTE Month VAR BYTE Day VAR BYTE Year VAR BYTE Idx VAR BYTE 'Define RTC Command Constants SecReg CON %00000 MinReg CON %00001 HrsReg CON %00010 DateReg CON %00011 MonReg CON %00100 DayReg CON %00101 pictech@parallainc.com stamptech@parallaxinc.com Page 3

YrReg CON %00110 CtrlReg CON %00111 TChgReg CON %01000 BrstReg CON %11111 'Define Days-Of-Week, Months and AM/PM text. 'All text is stored in EEPROM with a binary 0 as the end-of-text character Sun DATA "Sun",0 Mon DATA "Mon",0 Tue DATA "Tues",0 Wed DATA "Wednes",0 Thu DATA "Thurs",0 Fri DATA "Fri",0 Sat DATA "Satur",0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dcm AM PM DATA "January",0 DATA "February",0 DATA "March",0 DATA "April",0 DATA "May",0 DATA "June",0 DATA "July",0 DATA "August",0 DATA "September",0 DATA "October",0 DATA "November",0 DATA "December",0 DATA " AM",0 DATA " PM",0 'Set I/O pin states and directions OUTS = %0000000000000000 DIRS = %0000000000000111 'All logic low 'I/O 0,1 and 2 are output, rest are input Initialize: 'Set Time and Date to 05/18/98-3:00 PM 'NOTE: Date must be set only once for every power-up of DS1302 chip. Day = $02 'Monday Month = $05 'May Date = $18 '18th Year = $98 '1998 Hours = $15 '3:00 PM (in 24-hour mode) Minutes = $00 Seconds = $00 GOSUB SetTimeAndDate Loop: 'Read out all date and time values and display them in two formats on pictech@parallainc.com stamptech@parallaxinc.com Page 4

'the debug screen. GOSUB ReadRTCBurst DEBUG HOME,"LONG FORMAT DATE AND TIME:",CR GOSUB PrintLongDate GOSUB Print12HourTime DEBUG CR,CR,"SHORT FORMAT DATE AND TIME:",CR GOSUB PrintShortDate GOSUB Print24HourTime GOTO Loop '==================== DS1302 Real-Time Clock Subroutines =================== PrintLongDate: 'Print long date format on debug screen LOOKUP Day-1,[Sun,Mon,Tue,Wed,Thu,Fri,Sat],Idx GOSUB PrintIt DEBUG "day, " LOOKUP Month-1,[Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dcm],Idx GOSUB PrintIt 'NOTE: The following line prints the proper 4-digit year for the years '1990 through 2089 DEBUG " ",HEX2 Date,", ",DEC2 20-(Year/90),HEX2 Year, CR PrintShortDate: 'Print short date format on debug screen DEBUG HEX2 Month,"/",HEX2 Date,"/",HEX2 Year, CR Print12HourTime: 'Print 12-hour time format on debug screen 'NOTE: The DS1302 has 12 and 24 hour time-keeping modes (bit 7 of HrsReg 'sets 12/24 mode and bit 5 indicates AM/PM or 20+ hours). For purposes 'of this example, we're using 24 hour mode only, and converting it to '12-hour in the next two lines below. DEBUG DEC2 12-(24-(Hours.HIGHNIB*10+Hours.LOWNIB)//12),":",HEX2 Minutes,":",HEX2 Seconds LOOKUP Hours/$12,[AM,PM],Idx GOSUB PrintIt Print24HourTime: 'Print 24-hour time format on debug screen DEBUG HEX2 Hours,":",HEX2 Minutes,":",HEX2 Seconds PrintIt: 'Prints zero (0) terminated text from EEPROM READ Idx,Value 'Get next character IF Value = 0 THEN Finished 'Make sure it's not a binary 0 pictech@parallainc.com stamptech@parallaxinc.com Page 5

DEBUG Value Idx = Idx + 1 GOTO PrintIt Finished: 'Display it on screen WriteRTCRAM: 'Write to DS1302 RAM Register HIGH RTCCS SHIFTOUT Dta, Clk, LSBFIRST, [%0\1,RTCCmd\5,%11\2,Value] LOW RTCCS WriteRTC: 'Write to DS1302 HIGH RTCCS SHIFTOUT Dta, Clk, LSBFIRST, [%0\1,RTCCmd\5,%10\2,Value] LOW RTCCS ReadRTCBurst: 'Read all time-keeping registers in one burst HIGH RTCCS SHIFTOUT DTA, Clk, LSBFIRST, [%1\1,BrstReg\5,%10\2] SHIFTIN DTA, Clk, LSBPRE, [Seconds,Minutes,Hours,Date,Month,Day,Year] LOW RTCCS ReadRTCRAM: 'Read DS1302 RAM Register HIGH RTCCS SHIFTOUT DTA, Clk, LSBFIRST, [%1\1,RTCCmd\5,%11\2] SHIFTIN DTA, Clk, LSBPRE, [Value] LOW RTCCS SetTimeAndDate: 'Write time values into all time-keeping registers, being sure to clear 'the write-protect bit in CtrlReg before the write, and set the 'write-protect bit after the write FOR Idx = 0 TO 8 LOOKUP Idx,[0,Seconds,Minutes,Hours,Date,Month,Day,Year,128],Value LOOKUP Idx,[CtrlReg, SecReg, MinReg, HrsReg, DateReg, MonReg, DayReg, YrReg, CtrlReg],RTCCmd NEXT pictech@parallainc.com stamptech@parallaxinc.com Page 6

BASIC Stamp II (BS2-IC) Program Listing #2 '*************************************************************************** '* Title: DS1302_2.BS2 Author: Jeff A Martin Date: 5/18/98 * '* * '* Description: Shortened version of DS1302_1.BS2. * '* *'*************************************************************************** DATA (49) RTCCmd VAR BYTE Clk CON 0 Dta CON 1 RTCReset CON 2 Temp VAR BYTE Seconds VAR BYTE Minutes VAR BYTE Hours VAR BYTE Date VAR BYTE Month VAR BYTE Year VAR BYTE I VAR BYTE 'Define Constants SecReg CON %00000 MinReg CON %00001 HrsReg CON %00010 DateReg CON %00011 MonReg CON %00100 YrReg CON %00110 CtrlReg CON %00111 BrstReg CON %11111 DIRS = %0000000000111111 OUTS = %0000000000000000 ' Clear Write Protect bit in control register Temp = $10 RTCCmd = CtrlReg Temp = $98 RTCCmd = YrReg Temp = $08 RTCCmd = MonReg Temp = $27 RTCCmd = DateReg pictech@parallainc.com stamptech@parallaxinc.com Page 7

Temp = $48 RTCCmd = MinReg Temp = $00 RTCCmd = SecReg Temp = $80 RTCCmd = CtrlReg Loop: GOSUB ReadRTCBurst DEBUG HOME,DEC Hours.HIGHNIB,DEC Hours.LOWNIB,":",DEC Minutes.HIGHNIB DEBUG DEC Minutes.LOWNIB,":",DEC Seconds.HIGHNIB,DEC Seconds.LOWNIB DEBUG " ",DEC Month.HIGHNIB,DEC Month.LOWNIB,"/" DEBUG DEC Date.HIGHNIB, DEC Date.LOWNIB,"/",DEC Year.HIGHNIB, DEC Year.LOWNIB,CR GOTO Loop WriteRTCRAM: 'Write to DS1202 RTC SHIFTOUT Dta, Clk, LSBFIRST, [%0\1,RTCCmd\5,%11\2,Temp] WriteRTC: 'Write to DS1202 RTC SHIFTOUT Dta, Clk, LSBFIRST, [%0\1,RTCCmd\5,%10\2,Temp] ReadRTCBurst: SHIFTOUT DTA, Clk, LSBFIRST, [%1\1,BrstReg\5,%10\2] SHIFTIN DTA, Clk, LSBPRE, [Seconds,Minutes,Hours,Date,Month,Year,Year] ReadRTCRAM: SHIFTOUT DTA, Clk, LSBFIRST, [%1\1,RTCCmd\5,%11\2] SHIFTIN DTA, Clk, LSBPRE, [Temp] pictech@parallainc.com stamptech@parallaxinc.com Page 8

'{$Stamp Bs2} 'BASIC Stamp II (BS2-IC) Program Listing #3 '*************************************************************************************************************************** '* Title: DS1302_3.BS2 Author: Stephen Swanson Date: 1/11/99 * '* * '* Description: Trickle Charge timer enabled version of DS1302_2.BS2. * '* * '*************************************************************************************************************************** DATA (49) RTCCmd VAR BYTE Clk CON 0 Dta CON 1 RTCReset CON 2 Temp VAR BYTE Seconds VAR BYTE Minutes VAR BYTE Hours VAR BYTE Date VAR BYTE Month VAR BYTE Year VAR BYTE I VAR BYTE 'Define Constants SecReg CON %00000 MinReg CON %00001 HrsReg CON %00010 DateReg CON %00011 MonReg CON %00100 YrReg CON %00110 CtrlReg CON %00111 BrstReg CON %11111 Tric CON %10010000 'Trickle time charger settings OFF CON %11110000 'turns off trickle charge D1R1 CON %10100101 '1 diode 1 resistor D1R2 CON %10100110 '1 diode 2 resistor D1R3 CON %10100111 '1 diode 3 resistor D2R1 CON %10101001 '2 diode 1 resistor D2R2 CON %10101010 '2 diode 2 resistor D2R3 CON %10101011 '2 diode 3 resistor DIRS = %0000000000111111 OUTS = %0000000000000000 ' Clear Write Protect bit in control register Temp = $10 RTCCmd = CtrlReg pictech@parallainc.com stamptech@parallaxinc.com Page 9

Temp = $98 RTCCmd = YrReg Temp = $08 RTCCmd = MonReg Temp = $27 RTCCmd = DateReg Temp = $48 RTCCmd = MinReg Temp = $00 RTCCmd = SecReg ' trickle timer settings Temp = off 'changes this variable to off or the setting that you want the ds1302 to charge at see data sheet RTCCmd = TRIC GOSUB trick Temp = $80 RTCCmd = CtrlReg Loop: GOSUB ReadRTCBurst DEBUG HOME,DEC Hours.HIGHNIB,DEC Hours.LOWNIB,":",DEC Minutes.HIGHNIB DEBUG DEC Minutes.LOWNIB,":",DEC Seconds.HIGHNIB,DEC Seconds.LOWNIB DEBUG " ",DEC Month.HIGHNIB,DEC Month.LOWNIB,"/" DEBUG DEC Date.HIGHNIB, DEC Date.LOWNIB,"/",DEC Year.HIGHNIB, DEC Year.LOWNIB,CR GOTO Loop WriteRTCRAM: 'Write to DS1202 RTC SHIFTOUT Dta, Clk, LSBFIRST, [%0\1,RTCCmd\5,%11\2,Temp] WriteRTC: 'Write to DS1202 RTC SHIFTOUT Dta, Clk, LSBFIRST, [%0\1,RTCCmd\5,%10\2,Temp] pictech@parallainc.com stamptech@parallaxinc.com Page 10

Trick: HIGH rtcreset SHIFTOUT Dta, Clk, LSBFIRST, [RTCCmd,Temp] return ReadRTCBurst: SHIFTOUT DTA, Clk, LSBFIRST, [%1\1,BrstReg\5,%10\2] SHIFTIN DTA, Clk, LSBPRE, [Seconds,Minutes,Hours,Date,Month,Year,Year] ReadRTCRAM: SHIFTOUT DTA, Clk, LSBFIRST, [%1\1,RTCCmd\5,%11\2] SHIFTIN DTA, Clk, LSBPRE, [Temp] pictech@parallainc.com stamptech@parallaxinc.com Page 11