DS1302 RAM Rd/Wr constant/address formatting question
xanatos
Posts: 1,120
I've spent the past hour searching the forum.· I KNOW I've seen the answer to this somewhere - perhaps an N&V column - but I've opened and read all the likely candidates there ("getting real with the DS1302", etc).· So in frustration, I've gotta ask....
I'm looking for the *description* of how the address and the·constant to read/write to that address are actually operated on by the DS1302.· The specific lines of code I am seeking to better understand is:
reg = WrRam | (index << 1)
and
reg = RdRam | (index << 1)
Where RdRam is a constant = $C0 and WrRam = $C1.
While I "know" that this means that the constant RdRam or WrRam are OR'd with the index value for the byte to be written to and shifted left 1 bit (???), I'm not really *understanding* what's happening.· And I'd like to...
Thanks for any help!
Dave
·
I'm looking for the *description* of how the address and the·constant to read/write to that address are actually operated on by the DS1302.· The specific lines of code I am seeking to better understand is:
reg = WrRam | (index << 1)
and
reg = RdRam | (index << 1)
Where RdRam is a constant = $C0 and WrRam = $C1.
While I "know" that this means that the constant RdRam or WrRam are OR'd with the index value for the byte to be written to and shifted left 1 bit (???), I'm not really *understanding* what's happening.· And I'd like to...
Thanks for any help!
Dave
·
Comments
First thing is to notify the DS1302 that you want to write and to which address you want to write to.
WrRam ($C0)·is the template for your command , the gap you have to fill in is the address which is bit 1 through 5 ( marked in·red )
11000000
The variable index is the address you manually enter via the debug screen , so say you entered 23 in binary thats 10111 ( the 5 bits we need )
Next we shift the value 23 left by 1 ( index<<1 ) giving 101110 .
Now when we OR index with WrRam we have the write command containing our address (which is now held by "reg")
11000000
OR
00101110
reg= 11101110
Jeff T.
It seems so simple now... Don't know why it seemed so confusing before...
Thanks again!
Dave X
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering