I hope Anobium won't think it too forward of me, but I tucked into his DS1307.H file to see if I could tighten things up a bit. After a very full week of hair pulling it finally fell together tonight. The hours-mode command was the real killer--more to that than meets the eye. I'll attach the new file in the next posting. But here's what I did:
edited for consistency and also heavily commented the code
removed several redundancies
combined DS1307_Enab_Osc and DS1307_Dis_Osc into one command
combined DS1307_Set12HourMode and DS1307_Set24HourMode into one command
combined DS1307_SQWEnable and DS1307_SQWDisable into one command
made parameters private so not to conflict with user's variables
reused parameters where reasonable to save memory (ten bytes only now)
amplified hour-mode to work reliably under all conditions
added a.m./p.m. flag
Again, I've commented the hell out of the code, so it should be pretty self-documenting. Let me know if you think I've missed anything.
Thomas Henry
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am sure it was not mine work in the first place. :-)
If we can get this validated by a few users then we can drop into to the next release as a replacement file.
Can you confirm you version of compiler and I2C support file please? Was the base code the May 2014 Hot Release?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2014-05-25
I'm using the newest Hot Release package for everything. Here's a better list of the commands and how to use them. I'll also attach it as a Word document. I decided to rename the Read and Write commands since they work equally well on the registers or the RAM.
I'm also continuing to test and work up some applications to use the new commands. I haven't given up on interrupts either!
DS1307 Real-Time Clock Commands
The DS1307.h include file provides both high- and low-level support for the DS1307 real-time clock chip, as well as inexpensive breakout boards like the TinyRTC which come packaged with a backup battery and additional eeprom. Insert the following directive in your code to make these new commands available:
#include<DS1307.h>
Here follows a list of the commands..
DS1307_Enable(flag)
enables the clock when flag is TRUE,
disables the clock when flag is FALSE
DS1307_ResetClock
resets clock completely to manufacturer’s original condition,
time to 00:00:00, day of the week to 01, date to 01/01/00,
also sets 24-hour mode and enables the clock.
DS1307_SetTime(hour, minute, second)
sets the time only: hours, minutes, seconds,.
also sets 24-hour mode and enables the clock.
DS1307_SetDate(date, month, year)
sets the date only: date, month, year,
there is no error detection for out-of-range dates, (e.g., April 31)
DS1307_SetClock(hour, minute, second, DOW, date, month, year)
sets the entire clock: hours, minutes, seconds, day of week, date, month, year.
there is no error detection for out-of-range dates, (e.g., April 31)
also sets 24-hour mode and enables the clock.
DS1307_ReadTime(hour, minute, second, flag)
reads the time only: hours, minutes, seconds, a.m. or p.m.,
flag = FALSE means a.m.,
flag = TRUE means p.m.
DS1307_ReadDate(date, month, year)
reads the date only: date, month, year
DS1307_ReadClock(hour, minute, second, flag, DOW, date, month, year)
reads the entire clock: hours, minutes, seconds, flag, day of week, date, month, year
flag = FALSE means a.m.,
flag = TRUE means p.m.
DS1307_SetHourMode(12|24)
sets the hour mode,
12 = 12-hour
24 = 24-hour
any other value defaults to 24-hour mode
DS1307_SetSQW(rate)
sets the square wave output pin mode:
0 = disable square wave output
1 = 1 Hz output
4 = 4096 Hz
8 = 8192 Hz
32 = 32768 Hz
any other value defaults to 1 Hz
DS1307_Write(address, value)
writes to the internal registers or RAM,
registers: 0x00 to 0x07
RAM: 0x08 to 0x3F
writing beyond this wraps around to the register space again, so be careful with multibyte writes
DS1307_Read(address, value)
reads from the internal registers or RAM,
see the notes, above.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2014-05-26
Hi gang,
I'm testing the revised include file and also working up a very complete demo. I'll post some results later today. Just so you know, in case you're testing in parallel with me, I found a simple problem with the day of the week which was easy to fix. It also means I'll have to update the documentation very slightly for total accuracy. It's not a bit deal, but I didn't want anyone losing hair over it.
Everything else is working very nicely.
Updates in a while,
Thomas Henry
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2014-05-27
Okay, here we go after an extremely productive day. Attached is a newly revised include file, a newly revised help file, and a substantial demo program.
While writing a practical demo program, I found that I needed a new command in the include file. So, I added DS_1307_ReadHourMode. There are also a few other changes from the previous draft I provided.
The demo is a very full featured calendar/clock. The code is extensively commented and includes operating instructions as well. I only needed two pushbuttons to get all the options which will make it great for chips with fewer pins.
If you had downloaded and saved any previous files I provided for the DS1307, please delete them now before getting the new ones (to avoid any confusion).
I am exceedingly happy with the clock chip itself (I'm using a TinyRTC breakout board version--only cost several dollars), how GCB handles it and the revised include file. Perhaps some enterprising person would like to expand the code below to include an alarm feature.
Anyway, I hope someone else will download these files and give them a test.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2014-05-28
I wrote up a small program to test the DS1307_Read and DS1307_Write commands (for the onboard RAM). They work just fine. Attached is the code if you want to confirm it for yourself.
With that, I have tested all of the old and new commands in the revised DS1307.h include file. As near as I can tell, it all works as expected. But it would be good if someone else could confirm or deny.
Finally got through to a code review and testing the revised DS1307.h file. Tested against old GCB DS1307 routines and they work great. There may be some backwards compatibility issue but these should be manageable.
This passed with flying colours/colors. I have posted to the code section of SourceForge - see here
I have posted a revised the extensive clock demo. See the next two postings.
Last edit: Anobium 2014-08-29
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A revised the extensive clock demofor the Chipino.
This has improvements to the user interface, support for UK clocks format, support for the Chipino, correction of a set error and a few other tweaks.
This will be included in the Help File as some point in the future.
The Chipino configuration is:
- An LCD Keypad shield with 6 buttons.
- DS1307 Data connected to D12
- DS1307 Clock connected to D13
- The DS1307 is required to be pulled high with suitable (4.7k) resistors.
- The DS1307 and the Chipino MUST have a common 0v connection.
A revised the extensive clock demo for the a 40 Pin development 16F877a board.
This has the same improvements to the user interface as the Chipino version, support for UK clocks format, correction of a set error and a few other tweaks.
This will be included in the Help File as some point in the future.
The configuration is:
- A 40 Pin 40 Pin development 16F877a board, like this <http://hobbycomponents.com/index.php/dvbd/dvbd-pic/pic-pic-development-board-pic16f877a.html>
- LCD connected in 4 bit mode as per the code.
- DS1307 Data connected to RC4
- DS1307 Clock connected to RCC
- The DS1307 is required to be pulled high with suitable (4.7k) resistors.
- The DS1307 and the board MUST have a common 0v connection.
I hope Anobium won't think it too forward of me, but I tucked into his DS1307.H file to see if I could tighten things up a bit. After a very full week of hair pulling it finally fell together tonight. The hours-mode command was the real killer--more to that than meets the eye. I'll attach the new file in the next posting. But here's what I did:
Again, I've commented the hell out of the code, so it should be pretty self-documenting. Let me know if you think I've missed anything.
Thomas Henry
And here is the new include file.
:-)
I am sure it was not mine work in the first place. :-)
If we can get this validated by a few users then we can drop into to the next release as a replacement file.
Can you confirm you version of compiler and I2C support file please? Was the base code the May 2014 Hot Release?
I'm using the newest Hot Release package for everything. Here's a better list of the commands and how to use them. I'll also attach it as a Word document. I decided to rename the Read and Write commands since they work equally well on the registers or the RAM.
I'm also continuing to test and work up some applications to use the new commands. I haven't given up on interrupts either!
DS1307 Real-Time Clock Commands
The DS1307.h include file provides both high- and low-level support for the DS1307 real-time clock chip, as well as inexpensive breakout boards like the TinyRTC which come packaged with a backup battery and additional eeprom. Insert the following directive in your code to make these new commands available:
Here follows a list of the commands..
DS1307_Enable(flag)
enables the clock when flag is TRUE,
disables the clock when flag is FALSE
DS1307_ResetClock
resets clock completely to manufacturer’s original condition,
time to 00:00:00, day of the week to 01, date to 01/01/00,
also sets 24-hour mode and enables the clock.
DS1307_SetTime(hour, minute, second)
sets the time only: hours, minutes, seconds,.
also sets 24-hour mode and enables the clock.
DS1307_SetDate(date, month, year)
sets the date only: date, month, year,
there is no error detection for out-of-range dates, (e.g., April 31)
DS1307_SetClock(hour, minute, second, DOW, date, month, year)
sets the entire clock: hours, minutes, seconds, day of week, date, month, year.
there is no error detection for out-of-range dates, (e.g., April 31)
also sets 24-hour mode and enables the clock.
DS1307_ReadTime(hour, minute, second, flag)
reads the time only: hours, minutes, seconds, a.m. or p.m.,
flag = FALSE means a.m.,
flag = TRUE means p.m.
DS1307_ReadDate(date, month, year)
reads the date only: date, month, year
DS1307_ReadClock(hour, minute, second, flag, DOW, date, month, year)
reads the entire clock: hours, minutes, seconds, flag, day of week, date, month, year
flag = FALSE means a.m.,
flag = TRUE means p.m.
DS1307_SetHourMode(12|24)
sets the hour mode,
12 = 12-hour
24 = 24-hour
any other value defaults to 24-hour mode
DS1307_SetSQW(rate)
sets the square wave output pin mode:
0 = disable square wave output
1 = 1 Hz output
4 = 4096 Hz
8 = 8192 Hz
32 = 32768 Hz
any other value defaults to 1 Hz
DS1307_Write(address, value)
writes to the internal registers or RAM,
registers: 0x00 to 0x07
RAM: 0x08 to 0x3F
writing beyond this wraps around to the register space again, so be careful with multibyte writes
DS1307_Read(address, value)
reads from the internal registers or RAM,
see the notes, above.
Hi gang,
I'm testing the revised include file and also working up a very complete demo. I'll post some results later today. Just so you know, in case you're testing in parallel with me, I found a simple problem with the day of the week which was easy to fix. It also means I'll have to update the documentation very slightly for total accuracy. It's not a bit deal, but I didn't want anyone losing hair over it.
Everything else is working very nicely.
Updates in a while,
Thomas Henry
Okay, here we go after an extremely productive day. Attached is a newly revised include file, a newly revised help file, and a substantial demo program.
While writing a practical demo program, I found that I needed a new command in the include file. So, I added DS_1307_ReadHourMode. There are also a few other changes from the previous draft I provided.
The demo is a very full featured calendar/clock. The code is extensively commented and includes operating instructions as well. I only needed two pushbuttons to get all the options which will make it great for chips with fewer pins.
If you had downloaded and saved any previous files I provided for the DS1307, please delete them now before getting the new ones (to avoid any confusion).
I am exceedingly happy with the clock chip itself (I'm using a TinyRTC breakout board version--only cost several dollars), how GCB handles it and the revised include file. Perhaps some enterprising person would like to expand the code below to include an alarm feature.
Anyway, I hope someone else will download these files and give them a test.
Thomas Henry
Here's the help file info in Word format.
And here's the extensive clock demo.
I wrote up a small program to test the DS1307_Read and DS1307_Write commands (for the onboard RAM). They work just fine. Attached is the code if you want to confirm it for yourself.
With that, I have tested all of the old and new commands in the revised DS1307.h include file. As near as I can tell, it all works as expected. But it would be good if someone else could confirm or deny.
Finally got through to a code review and testing the revised DS1307.h file. Tested against old GCB DS1307 routines and they work great. There may be some backwards compatibility issue but these should be manageable.
This passed with flying colours/colors. I have posted to the code section of SourceForge - see here
I have posted a revised the extensive clock demo. See the next two postings.
Last edit: Anobium 2014-08-29
A revised the extensive clock demofor the Chipino.
This has improvements to the user interface, support for UK clocks format, support for the Chipino, correction of a set error and a few other tweaks.
This will be included in the Help File as some point in the future.
The Chipino configuration is:
A revised the extensive clock demo for the a 40 Pin development 16F877a board.
This has the same improvements to the user interface as the Chipino version, support for UK clocks format, correction of a set error and a few other tweaks.
This will be included in the Help File as some point in the future.
The configuration is:
Last edit: Anobium 2014-08-29
Added Harware I2C support to the driver.
See here for example code. The driver now support Software I2C and Hardware I2C.