DS1302 (RTC) timer circuit. HELP!!
Hello All:
I am new to this group, but I've been looking through the archives, and you seem
very helpful. So here is my problem:
I am currently using a BSII on a BOE circuit board with a DS1302 RTC. I have an
X-10 powerline interface connected to the circuit as well. All circuit
connections seem to be correct. My only problem is programming in PBASIC. Now,
I'm not very familiar with programming in general, but here's what I need.
-I need the circuit to issue ON/OFF commands to the X-10 module on a
user-defined time. In my case I chose 8:10:00am for on & 8:25:00am for OFF, but
these need to be able to be varied in the code.
-I need the debug screen to show the circuit issuing the ON or OFF commands to
the X-10 module at the specified times.
With the code I currently have, the light I have connected to the X-10 module
just blinks ON-OFF-ON-OFF-ON, etc. repeatedly. Also, if I plug anything into the
X-10 switch module, it automatically stays on if i don't have the circuit
powered. Is this supposed to happen.
Below is the code I wrote using the sample codes given to me by Parallax. If
anyone can modify it to what i need or give me a few leads, I'd really
appreciate it.
Thanks,
-J
'{$STAMP BS2}
'* Title: my_code.bs2 *
'* 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. It then sends XOUT commands to turn a coffee maker
'* on or off.
'Define I/O pins and RTC variables
Clk CON 2
Dta CON 3
RTCCS CON 4
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
'X-10 Powerline Interface pin assignments:
zPin con 0 ' Zero-crossing-detect pin.
mPin con 1 ' Modulation-control pin.
'Define RTC Command Constants
SecReg CON %00000
MinReg CON %00001
HrsReg CON %00010
DateReg CON %00011
MonReg CON %00100
DayReg CON %00101
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 DATA "January",0
Feb DATA "February",0
Mar DATA "March",0
Apr DATA "April",0
May DATA "May",0
Jun DATA "June",0
Jul DATA "July",0
Aug DATA "August",0
Sep DATA "September",0
Oct DATA "October",0
Nov DATA "November",0
Dcm DATA "December",0
AM DATA " AM",0
PM DATA " PM",0
'House code & Unit code for X-10 modules:
houseA con 0 ' House code: 0=A, 1=B... 15=P
Unit1 con 0 ' Unit code: 0=1, 1=2... 15=16
'Set I/O pin states and directions
OUTS = %0000000000000000 'All logic low
DIRS = %0000000000000111 'I/O 0,1 and 2 are output, rest are input
Initialize:
'Set Time and Date to current.
'NOTE: Date must be set only once for every power-up of DS1302 chip.
Day = $03 'Tuesday
Month = $08 'August
Date = $07 '7th
Year = $01 '2001
Hours = $17 '5:00 PM (in 24-hour mode)
Minutes = $23
Seconds = $20
GOSUB SetTimeAndDate
Loop:
'Read out all date and time values and display them in two formats on
'the debug screen.
GOSUB ReadRTCBurst
DEBUG HOME,"LONG FORMAT DATE AND TIME:",CR
GOSUB PrintLongDate
GOSUB Print24HourTime
DEBUG CR,CR,"SHORT FORMAT DATE AND TIME:",CR
GOSUB PrintShortDate
GOSUB Print12HourTime
'Timer commands:
IF HrsReg = $08 & MinReg = $10 & SecReg = $00 THEN ON: 'Turn ON at 8:10am.
ON:
xout mPin,zPin,[noparse][[/noparse]houseA\Unit1] ' Talk to Unit 1.
xout mPin,zPin,[noparse][[/noparse]houseA\uniton] ' Tell it to turn ON.
IF HrsReg = $08 & MinReg = $25 & SecReg = $00 THEN OFF: 'Turn OFF at 8:25am.
OFF:
xout mPin,zPin,[noparse][[/noparse]houseA\Unit1] ' Talk to Unit 1.
xout mPin,zPin,[noparse][[/noparse]houseA\unitoff] ' Tell it to turn OFF.
GOTO Loop
'==================== DS1302 Real-Time Clock Subroutines ===================
PrintLongDate:
'Print long date format on debug screen
LOOKUP Day-1,[noparse][[/noparse]Sun,Mon,Tue,Wed,Thu,Fri,Sat],Idx
GOSUB PrintIt
DEBUG "day, "
LOOKUP Month-1,[noparse][[/noparse]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
RETURN
PrintShortDate:
'Print short date format on debug screen
DEBUG HEX2 Month,"/",HEX2 Date,"/",HEX2 Year, CR
RETURN
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,[noparse][[/noparse]AM,PM],Idx
GOSUB PrintIt
RETURN
Print24HourTime:
'Print 24-hour time format on debug screen
DEBUG HEX2 Hours,":",HEX2 Minutes,":",HEX2 Seconds
RETURN
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
DEBUG Value 'Display it on screen
Idx = Idx + 1
GOTO PrintIt
Finished:
RETURN
WriteRTCRAM:
'Write to DS1302 RAM Register
HIGH RTCCS
SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%11\2,Value]
LOW RTCCS
RETURN
WriteRTC:
'Write to DS1302
HIGH RTCCS
SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%10\2,Value]
LOW RTCCS
RETURN
ReadRTCBurst:
'Read all time-keeping registers in one burst
HIGH RTCCS
SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Day,Year]
LOW RTCCS
RETURN
ReadRTCRAM:
'Read DS1302 RAM Register
HIGH RTCCS
SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,RTCCmd\5,%11\2]
SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Value]
LOW RTCCS
RETURN
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,[noparse][[/noparse]0,Seconds,Minutes,Hours,Date,Month,Day,Year,128],Value
LOOKUP Idx,[noparse][[/noparse]CtrlReg, SecReg, MinReg, HrsReg, DateReg, MonReg, DayReg, YrReg,
CtrlReg],RTCCmd
GOSUB WriteRTC
NEXT
RETURN
'End of Program.
stop
[noparse][[/noparse]Non-text portions of this message have been removed]
I am new to this group, but I've been looking through the archives, and you seem
very helpful. So here is my problem:
I am currently using a BSII on a BOE circuit board with a DS1302 RTC. I have an
X-10 powerline interface connected to the circuit as well. All circuit
connections seem to be correct. My only problem is programming in PBASIC. Now,
I'm not very familiar with programming in general, but here's what I need.
-I need the circuit to issue ON/OFF commands to the X-10 module on a
user-defined time. In my case I chose 8:10:00am for on & 8:25:00am for OFF, but
these need to be able to be varied in the code.
-I need the debug screen to show the circuit issuing the ON or OFF commands to
the X-10 module at the specified times.
With the code I currently have, the light I have connected to the X-10 module
just blinks ON-OFF-ON-OFF-ON, etc. repeatedly. Also, if I plug anything into the
X-10 switch module, it automatically stays on if i don't have the circuit
powered. Is this supposed to happen.
Below is the code I wrote using the sample codes given to me by Parallax. If
anyone can modify it to what i need or give me a few leads, I'd really
appreciate it.
Thanks,
-J
'{$STAMP BS2}
'* Title: my_code.bs2 *
'* 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. It then sends XOUT commands to turn a coffee maker
'* on or off.
'Define I/O pins and RTC variables
Clk CON 2
Dta CON 3
RTCCS CON 4
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
'X-10 Powerline Interface pin assignments:
zPin con 0 ' Zero-crossing-detect pin.
mPin con 1 ' Modulation-control pin.
'Define RTC Command Constants
SecReg CON %00000
MinReg CON %00001
HrsReg CON %00010
DateReg CON %00011
MonReg CON %00100
DayReg CON %00101
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 DATA "January",0
Feb DATA "February",0
Mar DATA "March",0
Apr DATA "April",0
May DATA "May",0
Jun DATA "June",0
Jul DATA "July",0
Aug DATA "August",0
Sep DATA "September",0
Oct DATA "October",0
Nov DATA "November",0
Dcm DATA "December",0
AM DATA " AM",0
PM DATA " PM",0
'House code & Unit code for X-10 modules:
houseA con 0 ' House code: 0=A, 1=B... 15=P
Unit1 con 0 ' Unit code: 0=1, 1=2... 15=16
'Set I/O pin states and directions
OUTS = %0000000000000000 'All logic low
DIRS = %0000000000000111 'I/O 0,1 and 2 are output, rest are input
Initialize:
'Set Time and Date to current.
'NOTE: Date must be set only once for every power-up of DS1302 chip.
Day = $03 'Tuesday
Month = $08 'August
Date = $07 '7th
Year = $01 '2001
Hours = $17 '5:00 PM (in 24-hour mode)
Minutes = $23
Seconds = $20
GOSUB SetTimeAndDate
Loop:
'Read out all date and time values and display them in two formats on
'the debug screen.
GOSUB ReadRTCBurst
DEBUG HOME,"LONG FORMAT DATE AND TIME:",CR
GOSUB PrintLongDate
GOSUB Print24HourTime
DEBUG CR,CR,"SHORT FORMAT DATE AND TIME:",CR
GOSUB PrintShortDate
GOSUB Print12HourTime
'Timer commands:
IF HrsReg = $08 & MinReg = $10 & SecReg = $00 THEN ON: 'Turn ON at 8:10am.
ON:
xout mPin,zPin,[noparse][[/noparse]houseA\Unit1] ' Talk to Unit 1.
xout mPin,zPin,[noparse][[/noparse]houseA\uniton] ' Tell it to turn ON.
IF HrsReg = $08 & MinReg = $25 & SecReg = $00 THEN OFF: 'Turn OFF at 8:25am.
OFF:
xout mPin,zPin,[noparse][[/noparse]houseA\Unit1] ' Talk to Unit 1.
xout mPin,zPin,[noparse][[/noparse]houseA\unitoff] ' Tell it to turn OFF.
GOTO Loop
'==================== DS1302 Real-Time Clock Subroutines ===================
PrintLongDate:
'Print long date format on debug screen
LOOKUP Day-1,[noparse][[/noparse]Sun,Mon,Tue,Wed,Thu,Fri,Sat],Idx
GOSUB PrintIt
DEBUG "day, "
LOOKUP Month-1,[noparse][[/noparse]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
RETURN
PrintShortDate:
'Print short date format on debug screen
DEBUG HEX2 Month,"/",HEX2 Date,"/",HEX2 Year, CR
RETURN
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,[noparse][[/noparse]AM,PM],Idx
GOSUB PrintIt
RETURN
Print24HourTime:
'Print 24-hour time format on debug screen
DEBUG HEX2 Hours,":",HEX2 Minutes,":",HEX2 Seconds
RETURN
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
DEBUG Value 'Display it on screen
Idx = Idx + 1
GOTO PrintIt
Finished:
RETURN
WriteRTCRAM:
'Write to DS1302 RAM Register
HIGH RTCCS
SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%11\2,Value]
LOW RTCCS
RETURN
WriteRTC:
'Write to DS1302
HIGH RTCCS
SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%10\2,Value]
LOW RTCCS
RETURN
ReadRTCBurst:
'Read all time-keeping registers in one burst
HIGH RTCCS
SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Day,Year]
LOW RTCCS
RETURN
ReadRTCRAM:
'Read DS1302 RAM Register
HIGH RTCCS
SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,RTCCmd\5,%11\2]
SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Value]
LOW RTCCS
RETURN
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,[noparse][[/noparse]0,Seconds,Minutes,Hours,Date,Month,Day,Year,128],Value
LOOKUP Idx,[noparse][[/noparse]CtrlReg, SecReg, MinReg, HrsReg, DateReg, MonReg, DayReg, YrReg,
CtrlReg],RTCCmd
GOSUB WriteRTC
NEXT
RETURN
'End of Program.
stop
[noparse][[/noparse]Non-text portions of this message have been removed]
Comments
> ...With the code I currently have, the light I have connected to
> the X-10 module just blinks ON-OFF-ON-OFF-ON, etc. repeatedly.
> Also, if I plug anything into the X-10 switch module, it
> automatically stays on if i don't have the circuit powered. Is this
> supposed to happen.
When an IF statement's condition is satisfied, execution resumes at
the indicated label. When the condition is not satisfied, execution
resumes at the next sequential instruction. In your case, both were
the same so execution always resumed at the ON and OFF labels. Also
the "AND" operator is preferred over "&" in IF statements. I think
this is more like what you want:
'Timer commands:
IF HrsReg = $08 AND MinReg = $10 AND SecReg = $00 THEN ON
IF HrsReg = $08 AND MinReg = $25 AND SecReg = $00 THEN OFF
GOTO Loop
ON:
xout mPin,zPin,[noparse][[/noparse]houseA\Unit1] ' Talk to Unit 1.
xout mPin,zPin,[noparse][[/noparse]houseA\uniton] ' Tell it to turn ON.
GOTO Loop
OFF:
xout mPin,zPin,[noparse][[/noparse]houseA\Unit1] ' Talk to Unit 1.
xout mPin,zPin,[noparse][[/noparse]houseA\unitoff] ' Tell it to turn OFF.
GOTO Loop
Regards,
Steve
the serial port.
-J
Original Message
From: "S Parkis" <parkiss@e...>
To: "Joe Khachadourian" <kach705@y...>; <basicstamps@yahoogroups.com>
Sent: Wednesday, August 08, 2001 3:34 PM
Subject: Re: [noparse][[/noparse]basicstamps] DS1302 (RTC) timer circuit. HELP!!
> On 8 Aug 01 at 12:42, Joe Khachadourian wrote:
>
> > ...With the code I currently have, the light I have connected to
> > the X-10 module just blinks ON-OFF-ON-OFF-ON, etc. repeatedly.
> > Also, if I plug anything into the X-10 switch module, it
> > automatically stays on if i don't have the circuit powered. Is this
> > supposed to happen.
>
> When an IF statement's condition is satisfied, execution resumes at
> the indicated label. When the condition is not satisfied, execution
> resumes at the next sequential instruction. In your case, both were
> the same so execution always resumed at the ON and OFF labels. Also
> the "AND" operator is preferred over "&" in IF statements. I think
> this is more like what you want:
>
>
> 'Timer commands:
>
> IF HrsReg = $08 AND MinReg = $10 AND SecReg = $00 THEN ON
> IF HrsReg = $08 AND MinReg = $25 AND SecReg = $00 THEN OFF
> GOTO Loop
>
> ON:
> xout mPin,zPin,[noparse][[/noparse]houseA\Unit1] ' Talk to Unit 1.
> xout mPin,zPin,[noparse][[/noparse]houseA\uniton] ' Tell it to turn ON.
> GOTO Loop
>
> OFF:
> xout mPin,zPin,[noparse][[/noparse]houseA\Unit1] ' Talk to Unit 1.
> xout mPin,zPin,[noparse][[/noparse]houseA\unitoff] ' Tell it to turn OFF.
> GOTO Loop
>
>
> Regards,
>
> Steve
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com