hippy
Ex-Staff (retired)
This code shows how to take the time data from a DS1307 RTC ( I2C Real-Time Clock ) and automatically adjust the date and time to local time, GMT (UTC) or BST for the UK. The DS1307 always keeps track of date and time as GMT, and time setting must be done using GMT.
BST starts on the last Sunday of March at 01:00:00 GMT, and finishes on the last Sunday of October at 01:00:00 GMT / 02:00:00 BST. The algorithm basically checks if it's between those times and if so adds an extra hour to what the DS1307 GMT date and time returned was, handling the roll-over during 23:00:00-23:59:59 GMT.
The code relies on the DS1307 automatically handling day roll-over adjusting the entire date including day of week ( held as 1-7, Sun-Sat, within DS1307 but converted to 0-6, Sun-Sat within the code ). The code only works for years 2000-2099, but so too does the DS1307. When we reach year 2100, the code can be adjusted to add and subtract days to compensate for the wrong leap year handling the DS1307 will present. Anyone trying is on their own; it's unlikely I'll be around then to help
All date and time information is kept and handled as BCD but code is written so it should be usable with any PICAXE, not just the X2 which have BCD conversion unary operators. Only tested with 28X2.
Output to AXE033 and/or Programming Editor Terminal display.
BST starts on the last Sunday of March at 01:00:00 GMT, and finishes on the last Sunday of October at 01:00:00 GMT / 02:00:00 BST. The algorithm basically checks if it's between those times and if so adds an extra hour to what the DS1307 GMT date and time returned was, handling the roll-over during 23:00:00-23:59:59 GMT.
The code relies on the DS1307 automatically handling day roll-over adjusting the entire date including day of week ( held as 1-7, Sun-Sat, within DS1307 but converted to 0-6, Sun-Sat within the code ). The code only works for years 2000-2099, but so too does the DS1307. When we reach year 2100, the code can be adjusted to add and subtract days to compensate for the wrong leap year handling the DS1307 will present. Anyone trying is on their own; it's unlikely I'll be around then to help
All date and time information is kept and handled as BCD but code is written so it should be usable with any PICAXE, not just the X2 which have BCD conversion unary operators. Only tested with 28X2.
Output to AXE033 and/or Programming Editor Terminal display.
Attachments
-
14.4 KB Views: 354