| Home | Products | Prices | Site Map | Order | Contact | What's New | Books | Free Files | Links | FAQ |
| Back to Free
Files - (Don's Download Dungeon) |
Basic Stamp 2. Program 1: To DS-1202 by Bob
Martin.
Basic Stamp 2. Program 2: To DS-1202 by David
Baker.
Basic Stamp 2. Program 3: To NJU-6355 by Craig
Simmonds.
Basic Stamp 2. Program 4: To PCF8593P by Dragan
Kujovic.
FED Basic Program: To DS-1302 by Mick Gulovsen.
PIC MicroChip Code: To DS-1202 by Mark Sullivan.
PIC MicroChip Code: To DS-1302 by John Sanderson.
DS-1202 problems: by Llewellyn Griffiths.
Interfacing the DS5000 to the DS1307 By Dallas
Semiconductor
Check Additional Data on DS-1202/1302
DS1302 from port d on an 8535 (SIMM100), written in
asm using AVRA assembler. by Ingmar Meins
Introduction
You can easily add a real time clock to most micros using only 3 signals. With careful selection, some pins can be shared with other devices.
I have put together a clock/crystal combination that takes a bit of beating. The Dallas-Semiconductor DS1302 is an 8 pin DIP Trickle Charge Time Keeping Chip that uses a 32.768kHz crystal. This crystal should have a load capacitance of 6pf for reasonable accuracy.
The DS1302 is an enhanced version of the DS1202. Pin 1 is now used to connect to an optional trickle charge for battery or supercap input. It also has 31 bytes of RAM, an extra 7 bytes over the DS1202.
DS1302 in 8 pin DIP.
32.768kHz Crystal to suit.
Check RTC Prices
Beware! These crystals are small, about the width of a very small tooth-pick and about 1/4" long, so don't loose it.
As a working example, I have included in this file some programs I found on the Internet Stamp List, which may be enough get you started towards a result. And if you do get a result, please feedback is nice.
I also have added the code that my friend Mick Gulovsen did using FED Basic and the DS-1302.
The example has some additional overhead for speaker and LCD operation that needs to be weeded out and it's for the DS1202, so it doesn't take advantage of the DS1302 features, but should work straight up, as both devices are code and pin compatible with upward expansion for the DS1302.
From rtm@newton.apple.com Fri Dec 8 17:50:41 1995Back to the Table of Contents
Date: Sun, 3 Dec 1995 14:31:55 -0800
From: Bob MartinReply to: stamps@parallaxinc.com To: NUNESJ@aol.com, stamps@parallaxinc.com Subject: [STAMPS] Stamp II - time and date Here's the source code for a simple LCD clock using the Stamp II and the dallas semiconductor DS1202 clock chip. The Dallas chip is available mail order from JDR Microdevices. You can get dallas semi spec sheets from their web server at http://www.dalsemi.com Cheers- Bob Martin ' Bob's Clock for the Stamp II - DS120S ' Uses: ' Dallas Semiconductor DS1202 clock chip ' Optrex DMC-16207 16x2 LCD ' Cheezy 2.5" speaker ' Last modified: ' 12/3/95 RTM 1200 ' Stamp II I/O pins: ' 0 LCD 11 8 DS1202 5 rst* ' 1 LCD 12 9 DS1202 6 i/o ' 2 LCD 13 10 DS1202 7 clk ' 3 LCD 14 11 ' 4 LCD 4 12 ' 5 LCD 6 13 cheezy speaker thru 10uf ' 6 14 ' 7 15 ' I/O definitions lcdrs con 4 ' LCD register select lcde con 5 ' LCD enable pin lcdbl con 6 ' LCD backlight control spkr con 13 ' for a cheezy speaker ' Dallas Semiconductor DS1202 clock chip dsrst con 8 ' rst* pin 5 (normally low w 47k) dsio con 9 ' i/o pin 6 dsclk con 10 ' sclk pin 7 (pull low w 47k) ' Constants for addressing the DS1202 clock chip dssec con $80 ' seconds register dsmin con $82 ' minutes register dshr con $84 ' hours register dsdate con $86 ' date dsmon con $88 ' month dsday con $8A ' day of week, 1=sunday dsyear con $8C ' year dsctl con $8E ' control register dsram con $C0 ' start of ram (24 bytes) ' constants for lcd commands posdate con $80 | 40 ' position to line 2 postime con $80 | 4 ' time hh:mm:ss starts here possecs con $80 | 10 ' seconds (ss) starts here ' dsis is the initialisation string for the clock. ' consists of pairs . Note the first entries should
' write enable the clock and then stop it running, and the
' last entries should restart and write protect it!
dsis data dsctl,0 ' write enable the clock
data dssec,$80 ' stop clock, set secs to 00
data dsyear,$95 ' year 1995
data dsday,6 ' friday
data dsmon,$12 ' december
data dsdate,$1 ' 1
data dshr,$20 ' 24 hour clock, 2000
data dsmin,$04 ' 04 minutes
data dssec,$00 ' start the clock running again
data dsctl,$80 ' write protect the clock
data 0,0 ' end of the list
' Day of week text (abbreviations) Each entry is 3 bytes
' plus a zero termination character. Sunday=1
dowt data "RTM",0,"Sun",0,"Mon",0,"Tue",0
data "Wed",0,"Thu",0,"Fri",0,"Sat",0
' variables used in the program
' these variables are copies of the DS1202 registers, and are
' updated as bytes- so you can't change dow to a nybble!
secs var byte ' bcd seconds
mm var byte ' bcd minutes
hh var byte ' bcd hours
date var byte ' bcd day of the month
month var byte ' bcd month
dow var byte ' day of the week, Sunday = 1
year var byte ' bcd year
' general stuff
i var word ' computational temp
dsaddr var byte ' ds1202 register address we're whacking
dsdata var byte ' and the data going back and forth
lcdchr var byte ' character sent to LCD
bcd var byte ' bcd data sent to LCD
' Start here.
low dsrst ' make sure the reset* line is low
low dsclk ' same with the clock line
nap 2 ' wait for the world to settle
gosub lcdinit ' set up the display
' gosub dsinit ' set up the clock
' gosub dsdbg
' Read data from the clock and display date and time
gosub dsrd7 ' update time variables
gosub tdisplay ' update display
' nap 6 ' snooze a bit
' Top of the clock loop. We wait for the seconds to change,
' napping in low power mode between checking the clock
clock1: nap 2 ' delay at low power a while
dsaddr = dssec ' look at seconds register
gosub dsread ' read seconds register
if dsdata = secs then clock1 ' wait if no change
clock2: secs = dsdata ' update our number
' tick-tock stuff with the speaker - tone flips between 400 and 800 hz
' based on the low bit of the seconds
freqout spkr,30,400+(400*(secs & $01))
' When the seconds change, we only rewrite the seconds portion of
' the display.
clock4: if secs = 0 then clock5 ' a minute has passed
lcdchr = possecs
bcd = secs
gosub wrcb ' put out seconds
' debug HEX secs,cr
goto clock1 ' loop
' secs=0, a minute has passed. update vars and rewrite whole display
clock5: gosub dsrd7 ' block read all 7 bytes
gosub tdisplay ' display date and time
' debug HEX2 hh,":",HEX2 mm,":00",cr
clock6: if mm <> 0 then clock1 ' scram if not an hour
' We have reached an hour! Do something exciting!
clock7:
' Daylight savings time. I don't mind having to reset mechanical
' clocks when we go on and off dst, but if the thing has a calendar
' in it, it should be able to do daylight savings adjustments itself.
if (hh=2) & (dow=1) & ((month=4)|(month=$10)) then ckdst
goto clock1 ' loop around
' Check for dalight savings time. We already know it is 2am on a
' Sunday in April or October- do the rest of the test and diddle
' the time if required.
ckdst: if (month=10) & (date>$24) then ckdstf ' last Sun in Oct.
if (month=4) & (date<8) then ckdsts ' first Sun in April
goto clock1 ' not time to correct.
' Fall back - last Sunday in October
ckdstf: hh=1
goto ckdstu ' 1 AM and update it
' Spring forward - first Sunday in April
ckdsts: hh=3 ' 3 AM
ckdstu: gosub dsenab ' write enable the clock
dsdata=hh
dsaddr=dshr
gosub dswrite ' jam in new hour
gosub dswp ' write protect the clock
goto clock1 ' loop
' tdisplay put hh:mm:ss on line 1 of the display,
' Put dow dd/mm/yy on the LCD in line 2, character position 40.
' The end of this routine shows another space saving trick- replacing
' a gosub xxxx/return sequence with goto xxxx.
tdisplay:
if mm>0 then tdisp0
lcdchr = $1
gosub lcdcmd ' clear display once per hour
pause 1
tdisp0: lcdchr = postime ' put hh:mm:ss on display here
bcd = hh ' so it lines up with the date
gosub wrcb ' displayed on line 2
lcdchr = ":" ' hh :
bcd = mm
gosub wrsb ' hh:mm
bcd = secs
gosub wrsb ' hh:mm:ss
i = 4*dow ' index into day of week text
lcdchr= posdate ' this is where line 2 starts
gosub lcdcmd ' position LCD cursor
tdisp1: read dowt+i,lcdchr ' get day of week text
if lcdchr = 0 then tdisp2
gosub wrlcd ' put out that character
i = i + 1
goto tdisp1 ' loop until 00 byte hit
tdisp2: lcdchr = " "
bcd = month
gosub wrsb ' dow mm
lcdchr = "/"
bcd = date
gosub wrsb ' dow mm/dd
bcd = year
goto wrsb ' dow mm/dd/yy and return
' debug dump the contents of clock registers- about 48 bytes
'dsdbg: for i=0 to 7
' dsaddr = $80 | (i+i) ' make a register address
' gosub dsread ' read its contents
' debug "reg ",HEX i," = ",HEX dsdata,cr
' next
' return
' ram test - uses first ram location
'
' ram test pattern - walking 1 followed by walking 0
'
'dsrt data 1,2,4,8,$10,$20,$40,$80
' data $7F,$BF,$DF,$EF,$F7,$FB,$FD,$FE,0
'
'ramtest:
' gosub dsenab ' write enable ram
' i = 0 ' index into rt data
' dsaddr = dsram ' use this loc
'rt1: read dsrt+i,dsdata
' if dsdata = 0 then rtn ' split when 00 hit
' hh=dsdata ' save it off
' gosub dswrite ' write it
' gosub dsread
' debug "wrote ",HEX hh," read ",HEX dsdata,cr
' pause 700
' i = i + 1
' goto rt1
' set up the clock for a reasonable starting time
dsinit: i = 0 ' index into initialization data
dsi0: read dsis + i,dsaddr ' get address to stuff
read dsis + 1 + i,dsdata ' and data to put there
if dsaddr = 0 then rtn ' exit when 00 hit
gosub dswrite ' write data to the clock
i = i+2 ' bump the pointer
goto dsi0 ' loop over the list
' read and write subroutines. uses dsaddr and dsdata
' specifying \8 doesn't cost anything in terms of memory use- even
' though it's the default, it's a good reminder to have it present...
dsread:
dsaddr = dsaddr | 1 ' make sure it's a read!
high dsrst ' start read cycle
shiftout dsio,dsclk,lsbfirst,[dsaddr\8] ' send address
shiftin dsio,dsclk,lsbpre,[dsdata\8] ' get the data
low dsrst ' end read cycle
return
' write enable and write protect the clock.
' clobbers dsaddr and dsdata
dsenab: dsdata = 0 ' 0 to write enable
goto dswp0 ' return through write protect code
dswp: dsdata = $80 ' set the bit to write protect
dswp0: dsaddr = dsctl ' control register, fall into dswrite
dswrite:
dsaddr = dsaddr & $FE ' make sure a write
high dsrst ' start cycle
shiftout dsio,dsclk,lsbfirst,[dsaddr\8] ' send address
shiftout dsio,dsclk,lsbfirst,[dsdata\8] ' send data
low dsrst ' end cycle
return
' block read clock vars- unfortunately, shiftin only does
' 16 bits at a shot, so I can't do all 56 bits at once
dsrd7: dsaddr = $BF ' clock burst
high dsrst ' start the cycle
shiftout dsio,dsclk,lsbfirst,[dsaddr\8]
shiftin dsio,dsclk,lsbpre,[secs\8] ' 8 for seconds
shiftin dsio,dsclk,lsbpre,[mm\8]
shiftin dsio,dsclk,lsbpre,[hh\8]
shiftin dsio,dsclk,lsbpre,[date\8]
shiftin dsio,dsclk,lsbpre,[month\8]
shiftin dsio,dsclk,lsbpre,[dow\8]
shiftin dsio,dsclk,lsbpre,[year\8] ' thru 8 for year
low dsrst
return
' LCD support routines - should work with most LCDs using the same
' controller chip. Note that these routines use "pause" and not "nap"-
' we don't want the I/O pins going hi-Z on us...
' LCD init, 4 bit mode, stamp II pins 0-5
LCDinit:
dirl = %00111111 ' lcd pins as outputs
outl = 00 ' make 'em all low
pause 200 ' 200 ms reset time for lcd!
outa = %0011 ' 8 bit mode
pulsout lcde,1
pause 5
pulsout lcde,1
pulsout lcde,1 ' this insures 8 bit mode
outa = %0010 ' now force 4 bit mode
pulsout lcde,1
lcdchr = $28 ' force 2 line mode
gosub wrlcd
lcdchr = $0C ' display on, cursor off, blink off
gosub wrlcd
lcdchr = 6 ' autoincr cursor, no shift
gosub wrlcd
lcdchr = 1 ' clear lcd
goto lcdcm0 ' exiting through common code
' Send command in lcdchr to the LCD - flip RS, send it, flip RS back.
' preserves lcdchr
' The label "rtn" on the return in this routine is used as a branch
' target in other places in the program to save code space.
lcdcmd: low lcdrs ' rs=0 for command mode
lcdcm0: gosub wrlcd
high lcdrs ' back to character mode
rtn: return
' Send character in lcdchr to the LCD. lcdchr preserved.
' Note that lcdrs, register select, is untouched.
wrlcd: outa = lcdchr >> 4 ' output high nibble
wrlcd1: pulsout lcde,1
outa = lcdchr ' low nibble
pulsout lcde,1
return
' code shortening routines - we send a separator or command followed
' by a bcd character to the display a lot. the code also relies on the
' fact that wrlcd and wrbcd use different inputs and preserve them.
wrcb: low lcdrs ' select command mode
wrsb: gosub wrlcd ' do separator in lcdchr
high lcdrs ' fall through to do bcd
' send the BCD byte in bcd to the LCD as 2 characters
' bcd preserved
wrbcd: outa = 3 ' output lcdchr as 2 bcd chars
pulsout lcde,1 ' hex 3x is a digit
outa = bcd >> 4 ' digit info for high digit
pulsout lcde,1
outa = 3 ' now do the low digit
pulsout lcde,1
outa = bcd ' low nibble
pulsout lcde,1
return
' end of the program
' More on the hardware portion:
' Power supplied through an LM2930 to220 5 volt regulator. Average
' current needed is around 5mA
' Rather than use the onboard regulator, the Stamp II is also run
' off the main 3 terminal regulator. Power for the DS1202 clock
' chip is provided through a 1N914 diode from the +5 line, and
' from a 3V lithium coin cell through another 1N914 to provide
' backup power for the clock.
' Pulldown resistors are present on the rst* and clk pins of the
' DS1202 clock chip- this precludes false clocking when the Stamp II
' I/O pins go high impedance for 18ms at the end of each nap.
' On the LCD, pins 3 and 5 of the LCD are tied low, so the LCD is
' treated as a write-only device. With some multi-line LCDs, pin 3
' may require a negative bias voltage. Even though the LCD is only 16
' characters wide, the second line at character 40.
From PIC@baker.pc.my Sat Jun 29 07:28:04 1996Back to the Table of Contents
Date: Fri, 28 Jun 1996 18:57:42 +0000
From: David BakerReply to: stamps@parallaxinc.com To: stamps@parallaxinc.com Subject: Re: [STAMPS] DS1202 & Stamp On 28 Jun 96 at 3:08, WARPEDRIVE@aol.com wrote: > Yes, excellent question.. anyone already written this interface code? I could > really use the time savings about now.. I just had a quick go today - it turned out to be very easy. The program's pretty short so I guess people won't mind if I post it here. I haven't tidied it up yet & there may be a better way to do it, but here it is: '------------------------------------------------------------------------ ' DS1202_C.BS2 ' Written by Dave Baker &nbsnbsp; 28JUN96 ' Sets the Dallas DS1202 real time clock chip to a preset time ' & enables the clock to start counting. ' Reading & writing of time done by burst programming method. CEnable con $55 ' Clock Start MinVal con $59 ' Preset value for minutes HourVal con $23 ' Preset value for hours DayVal con $31 ' Preset value for day MonthVal con $12 ' Preset value for month DCVal con $00 ' Preset value for dow - don't care YearVal con $96 ' Preset value for year RST con 10 ' Reset pin 10 IO con 9 ' IO pin 9 SCLK con 8 ' Serial clock pin 8 pauseval con 1 ' Value for pauses WEnable con $00 ' Write enable WSec con $80 ' Write to seconds register Rsec con $81 ' Read seconds register Wmin con $82 ' Write to minutes register Rmin con $83 ' Read minutes register Whour con $84 ' Write to hours register Rhour con $85 ' Read hours register Wday con $86 ' Write to days register Rday con $87 ' Read day register Wmonth con $88 ' Write to months register Rmonth con $89 ' Read month register Wyear con $8C ' Write to years register Ryear con $8D ' Read year register WCont con $8E ' Write to control register WCB con $BE ' Read clock burst RCB con $BF ' Write clock burst IOSec var word ' store register data for seconds IOMin var word ' store register data for minutes IOHour var word ' store register data for hours IODay var word ' store register data for day IOMonth var word ' store register data for month IODCare var word ' For day of week - don't care IOYear var word ' store register data for year Tmonth1 var byte Tmonth2 var byte Tmonth3 var byte IOMDec var word pause pauseval high RST ' tell 1202 that we want to write a clock burst shiftout IO,SCLK,lsbfirst,[WCB] ' read everything in a burst Shiftout IO,SCLK,lsbfirst,[Cenable,MinVal,HourVal,DayVal,MonthVal,DCVal,YearVal,Wenable] low RST loop: pause pauseval high RST ' tell 1202 that we want to read a clock burst shiftout IO,SCLK,lsbfirst,[RCB] ' read everything in a burst Shiftin IO,SCLK,lsbpre,[IOSec\8,IOMin\8,IOhour\8,IOday\8,IOmonth\8,IODcare\8,IOyear\8] low RST gosub TextMonth gosub display goto loop display: debug HEX2 IOHour,":",Hex2 IOMin,":",Hex2 IOSec," " debug HEX2 IODay," " 'debug HEX2 IOMonth, " " debug Tmonth1,Tmonth2,Tmonth3, " " debug HEX2 IOYear,cr 'pause 100 goto loop TextMonth: ' convert month from BCD to decimal value IOMDec = (IOMonth.nib1 * 10) + (IOMonth.nib0) lookup IOMDec*3,[" ","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],TMonth1 lookup IOMDec*3+1,[" ","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],TMonth2 lookup IOMDec*3+2,[" ","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],TMonth3 return '------------------------------------------------------------------------ Looks like my wordwrap messed up a couple of the lines - the shiftin, shiftout & lookup lines aren't supposed to be wrapped. That's a good start anyway. Don McKenzie has a similar program on his homepage from Bob Martin - I found it after I had already written mine. (Honest!) Actually mine uses the burst programming method which means a lot less code & is faster. Also even though Bob says shifting can only read 16 bits max I had no trouble reading in 8 bytes at a time. Dave
From: "Craig Simmons" simmons@airmail.netBack to the Table of Contents
To: stamps@parallaxinc.com
Subject: [STAMPS] Re: JRC6355ED Real Time Clock Problem
Date: Sat, 14 Dec 1996 04:21:25 -0600
Well,
I answered my own question on this one, and since it threw me for a loop
I thought I would share it with you all. It seems that you have to enable
the chip, then disable it between read cycles or the counter will never get
incremented. Makes sense, guess I just need some sleep. I have included the
code that debugs the time to the screen for those that want to use the
chip. It really has a great price compared to the EPSON, but since I
haven't used the EPSON, I can't compare. I will say that I had a devil of a
time finding information on this chip. Scott Edwards notes in the Nuts and
Volts archive were a help for schematics, and some information I found on
the PicStic had the instruction set which was invaluable. I ranting again.
The code is below. Thanks again for this group and the massive serarch
engines on the internet.
Craig Simmons
' This code is for the BS2 to read and write the time to an NJU6355ED or
JRC6355ED real time clock
' Variables
TEMP Var BYTE
ENABLE CON 13
IO CON 12
DATAPIN CON 14
CLOCKPIN CON 15
' Put it into Write Mode and Set Time
HIGH IO
HIGH ENABLE
shiftout DATAPIN,CLOCKPIN,0,[$96\8] ' Year (0-99)
shiftout DATAPIN,CLOCKPIN,0,[$12\8] ' Month (1-12)
shiftout DATAPIN,CLOCKPIN,0,[$13\8] ' Date (1-31)
shiftout DATAPIN,CLOCKPIN,0,[$06\4] ' Day of Week (1-7)
shiftout DATAPIN,CLOCKPIN,0,[$08\8] ' Hour (0-24)
shiftout DATAPIN,CLOCKPIN,0,[$54\8] ' Minute (0-60)
Low ENABLE ' (Seconds reset automatically) &nb
' Put it into Read Mode
LOW IO
' Loop to read in the time and display
GetTime:
HIGH ENABLE ' You have to have this here.
shiftin DATAPIN,CLOCKPIN,1,[temp\8]
debug hex(temp) ' Year
shiftin DATAPIN,CLOCKPIN,1,[temp\8]
debug hex(temp) ' Month
shiftin DATAPIN,CLOCKPIN,1,[temp\8]
debug hex(temp) ' Date
shiftin DATAPIN,CLOCKPIN,1,[temp\4]
debug hex(temp) ' Day of Week
shiftin DATAPIN,CLOCKPIN,1,[temp\8]
debug hex(temp) ' Hour
shiftin DATAPIN,CLOCKPIN,1,[temp\8]
debug hex(temp) ' Minute
shiftin DATAPIN,CLOCKPIN,1,[temp\8]
debug hex(temp) ' Seconds
debug cr
LOW ENABLE ' And you have to have this here.
pause 1000
GOTO GetTime
From: "Dragan Kujovic" dkujovic@EUnet.yuBack to the Table of Contents
To: "Parallax Inc. Stamps" stamps@parallaxinc.com
Subject: [STAMPS] PCF8593P Real Time Clock
Date: Tue, 17 Dec 1996 14:23:52 +0100
Respectable Colleagues,
I am currently occupied with finishing couple of mine projects which all
have RTC implemented. But in Europe is very hard to find products from USA
manufacturers, such as Dallas, JRC etc.
So, I made RTC with Philips PCF8593P which can be found all over Europe.
There is example code for day, date & time clock with daylight savings.
Might be useful for implementing in some application.
PCF8593 data and application notes can be downloaded from:
http://www.semiconductors.philips.com/
Thanks to Jeff Martin for technical support,
and
thanks to Jordan Haralampopulos for I2C subroutines.
===============================================
' ***************************************************
' PHILIPS Real Time Clock PCF8593P (I2C protocol)
' ***************************************************
' Dragan Kujovic, EMAX Electronics, December 1996.
' USED PRODUCTS:
' Parallax Basic Stamp 2
' Parallax Serial LCD ( 2 x 16 characters)
' Philips real time clock PCF8593P
' Please be noticed that these products and source code for the RTC
' are not designed for use in life support appliances, devices,
' or systems where malfunction of these products can reasonably be expected
' to result in personal injury !
' This BS2 code read data from RTC and display it on Parallax serial LCD
' PCF8593 data and application notes can be downloaded from:
' www.semiconductors.philips.com
' BS2 pin description:
' RTC clock => 10
' RTC data => 11
' RTC reset => 0
' LCD Rx => 7
RTCaddress VAR WORD ' 16-bit address
RTCaddressHigh VAR RTCaddress.HIGHBYTE ' 8 MS-bit address
RTCaddressLow VAR RTCaddress.LOWBYTE ' 8 LS-bit address
RTCtemp VAR BYTE ' Temporary variable
RTCdata VAR BYTE ' Data variable
RTCack VAR BIT &p; ' RTC acknowledge bit
RTCclockPin CON 10 ' RTC clock pi
RTCdataPin CON 11 ' RTC datin
RTCwrite CON %10100010 ' RTC Slave address write
RTCread CON %10100011 ' RTC Slave address read
ResetRTC CON %00000000 ' Status Byte Default
Second VAR BYTE Second
Second1 VAR BYTE ' 1 second
Second10 VAR BYTE ' 10 seco
Minute VAR BYTE Minute
Minute1 VAR BYTE ' 1 ute
Minute10 VAR BYTE ' 10 minu
Hour VAR BYTE &n; ' Hour
Hour1 VAR BYTE &p; ' 1 hour
Hour10 VAR BYTE 10 hours
Date VAR BYTE &n; ' Day
Date1 VAR BYTE &p; ' 1 day
Date10 VAR BYTE 10 days
Day VAR BYTE &nb ' Day
Month VAR BYTE &p; ' Month
Month1 VAR BYTE 1 month
Month10 VAR BYTE ' 10 months
Year VAR BYTE &n; ' Year
Year1 VAR BYTE &p; ' 4 years
EEprom VAR BYTE EEPROM data
N VAR BYTE  bsp; ' Universal counter
DATA "Sun","Mon","Tue","Wed","Thu","Fri","Sat"
DATA "Jan","Feb","Mar","Apr","May","Jun"
DATA "Jul","Aug","Sep","Oct","Nov","Dec"
' --------------------------------------------------------
' PCF8593 need reset only after connection to power supply
' PCF8593 hardware reset (Reset pin pull down)
' LOW 0:PAUSE 500:HIGH 0
' PCF8593 software reset (Reset all variables)
' FOR N=0 TO 15
' RTCaddressLow=N
' RTCtemp=ResetRTC
' GOSUB WriteToRTC
' NEXT
' --------------------------------------------------------
' -------------------------------------------------------------
' Set current time & date sample => Tue, 17. Dec 1996. 10:00:00
' For details consult PCF8593 file which can be downloaded from
' www.semiconductors.philips.com
' RTCaddressLow=5: ' Year, Date
' RTCtemp=%00010111: ' 1996 / 17
' GOSUB WriteToRTC
' RTCaddressLow=6: ' Month, Day
' RTCtemp=%01010010: ' 12 / Tue
' GOSUB WriteToRTC
' RTCaddressLow=4: ' Hour
' RTCtemp=%00010000: ' 10
' GOSUB WriteToRTC
' RTCaddressLow=3: ' Minute
' RTCtemp=%00000000: ' 0
' GOSUB WriteToRTC
' -------------------------------------------------------------
SEROUT 7,396,[12," "] ' LCD reset
FREQOUT 14,100,3000 ' Make a "beep"
RTC:
' Day
RTCaddressLow=6
RTCtemp=0
GOSUB ReadFromRTC
IF RTCtemp.BIT7=%0 AND RTCtemp.BIT6=%0 AND RTCtemp.BIT5=%0 THEN D0
IF RTCtemp.BIT7=%0 AND RTCtemp.BIT6=%0 AND RTCtemp.BIT5=%1 THEN D1
IF RTCtemp.BIT7=%0 AND RTCtemp.BIT6=%1 AND RTCtemp.BIT5=%0 THEN D2
IF RTCtemp.BIT7=%0 AND RTCtemp.BIT6=%1 AND RTCtemp.BIT5=%1 THEN D3
IF RTCtemp.BIT7=%1 AND RTCtemp.BIT6=%0 AND RTCtemp.BIT5=%0 THEN D4
IF RTCtemp.BIT7=%1 AND RTCtemp.BIT6=%0 AND RTCtemp.BIT5=%1 THEN D5
IF RTCtemp.BIT7=%1 AND RTCtemp.BIT6=%1 AND RTCtemp.BIT5=%0 THEN D6
Days:
' Date
RTCaddressLow=5
RTCtemp=0:Date=0:Date1=0:Date10=0
GOSUB ReadFromRTC
IF RTCtemp.BIT5=%1 AND RTCtemp.BIT4=%1 THEN D30
IF RTCtemp.BIT5=%1 AND RTCtemp.BIT4=%0 THEN D20
IF RTCtemp.BIT5=%0 AND RTCtemp.BIT4=%1 THEN D10
Dates:
Date1=RTCtemp.LOWNIB
Date=Date10+Date1
' Month
RTCaddressLow=6
RTCtemp=0:Month=0:Month1=0:Month10=0
GOSUB ReadFromRTC
IF RTCtemp.BIT4=%1 THEN M10
Months:
Month1=RTCtemp.LOWNIB
Month=Month10+Month1
' Year
RTCaddressLow=5
RTCtemp=0:Year=0:Year1=0
GOSUB ReadFromRTC
IF RTCtemp.BIT7=%1 AND RTCtemp.BIT6=%1 THEN Y3
IF RTCtemp.BIT7=%1 AND RTCtemp.BIT6=%0 THEN Y2
IF RTCtemp.BIT7=%0 AND RTCtemp.BIT6=%1 THEN Y1
Years:
Year=Year1+96
' Hour
RTCaddressLow=4
RTCtemp=0:Hour=0:Hour1=0:Hour10=0
GOSUB ReadFromRTC
IF RTCtemp.BIT5=%1 THEN H20
IF RTCtemp.BIT4=%1 THEN H10
Hours:
Hour1=RTCtemp.LOWNIB
Hour=Hour10+Hour1
' Minute
RTCaddressLow=3
RTCtemp=0:Minute=0:Minute1=0:Minute10=0
GOSUB ReadFromRTC
Minutes:
Minute10=RTCtemp.HIGHNIB*10
Minute1=RTCtemp.LOWNIB
Minute=Minute10+Minute1
' Second
RTCaddressLow=2
RTCtemp=0:Second=0:Second1=0:Second10=0
GOSUB ReadFromRTC
Seconds:
Second10=RTCtemp.HIGHNIB*10
Second1=RTCtemp.LOWNIB
Second=Second10+Second1
' Daylight savings time
' Last Saturday/Sunday weekend in April and October at 2 AM
READ $03E,EEprom
IF Hour=2 AND Day=0 AND Month=4 AND Date>24 AND EEprom=0 THEN AddHour
READ $03F,EEprom
IF Hour=2 AND Day=0 AND Month=10 AND Date>24 AND EEProm=0 THEN SubtractHour
FOR N=0 TO 2
READ Day*3+N,EEprom
SEROUT 7,396,[27,N,EEprom]
NEXT
SEROUT 7,396,[27,3,", ",dec Date]
SEROUT 7,396,[27,7,"."]
FOR N=0 TO 2
READ Month+6*3+N,EEprom
SEROUT 7,396,[27,N+9,EEprom]
NEXT
SEROUT 7,396,[27,13,dec Year,"."]
SEROUT 7,396,[27,20,dec Hour]
SEROUT 7,396,[27,22,":"]
SEROUT 7,396,[27,23,dec Minute]
SEROUT 7,396,[27,25,":"]
SEROUT 7,396,[27,26,dec Second," "]
GOTO RTC
D0:Day=0:GOTO Days
D1:Day=1:GOTO Days
D2:Day=2:GOTO Days
D3:Day=3:GOTO Days
D4:Day=4:GOTO Days
D5:Day=5:GOTO Days
D6:Day=6:GOTO Days
D10:Date10=10:GOTO Dates
D20:Date10=20:GOTO Dates
D30:Date10=30:GOTO Dates
M10:Month10=10:GOTO Months
Y1:Year1=1:GOTO Years
Y2:Year1=2:GOTO Years
Y3:Year1=3:GOTO Years
H10:Hour10=10:GOTO Hours
H20:Hour10=20:GOTO Hours
AddHour:
RTCaddressLow=4
RTCtemp=%00000011: ' Set Hour to 3 AM
GOSUB WriteToRTC
WRITE $03E,1
WRITE $03F,0
GOTO RTC
SubtractHour:
RTCaddressLow=4
RTCtemp=%00000001: ' Set Hour to 1 AM
GOSUB WriteToRTC
WRITE $03F,1
WRITE $03E,0
GOTO RTC
' *************************************************************************
' Basic Stamp II / I2C SUBROUTINES
WriteToRTC:
GOSUB StartRTC: ' Send START sequence to RTC
RTCdata=RTCwrite: ' Slave address with WRITE command
GOSUB TxByte: ' Send slave address with WRITE command to RTC
GOSUB RxACK: ' Receive ACK signal from RTC
RTCdata=RTCaddressLow: ' RTC writting address determination
GOSUB TxByte: ' Send writting address to RTC
GOSUB RxACK: ' Receive ACK signal from RTC
RTCdata=RTCtemp: ' Write data from temporary variable
GOSUB TxByte: ' Send byte to determinated address in RTC
GOSUB RxACK: ' Receive ACK signal from RTC
GOSUB StopRTC: ' Send STOP sequence to RTC
RETURN
ReadFromRTC:
GOSUB StartRTC: ' Send START sequence to RTC
RTCdata=RTCwrite: ' Slave address with WRITE command
GOSUB TxByte: ' Send slave address with WRITE command to RTC
GOSUB RxACK: ' Receive ACK signal from RTC
RTCdata=RTCaddressLow: ' RTC writting address determination
GOSUB TxByte: ' Send writting address to RTC
GOSUB RxACK: ' Receive ACK signal from RTC
GOSUB StartRTC: ' Send again START sequence to RTC
RTCdata=RTCread: ' Slave address with READ command
GOSUB TxByte: ' Send slave address with READ command to RTC
GOSUB RxACK: ' Receive ACK signal from RTC
GOSUB RxByte: ' Read data from RTC-a
RTCtemp=RTCdata: ' Place data from RTC in RTCtemp variable
GOSUB StopRTC: ' Send STOP sequence to RTC
RETURN
StartRTC:
HIGH RTCdataPin: ' RTC data pin high
HIGH RTCclockPin: ' RTC clock pin high
LOW RTCdataPin: ' RTC data pin low
RETURN
StopRTC:
LOW RTCdataPin: ' RTC data pin low
HIGH RTCclockPin: ' RTC clock pin high
HIGH RTCdataPin: ' RTC data pin high
RETURN
TxByte:
SHIFTOUT RTCdataPin,RTCclockPin,1,[RTCdata] ' Send byte to RTC
RETURN
RxByte:
SHIFTIN RTCdataPin,RTCclockPin,0,[RTCdata] ' Receive byte from RTC
RETURN
TxACK:
SHIFTOUT RTCdataPin,RTCclockPin,1,[%0\1] ' Send ACK bit to RTC
RETURN
RxACK:
SHIFTIN RTCdataPin,RTCclockPin,0,[RTCack\1] ' Receive ACK bit from RTC
RETURN
' *************************************************************************
END
===============================================
With best regards,
Dipl. Ing. Dragan Kujovic
EMAX Electronics
Tel. ++381 11 185-188
Fax ++381 11 185-199
E-mail: dkujovic@EUnet.yu
; This program is for the 16c57 FED BasicBack to Top of Page
; it drives a 16x2 LCD display on port B and DS1302 on port C
;
; On 1st power-up the CH (clock hold) flag will be set and will
; have to be reset before the clock can count enter your initial time
; below in inithr & initmin variables.
;
; To reset clock after being set the first time just remove power
; and one of the backup batteries connected to VCC1 of the DS1302
;
; RTC chip is wired as follows:
;
; c5=RST, c6=SCLK, c7=I/O
;
; Mick Gulovsen 20-Apr-96 bigmik@blaze.net.au
typesub gettime() ; get time
typesub disptime() ; display time
typesub selreg(data) ; select register
typesub clkwr(data) ; clock data into RTC
typesub clkwr1(data) ; "
typesub initclk()
typefunc clkrd() ; clock data out of RTC
temp=0
hr=0
hrx=0
min=0
minx=0
sec=0
secx=0
reg=0
data=0
begin:
; initial start time here
;
; format as follows
;
; 0xxx yyyy where
;
;xxx=tens of hrs/mins and yyyy=units of hrs/mins
inithr=100001n ; 21:xx
initmin=0110000n ; xx:30
trisc(0) ; set clock I/O to outputs
portc = 0 ; clock I/O Low
;initclk() ; ################ temp always init clock
;goto initlcd:
;************* check if clock running *****************
;
; If seconds reg doesnt change after 1.1 seconds then initialise
; clock using the inithr & initmin variables above.
gettime()
temp=sec
wait(1100)
gettime()
if sec=temp then initclk()
initlcd:
lcd(-2) ; 2 line
lcd(257) ; clear and home
lcdstring("Clock MBG APR-96")
main:
gettime()
disptime()
goto main: ; restart whole cycle
;*************** select Register *******************
sub selreg(data)
trisc(0)
c6 = 0 ; set sclk LOW
c5 = 1 ; set RST high
clkwr1(data)
return
end
;*************** Clock Write *******************
sub clkwr(data)
clkwr1(data)
c5 = 0 ; set RST Low
return
end
;************* output data to RTC *************
sub clkwr1(data)
c7 = data & 1 ;
clocks(1,ADDPORTC+96) ; clock in bit0
c7 = data>>1 & 1 ;
clocks(1,ADDPORTC+96) ; clock in bit1
c7 = data>>2 & 1 ;
clocks(1,ADDPORTC+96) ; clock in bit2
c7 = data>>3 & 1 ;
clocks(1,ADDPORTC+96) ; clock in bit3
c7 = data>>4 & 1 ;
clocks(1,ADDPORTC+96) ; clock in bit4
c7 = data>>5 & 1 ;
clocks(1,ADDPORTC+96) ; clock in bit5
c7 = data>>6 & 1 ;
clocks(1,ADDPORTC+96) ; clock in bit6
c7 = data>>7 & 1 ;
clocks(1,ADDPORTC+96) ; clock in bit7
return
end
;************** read in data from RTC ***********
func clkrd()
trisc(10000000n) ; set I/O for INPUT (c7)
;clocks(1,ADDPORTC+96) ; clock out bit0
; NOTE! This is not needed as the
; act of clocking in the last bit
; of the register select routine
; actually clocks out the 1st bit
; of a following read routine
; because writes are clocked in on
; rising edges of SCLK whereas reads
; are clocked out on falling edges.
if c7=-1 then data=1
if c7=0 then data=0
clocks(1,ADDPORTC+96) ; clock out bit1
if c7=-1 then data=data+2
clocks(1,ADDPORTC+96) ; clock out bit2
if c7=-1 then data=data+4
clocks(1,ADDPORTC+96) ; clock out bit3
if c7=-1 then data=data+8
clocks(1,ADDPORTC+96) ; clock out bit4
if c7=-1 then data=data+16
clocks(1,ADDPORTC+96) ; clock out bit5
if c7=-1 then data=data+32
clocks(1,ADDPORTC+96) ; clock out bit6
if c7=-1 then data=data+64
clocks(1,ADDPORTC+96) ; clock out bit7
if c7=-1 then data=data+64+64
c5 = 0 ; set RST Low
return data
end
;*************** get time *********************
sub gettime()
selreg(10000101n) ; hour reg. (RD)
clkrd() ; read reg
hr=data&15
hrx=(data>>4)&3
selreg(10000011n) ; minutes reg. (RD)
clkrd() ; read reg
min=data&15
minx=(data>>4)&7
selreg(10000001n) ; seconds reg. (RD)
clkrd() ; read reg
sec=data&15
secx=(data>>4)&7
return
end
;*********** display time **********
sub disptime()
lcd(256+192+0) ; position for time display
lcd(hrx+48)
lcd(hr+48)
lcd(':')
lcd(minx+48)
lcd(min+48)
lcd(':')
lcd(secx+48)
lcd(sec+48)
return
end
;************* init clock *********************
sub initclk()
selreg(10001110n) ; Control reg. (WR)
clkwr(0) ; Reset WP flag
selreg(10000100n) ; Hours reg. (WR)
clkwr(inithr)
selreg(10000010n) ; Mins reg. (WR)
clkwr(initmin)
selreg(10010000n) ; Trickle Charge reg (WR)
clkwr(10100101n) ; 1 diode, 2k resistor (2ma charge)
selreg(10000000n) ; secs reg. +CH (bit7) (WR)
clkwr(2) ; +2 secs for initialise delays
return
end
Date: Thu, 25 Jul 1996Back to the Table of Contents
From: Mark K SullivanSubject: Re: Real Time Clocks (implementing) To: Multiple recipients of list PICLIST I've used Dallas DS1202 with the 16C54. It works well. I powered it from a .22F double layer capacitor when the power is off and it will keep the time for a couple of weeks. I wouldn't think 16C74 software code (using an interrupt timer) would be much bigger than what I used to talk to the DS1202. I used the 1202 because 1> it made the 16C54 code easier (no interrupts y'know) and 2> it made the capacitor backup much easier in my application. Code follows. This ran on an 8 MHz ceramic resonator. Sorry about the documentation (what documentation?!). I didn't know I was going to share it. The times are stored in BCD, just like in the DS1202 documentation. ; PROCESSOR PIC16C54 RADIX DEC ; #include "16c54.inc" ; cblock 8 Timer1 Timer2 Timer3 Count Second Minute Hour Date Month Day Year endc ; ; PB4 - CLOCK to calendar clock #define SCLK portb,4 ; PA2 - I/O to calendar clock. #define CLKDATA porta,2 ; PA3 - RST to calendar clock. #define CLKRST porta,3 ; org 0 ; RESET movlw 00h movwf porta ;turn off outputs movwf portb movlw 00h tris portb ;all outputs movlw 03h tris porta ;PA0,1 are inputs ; ; ; Set time ; call RClock ; movlw 96h movwf Year movlw 08h movwf Date movlw 02h movwf Day movlw 04h movwf Month movlw 17h movwf Hour movlw 25h movwf Minute movlw 00h movwf Second call WClock ;all done stop goto stop ; ; ; Write calendar clock ; WClock bcf SCLK ;negate clock nop nop nop nop bcf CLKDATA bsf CLKRST ;negate RST movlw 03h tris porta ;I/O is output movlw 08eh ;write control register call wbyte movlw 00h ;turn off WP call wbyte movlw 7 movwf Timer3 movlw 80h movwf Count movlw Second movwf fsr wc bcf CLKRST ;assert RST bcf SCLK ;negate clock nop nop nop nop bsf CLKRST ;negate RST movf Count,W call wbyte movf indf,W call wbyte incf fsr incf Count incf Count decfsz Timer3 goto wc bcf CLKRST ;assert RST retlw 0 ; ; ; Read calendar clock ; RClock bcf SCLK ;negate clock nop nop nop nop bcf CLKDATA ;negate I/O bsf CLKRST ;negate RST movlw 03h tris porta ;I/O is output movlw 0bfh ;burst read clock registers call wbyte movlw 07h tris porta ;I/O is input movlw Second movwf fsr call rbyte call rbyte call rbyte call rbyte call rbyte call rbyte call rbyte bcf CLKRST ;assert RST retlw 0 ; wbyte movwf Timer2 movlw 8 movwf Timer1 wbit bcf SCLK btfss Timer2,0 bcf CLKDATA btfsc Timer2,0 bsf CLKDATA nop nop ;data to clock setup nop bsf SCLK rrf Timer2 decfsz Timer1 goto wbit retlw 0 ; rbyte movlw 8 movwf Timer1 rbit bcf SCLK nop nop ;clock to data delay rrf indf bcf indf,7 btfsc CLKDATA bsf indf,7 bsf SCLK nop nop decfsz Timer1 goto rbit incf fsr retlw 0 ; org 1ffh goto RESET ; end
From: Llewellyn Griffiths llga@acslink.aone.net.auBack to the Table of Contents
Newsgroups: aus.electronics,comp.realtime,comp.arch.embedded
Subject: Re: DS 1202 Problem
Date: Mon, 13 Jan 1997 19:13:25 +1000
Regarding DS-1202 Problems
Some time ago I posted an article regarding problems setting the time
and date in a DS-1202 just as it rolled over at midnight. Since nobody
responded, I can only assume that this is a problem that is rarely
encountered. In the meantime I have received confirmation from Dallas
that this condition can occur if the RTC is updated when the chip's
internal state machine is rolling over the date and time.
It can be easily circumvented by waiting until the midnight rollover has
finished before setting the date and time.
While this situation obviously does not arise very often, I have posted
this article so that anybody who does come across it will not have to
waste time trying to determine the cause.
23 August 1998. Johannesburg
John Sanderson, JS Controls. jsand@pixie.co.za
notes:-
This code was written for a small daughter board, hosting a 16F84, to be
built into an existing instrument design.
It has a Real Time clock chip [DS1302], that comms. with the F84 by its
3-wire i/f.
There is BCD information read in from a mc14433 adc incorporated
in a DPM reading engineering units.
RS232 serial information is blasted out to a local printer, detailing the
time, DPM reading in 3 1/2 digit format, and a serial number incremented
in F84 EEPROM in three binary locations.
The data could just as easily go to a local PC com:port
Lastly, there are a couple of push switches and inputs from reed relays
here too, to initiate data dumping.
Lots of massage is needed to get the data into the right formats for all
this, this can be seen in the subroutinery.
Goodly chunks of the code have been cribbed from other folk's past PIClist
contributions, and from other places too I'm sure.
Having this stuff archived away saved me probably 50% of the time needed
to get this app. finished.
I've kept the names of the earlier contributors in the source code here
as a form of recognition.
My most heartfelt thanks go out to them.
;/////////////////////////////////////////////////////////////////////////
;//// rtc1302.ASM &nbsnbsp; ////
;//// &nbsnbsp; ////
;//// This module carries a Dallas DS1302 real time clock part.
; There is NO Xtal or Battery in this part, the time is held in
; registers for year, month, day hour etc.
; communication with the ds1302 is by 3-wire interface /rst,clk,dataq
;//// It reads / communicates with a FEMA MAG-35 panel DVM
;//// This uses a Motorola mc14433 adc, which can have the e.o.c. / d.u.
;//// lines disconnected.
;
;
; Functions:-
; 1. To HOLD DRO display on command of `closed relay' contacts from
; the rr4 contacts on the m/board.
; 2. To send serial output after the HOLD command.
; specs
; baud rate parity data bits stop bits
; 2400 n 8 2
; data
; year month day hour minute second index break value
; yyyy mm dd hh mm ss iiiiii kkkk
;
; Pushbuttons on unit - or flying umbilical
; 1. to advance time, faster as longer held in
; 2. to retard
;
;//// 16c84 has 32 fregs. 16f84 has 68 fregs. sp; //
;//// pin descriptions, DS 1302:- sp;
;//// 16f84 pin In/Out function **FOR PROTO-PIC ONLY!**
;//// ra0 17 I reed rla 4 closure for HOLD
;//// ra1 18 O rtc /rst pin5
;//// ra2 1 O rtc clk pin7
;//// ra3 2 I/O rtc dq data pin6
;//// ra4 3 O serial out rs232 0-5vdc (or up to 14v)
;////
;//// rb0 6 I/O interrupt of D.U. of mc14433 adc
;//// rb1 7 I BCD data from mc14433 Q0 pin20
;//// rb2 8 I BCD Q1 &p; pin21
;//// rb3 9 I BCD Q2 &p; pin22
;//// rb4 10 I BCD most sig. Q3 pin23
;//// rb5 11 I normally HI switches advance time
;//// rb6 12 I " " retard time
;//// rb7 13 spare
;//// &nbsnbsp;
;//////////////////////////////////////////////////////////////////////////
;******************************************assembler directives begin
list p=pic16f84
; list f=inhx8m
list r=dec ;radix decimal, keeps operands happy
__config _PWRTE_ON &_XT_OSC &_WDT_OFF
errorlevel 1,-302 ;kill off page rp0 warnings
#include;******************************************assembler directives end ;******************************************system definitions ;FOR PROTO-PIC VERSION ONLY! eerd equ 0 ;eeprom eecon1,0 read bit eewr equ 1 ;eeprom eecon1,1 write bit ;porta rr4 equ 0 ;reed relay4 closure. LO=closed _rst equ 1 ;rtc reset line LO=res clk equ 2 ;rtc clock (=sclk) dataq equ 3 ;rtc dq data line (=I/O) tx equ 4 ;rs232 tx line #define REED4 porta,rr4 ;INPUT ex m/b reed relay4. close=LO #define CLKRST porta,_rst ;RTC reset line LO=reset HI=active #define SCLK porta,clk ;RTC clock line #define CLKDATA porta,dataq ;RTC I/O data line #define SERTX porta,tx ;rs232 serial transmit line ;portb eoc equ 0 ;du = end of conv. int. and HOLD bcd_q0 equ 1 ;bcd data. ls bit bcd_q1 equ 2 ;bcd bcd_q2 equ 3 ;bcd bcd_q3 equ 4 ;bcd data. ms bit up_switch equ 5 ;normally HI switch for up time down_switch equ 6 ;" " " retard time ; equ 7 ;spare #define EOC portb,eoc #define BCD_Q0 portb,bcd_q0 #define BCD_Q1 portb,bcd_q1 #define BCD_Q2 portb,bcd_q2 #define BCD_Q3 portb,bcd_q3 #define UP_SWIT portb,up_switch #define DO_SWIT portb,down_switch ;#define portb, ;general purpose bit definitions ;gpflags register reed equ 0 ;reed relay `got pushed' flag up equ 1 ;up button `already pushed' flag down equ 2 ;down button `already pushed' ;general purpose register definitions cblock 0x0C m_porta ;mirror of port a m_portb ;mirror of port b gpflags ;general flags scratch ;scratch reg for *temporary* use scratch1 ; " &n; count1 ;counts 1,2,3 are for gen purpose count2 ;delay routines count3 ; up_count ;count of 0.1 secs when UP switch closed down_count ;count of 0.1 secs when DOWN switch closed timer1 ;for 8bit rotates in/out timer2 ;per Mark Sullivan's code 25.7.96 timer3 ;for the ds1202 or ds1302 count4 ;real-time-clock second ; minute ; hour ; date ; month ; day ; year ; ds1 ;adc most sig. bcd byte-low nibble only ds2 ; these are the bcd bytes as read in fro ds3 ; the adc, and have been massaged into ds4 ; (not packed) bcd tx_buff ;rs232 send routine pr01 ;rs232 buffer table pointer offset samp_index1 ;sample index no. binary l.s.byte EEPROM samp_index2 ;binary eeprom samp_index3 ;binary most sig. index eeprom byte count5 ;used in binary-to-bcd routine
temp_f ;for outputting binary-held data to
buff_4 ;bcd. bcd-to-ascii and rs232
buff_3 ;is then possible
buff_2
buff_1
temp_a
temp_b
temp_c
temp_d
temp_e
endc
;*********************************************end system definitions
;*********************************************system origin
org 0x000
goto start
org 0x004
goto service
;*********************************************end system origin
;************************************************tables first
powerup_table1
addwf pcl,same
retlw 0x59 ;Y ASCII char
retlw 0x65 ;e
retlw 0x61 ;a
retlw 0x72 ;r
retlw 0x20 ; sp
retlw 0x4D ;M
retlw 0x6F ;o
retlw 0x20 ; sp
retlw 0x44 ;D
retlw 0x61 ;a
retlw 0x20 ; sp
retlw 0x20 ; sp
retlw 0x68 ;h
retlw 0x72 ;r
retlw 0x20 ; sp
retlw 0x6D ;m
retlw 0x69 ;i
retlw 0x20 ; sp
retlw 0x73 ;s
retlw 0x65 ;e
retlw 0x20 ; sp
retlw 0x20 ; sp
retlw 0x69 ;i
retlw 0x6E ;n
retlw 0x64 ;d
retlw 0x65 ;e
retlw 0x78 ;x
retlw 0x20 ; sp
retlw 0x20 ; sp
retlw 0x20 ; sp
retlw 0x46 ;F
retlw 0x6F ;o
retlw 0x72 ;r
&