DS1302 clock integration problem
Archiver
Posts: 46,084
hello all,
I have been working on a project that, amoung other things,
interfaces the DS1302 clock with a BS2p40. Once finished, the project will have an
initial setup routine that will ask the user to set the clock. I pretty much
just copied the code that parallax sends out with it...the problem is that I want
to set the time with a variable instead of setting "temp" directly equal to
some HEX value (see below).
.
.
.
Temp = $23 'set hours here
RTCCmd = HrsReg
GOSUB WriteRTC
.
.
.
how do i convert a decimal input from the user into something that will work
here??
thanks in advance!
Joe Casabona
[noparse][[/noparse]Non-text portions of this message have been removed]
I have been working on a project that, amoung other things,
interfaces the DS1302 clock with a BS2p40. Once finished, the project will have an
initial setup routine that will ask the user to set the clock. I pretty much
just copied the code that parallax sends out with it...the problem is that I want
to set the time with a variable instead of setting "temp" directly equal to
some HEX value (see below).
.
.
.
Temp = $23 'set hours here
RTCCmd = HrsReg
GOSUB WriteRTC
.
.
.
how do i convert a decimal input from the user into something that will work
here??
thanks in advance!
Joe Casabona
[noparse][[/noparse]Non-text portions of this message have been removed]
Comments
allan.lane@h... writes:
> Note the 1302 uses "BCD" -- binary coded decimal.
> This means its numbers go from
> $00 to $09, then $10 to $19, then $20 to $29.
> So, $10 means '10' in BCD, but in the BS2 this
> value is really '16'.
>
Allan, the 1302 doesn't use BCD, but the DS1307 does.
Sid
[noparse][[/noparse]Non-text portions of this message have been removed]
jwilliams@p... writes:
> With respect, Sid, I believe the DS1302 DOES use BCD storage for values.
> All of my programs for the DS1302 are written that way....
>
Jon, I am running 3 different DS1302 programs/applications, and none of them
use BCD - just straight HEX.
Sid
[noparse][[/noparse]Non-text portions of this message have been removed]
jwilliams@p... writes:
> BCD is a method that stores a 0 to 9 value in each nibble of a byte --
> using the HEX operators in PBASIC is a way to work with BCD registers
> easily. If you wanted to preset the seconds register to 30, you would
> put 3 in the upper nibble and zero in the lower nibble. The easiest way
> to do this is
>
> secsReg = $30
>
> This handles things properly. The DS1302 does indeed use BCD storage,
> the hex operators included in PBASIC just make it a bit easier.
>
Jon, as usual you are absolutely correct. What I was trying to say was that
you do not need to convert from dec to BCD with the 1302 - just use the HEX
operators and you have accomplished the same thing. And much easier. I suppose
I could convert my 1307 program to HEX, but I will leave it in BCD so
I will remember how to use BCD if I ever need it for something else.
Sid
[noparse][[/noparse]Non-text portions of this message have been removed]
This means its numbers go from
$00 to $09, then $10 to $19, then $20 to $29.
So, $10 means '10' in BCD, but in the BS2 this
value is really '16'.
So, you'll need a decimal to BCD conversion.
Which is:
Number = 23 ' Number to be converted
HighNib = Number / 10 ' Gives 2
LowNib = Number // 10 ' Modulus operator -- gives 3
MyBCD = HighNib * 16 + LowNib ' * 16 to put in top nibble.
Temp = MyBCD
--- In basicstamps@yahoogroups.com, joecasa@a... wrote:
> hello all,
> I have been working on a project that, amoung other things,
> interfaces the DS1302 clock with a BS2p40. Once finished, the
project will have an
> initial setup routine that will ask the user to set the clock. I
pretty much
> just copied the code that parallax sends out with it...the problem
is that I want
> to set the time with a variable instead of setting "temp" directly
equal to
> some HEX value (see below).
>
> .
> .
> .
> Temp = $23 'set hours here
> RTCCmd = HrsReg
> GOSUB WriteRTC
> .
> .
> .
>
> how do i convert a decimal input from the user into something that
will work
> here??
>
> thanks in advance!
> Joe Casabona
>
>
> [noparse][[/noparse]Non-text portions of this message have been removed]
All of my programs for the DS1302 are written that way....
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: Newzed@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=X0Ynr1ZNzgO28oWnhqYvJHXq07tu55emUPpGk-NQPUiyjUPhPegGSMounb2BIMR2nSv4gw]Newzed@a...[/url
Sent: Monday, June 07, 2004 9:34 AM
To: basicstamps@yahoogroups.com
Subject: Re: [noparse][[/noparse]basicstamps] Re: DS1302 clock integration problem
In a message dated 6/7/2004 10:28:57 AM Eastern Daylight Time,
allan.lane@h... writes:
> Note the 1302 uses "BCD" -- binary coded decimal.
> This means its numbers go from
> $00 to $09, then $10 to $19, then $20 to $29.
> So, $10 means '10' in BCD, but in the BS2 this
> value is really '16'.
>
Allan, the 1302 doesn't use BCD, but the DS1307 does.
Sid
using the HEX operators in PBASIC is a way to work with BCD registers
easily. If you wanted to preset the seconds register to 30, you would
put 3 in the upper nibble and zero in the lower nibble. The easiest way
to do this is
secsReg = $30
This handles things properly. The DS1302 does indeed use BCD storage,
the hex operators included in PBASIC just make it a bit easier.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: Newzed@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=uZy2mo4HnEmvKMMNaUbagCZbbAAK_STPRI7aYOmSMOOvWuB6w3a2Q5831SL__V4GI42SHZSuJvbR]Newzed@a...[/url
Sent: Monday, June 07, 2004 10:46 AM
To: basicstamps@yahoogroups.com
Subject: Re: [noparse][[/noparse]basicstamps] Re: DS1302 clock integration problem
In a message dated 6/7/2004 11:43:36 AM Eastern Daylight Time,
jwilliams@p... writes:
> With respect, Sid, I believe the DS1302 DOES use BCD storage for
> values. All of my programs for the DS1302 are written that way....
>
Jon, I am running 3 different DS1302 programs/applications, and none of
them
use BCD - just straight HEX.
Sid