Problem with DS1302 and Proton+
dear friends,
I have a problem with the DS1302, PIC16f877 and PIC Proton+ combination. I designed a basic circuit in PROTEUS, and put your code in it. I worked fine. There was no problem. but when I made that circuit real, I met with problems. When I powered the PIC I can not see the time runing. The only thing that I see is " 00:00:80" and it always stays same. I used portd.0,d1 and d2 in the connection of PIc and DS1302. I used 32.768khz crystal. And there is no any mistake in connections. How can I fix this problem ?
And one more small question. How can I reset LCD ? in PicBasic PRo I used to written "Flags=0". In Proton+ what should I write instead of this ?
2 Attachment(s)
RTC - DS1302 with User Interface
Here is a modified version of the code posted by CocaColaKid above.
In the code above, the clock can only be set during the programming of PIC.
With the modification here, the user can set the time, date etc. at any given time.
Advise/post any additions, recommendations, modifications etc if any.
1 Attachment(s)
Shorther HEX convertion sub routine
As members are asking;
Attached is the updated version with more space.
(HEX Conversion is shorter)
------------------------------------------------------
Straight-forward RTC bits conversion algorithm
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)
1 Attachment(s)
How do I set the 12 hr mode for DS1302
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
enabling trickle charging
this is a very belated response to shahidali55.
I've added a tiny bit of code to "ds1302_user_interface.txt" to enable trickle charging. This is a small feat, but helped me understand how the register addressing and definitions are used.
edit: I'm using a 5v 0.47f supercap which doesn't need diodes or resistors, so "trickledef" below uses a bit sequence 1010 (for TCS) 00 (for DS) and 00 (for RS), see page 7 of the DS1302 datasheet for other options
cheers,
Tobie
==========================
'additional variables
writechrg var byte
tricklereg var byte
writechrg = $91 'Write Command for the trickle register
trickledef = $A0 'definition for a supercap which uses no diodes or resistors
' this goes in the "setup" subroutine, not as the statement first or last though
reg_adr = writechrg
outbyte = tricklereg
gosub w_out