Hey CocaColaKid,
Your code for the DS1302 is really good and efficient...
I got a few questions,
how should i enable the trickle charge option ?
and how should i clear or set the clock halt flag???
Hey CocaColaKid,
Your code for the DS1302 is really good and efficient...
I got a few questions,
how should i enable the trickle charge option ?
and how should i clear or set the clock halt flag???
I am a neophyte at programming, but have been writing BASIC code for 40 years. This is how I would do the conversion:
DECX VAR BYTE(59)
A VAR BYTE
B VAR BYTE
C VAR BYTE
FOR B = 0 TO 59
FOR A = $0 TO $59
IF C = B THEN DECX(C) = A
C = C+1
NEXT A
NEXT B
' THIS ROUTINE GENERATES AN ARRAY WHERE
' DECX(0) = $0
' DECX (1) = $1
' ETC.
I didn't do it correctly the first time, this is better.
Last edited by Russ Kincaid; - 6th July 2006 at 02:31.
For all you old timers, here's an alternate way of calculating Human Date/Time from the RTC bits:
(Also, because all info is read in one shot, there is less liklihood that the seconds won't match the minutes.)
I2CREAD DPIN,CPIN,RTC,I2C_Adr_B,[Rd_seconds, rd_minutes, rd_hours, Rd_DOW, Rd_DAy, RD_month, Rd_Year] ' in bcd code
Seconds = Rd_Seconds.0 + (Rd_Seconds.1 * 2) + (rd_seconds.2 * 4) + (rd_Seconds.3 * 8) + (rd_seconds.4 * 10) + (rd_seconds.5 * 20) + (Rd_Seconds.6 * 40)
Minutes = Rd_Minutes.0 + (Rd_Minutes.1 * 2) + (rd_Minutes.2 * 4) + (rd_Minutes.3 * 8) + (rd_Minutes.4 * 10) + (rd_Minutes.5 * 20) + (Rd_Minutes.6 * 40)
Hours = RD_Hours.0 + (Rd_hours.1 * 2) + (rd_hours.2 * 4) + (rd_hours.3 * 8) + (rd_hours.4 * 10)
am_pm = rd_hours.5
dow = rd_dow
day = rd_day.0 + (rd_day.1 * 2) + (rd_day.2 * 4) + (rd_day.3 * 8) + (rd_day.4 * 10) + (rd_day.5 * 20)
Month = rd_month.0 + (rd_month.1 * 2) + (rd_month.2 * 4) + (rd_month.3 * 8) + (rd_month.4 * 10)
Year = rd_year.0 + (rd_year.1 * 2) + (rd_year.2 * 4) + (rd_year.3 * 8) + (rd_year.4 * 10) + (rd_year.5 * 20) + (rd_year.6 * 40) + (rd_year.7 * 80)
I suppose that might work. But it wouldn't be my first choice.
Only 30 or 40 times the needed code.
DT
Hello,
I added some code to Omer Yildiz's ds1302_LCD_setup.bas program that was modified from CocaColaKids original code example posted here & I added a timer and have a few questions if anyone could answer me.
I have read the DS1302 datasheet but couldn't figure out how to get the clock to show in the 12 hour mode for am & pm time. According to the datasheet I have to set bit 7 of the hours register to a high (1) but I don't understand Omer's code to do that. Also can anyone here explain what this kind of look up table is all about?
Quote from Omer's code.............................................. ...............
Lets burn the eeprom for something useful. A kind of lookup table.
eeprom 1,[31,28,31,30,31,30,31,31,30,31,30,31]
I've included the program here if anyone wants to look at it, I'm sure its not very efficient but it works.
These are the modifications below that I made to Omer's ds1302_LCD_setup.bas program. A possible application could be as a kitchen timer.
I added visual Lcd screens that shows you what your setting when setting the calendar and the clock. I also programmed the menu led to be used as a visual flashing indicator that the alarm time has elapsed. I added an up-count timer that increments each time the second variable of the DS1302 increments. I also added another 2 push buttons and followed Omer's nice example of his 2 button set and increment push button routine for setting the Seconds, Minutes and Hours times for the alarm. On initial power up the up-count timer is disabled, once your finished setting the times for the alarm and press the Set_Alarm_Timer_Push_Button then the up-counter starts incrementing. When the
set time equals the up-count time then the alarm buzzer sounds for approx 10 beeps then shuts off while the red led continues to flash until the Set_Timer_Push_Button is pressed to shut it off. Eventually I'll change it again to add more buttons, one for each of the Seconds, Minutes and Hours settings so the times can be set quicker but it works great as is.
There is one thing I noticed after getting the timer set up to work, is that when the up-count timer starts after your finished setting the alarm times, its not always accurate to the second. Because, depending on the time when your finished setting your times and then when you return to start the up-count timer, it very seldom starts exactly on a second change and can be out by as much as 900 ms. If this is only used as a kitchen timer then its not a big deal but in a time critical application it could be.
Thanks
jessey
Originally Posted by jessey
Hi jessey,
Omer is me.
That code was so old and just for an example. I have modified it several times afterwards.
For the eeprom look up table, it works while the user is in setup menu. It is not used in any other place in the code.
While the user is changing the day, the table matches the number of days for the stored month.
If the year is one of those with 29 days, then the "EEPROM location 2" will be written by 29 so that when user gets into "changing the day" and if it is in February then the max days on LCD will be 29.
Examples:
If the month is 1 then LCD shows the max day as day31 then starts from day1.
If the month is 2 then LCD shows the max day as day28 or day29 depending on the year and then starts from day1.
.
..
...
if the month is 11 then LCD shows the max day as day30 then starts from day1.
etc...
Last edited by sayzer; - 29th August 2006 at 09:02.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Hi sayzer,
Thanks for the explanation of your eeprom code.
I went over the DS1302 data sheet again (actually many times) and I think I got it now, I'm hoping. I finally realized that you wrote your code for the reads and writes of the Registers in hex which threw me off. When I converted them over to binary for the hours then it made some sense. I set bit 7 and bit 5 in the binary number then converted them back to hex. I haven't tried it yet but I think this might work.
for am 12 hr mode
writehour = 00100011 = $C4
readhour = 10100011 = $A3
for pm 12 hr mode
readhour = 10101011 = $AB
writehour = 00101011 = $D4
Do you think this will do it? If I have this part right then I don't think I'll have any problems converting over the rest of the code to display it with the am and pm.
Thanks
jessey
Bookmarks