OK, lets break this down...
DecimalByte=(BCDByte>>4)*10+(BCDByte & $0F)
The calculations in the brackets will be perfomed first, and the results stored in a PICBasic variable behind the scenes. BCDByte is unchanged - just as well because we refer to it twice, once to access the top four bits, and once to access the bottom four bits.
Thereafter, PBP follows mathematical rules of priority... ie Multiplication and Division are performed before addition ans subtraction. Because items in brackets are always calculated from the centre out, and each set of brackets is it's own self-contained world, the result of the formula below, will be the same as that above.
DecimalByte=(BCDByte & $0F)+((BCDByte>>4)*10)
However, you do have an extra set of brackets there... but PBP actually resolved the formula without any additional penalty. Might not be so lucky on another occasion.
Thanks again Melanie,
Hmmm, I think I almost understand what's going on with that code. I must actually be learning something.
I ended up with this, from the code you supplied and it works excellent.
Code:increminute: rtcmathtemp =(rtcmin>>4)*10+(rtcmin & $0F) 'convert BCD minutes into Decimal minutes rtcmathtemp=rtcmathtemp+1 'increment by 1 If rtcmathtemp>59 then 'If minutes exceeds 59 rtcmathtemp=0 'reset to 0 endif rtcmin=((rtcmathtemp DIG 1)<<4)+rtcmathtemp DIG 0 'convert Decimal back to BCD gosub settime return
Sigh, well I seem to have a new problem. Although I'm obviously able to read/write to the DS1302 in "burst" mode, I seem to be having a problem addressing individual registers.
For instance, I need to turn the trickle charger on...
I *thought* it was as simple this:
But that doesn't seem to do it for me.Code:rst = 1 'Set Battery charger on and set to "1 diode, 2Kohm" Shiftout IO, SCLK, LSBFIRST, [$90, $A5] ' Set charger [$90, $A5] RST = 0
Anyone got the patience to help me along a little further....
p-p-p-please?
Thanks!
Steve
Hi Steve, check uot pages5/ 6 of this data sheet, it says: DS 1302 powers up with trickle charger disabled and only a pattern of 1010 will enable charger. http://forums.parallax.com/forums/attach.aspx?a=26594 HTH
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Thanks Joe,
You can't imagine how many times I've read the data sheet.... (it's been open on my desktop for days now)
I'm clearly not quite understanding yet.
Yes, a pattern of 1010 turns on the charger, and the other 4 bits of the byte set the charge rate.
So what ( I think) I want to send is 10100101 which should tun on the charger and set it to "1 diode, 2Kohm" operation. In HEX, that's $A5, right?
So I've sent $90, which should be the register address for the charger, and $A5, which should be the code to turn it on and set it to my chosen charge mode. I even tried sending the data in binary, like so:
but with the same (no) result.Code:rst = 1 'Set Battery charger on and set to "1 diode, 2Kohm" Shiftout IO, SCLK, LSBFIRST, [$90, %10100101] ' Set charger [$90, $A5] RST = 0
What am I doing wrong? (please!)
Thanks,
Steve
Ahh, never mind, I figured it out...
Setting up the trickle charger is the first task task I ask of the DS1302, and I just needed to pull the reset line LOW first, before I yank it high and move the data.
All I was missing was "rst = 0" up front:
Thanks again to everyone!Code:rst = 0 rst = 1 'Set Battery charger on and set to "1 diode, 2Kohm" Shiftout IO, SCLK, LSBFIRST, [$90, %10100101] ' Set charger [$90, $A5] RST = 0
Steve
Bookmarks