📄 rtc_calendar.asm
字号:
;******************************************************************************
; Code for application report - "Real Time Clock Library"
;******************************************************************************
; THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
; REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
; INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
; FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
; COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
; TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
; POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
; INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
; YOUR USE OF THE PROGRAM.
;
; IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
; CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
; THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
; OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
; OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
; EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
; REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
; OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
; USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
; AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
; YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
; (U.S.$500).
;
; Unless otherwise stated, the Program written and copyrighted
; by Texas Instruments is distributed as "freeware". You may,
; only under TI's copyright in the Program, use and modify the
; Program without any charge or restriction. You may
; distribute to third parties, provided that you transfer a
; copy of this license to the third party and the third party
; agrees to these terms by its first use of the Program. You
; must reproduce the copyright notice and any other legend of
; ownership on each copy or partial copy, of the Program.
;
; You acknowledge and agree that the Program contains
; copyrighted material, trade secrets and other TI proprietary
; information and is protected by copyright laws,
; international copyright treaties, and trade secret laws, as
; well as other intellectual property laws. To protect TI's
; rights in the Program, you agree not to decompile, reverse
; engineer, disassemble or otherwise translate any object code
; versions of the Program to a human-readable form. You agree
; that in no event will you alter, remove or destroy any
; copyright notice included in the Program. TI reserves all
; rights not specifically granted under this license. Except
; as specifically provided herein, nothing in this agreement
; shall be construed as conferring by implication, estoppel,
; or otherwise, upon you, any license or other right under any
; TI patents, copyrights or trade secrets.
;
; You may not use the Program in non-TI devices.
;
;******************************************************************************
; RTC Library
;
; Description; Keeps track of seconds, minutes, day, month, year, AM/PM
; Leap years are accounted for until year 2400
; Both EU standard and US daylight savings time is implemented
;
; Typical Cycle Count per function:
; incrementSeconds 14
; incrementMinutes 14
; incrementHours 35
; incrementDays 37
; incrementMonths 14
; incrementYears 36
; setDate 681
; get24Hour 23
;
; Memory Usage: 714 bytes
; (12 bytes RAM)
;
; L. Westlund
; Version 1.0
; Texas Instruments, Inc
; January 2005
; Built with Code Composer Essentials Version: 1.0
;******************************************************************************
;Change log
;
;1.0 - Inital version - L.Westlund
;******************************************************************************
;Variables
.def TI_day
.def TI_FebDays
.def TI_hour
.def TI_dayOfWeek
.def TI_PM
.def TI_second
.def TI_year
.def TI_minute
.def TI_month
.def TI_dayLightZone
.def TI_dayLightSavings
;Functions
.def incrementSeconds
.def incrementMinutes
.def incrementHours
.def incrementDays
.def incrementMonths
.def incrementYears
.def testLeap
.def setDate
.def get24Hour
.bss TI_year, 2
.bss TI_second, 1
.bss TI_minute, 1
.bss TI_hour, 1
.bss TI_day, 1
.bss TI_month, 1
.bss TI_PM, 1
.bss TI_FebDays, 1
.bss TI_dayOfWeek, 1
.bss TI_dayLightZone, 1
.bss TI_dayLightSavings, 1
.text ; text section
TI_daysInMonth .byte 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x30, 0x31
TI_mNumbers .byte 0x00, 0x03, 0x02, 0x05, 0x00, 0x03, 0x05, 0x01, 0x04, 0x06, 0x02, 0x04
;============================================================================
; incrementSeconds
;============================================================================
incrementSeconds
clrc
dadd.b #0x01, &TI_second ; tick one second
cmp.b #0x60, &TI_second ; see if we've hit 60 seconds
jne return ; if not, return
clr.b &TI_second ; if so, go back to 00
; fall down to increment minutes
;============================================================================
; incrementMinutes
;============================================================================
incrementMinutes
clrc
dadd.b #0x01, &TI_minute ; tick one minute
cmp.b #0x60, &TI_minute ; see if we've hit 60 minutes
jne return ; if not, return
clr.b &TI_minute ; if so, go back to 00
; fall down to increment hours
;============================================================================
; incrementHours
;============================================================================
incrementHours
clrc
mov.b &TI_hour, r14
dadd.b #0x01, r14
cmp.b #0x01, &TI_dayLightZone ; see what we are doing for DS
jeq US_DS_TEST
jge EU_DS_TEST
noDS cmp.b #0x12, r14 ; test for 12:00 o'clock
jne notSwitchPM ; if not, don't switch the PM variable
tst.b &TI_PM ; see if it is PM and we should roll
jnz rollAM ; PM and roll bit set, change to AM and roll day
xor.b #0x01, &TI_PM ; change PM value
returnHours
mov.b r14, &TI_hour
return ret
notSwitchPM
cmp.b #0x13, r14 ; see if we've hit 13
jne returnHours ; if not, return
mov.b #0x01, &TI_hour ; if so, 13 o'clock == 1 o'clock
ret ; return to save CPU cycles
rollAM
clr.b &TI_PM ; clear PM, now it is AM
mov.b r14, &TI_hour ; save hour value
; fall down to increment days
;============================================================================
; incrementDays
;============================================================================
incrementDays
clrc
dadd.b #0x01, &TI_day ; add a day
cmp.b #0x06, &TI_dayOfWeek ; see if it is Sat, end of week
jl notSat
mov.b #0xFF, &TI_dayOfWeek
notSat add.b #0x01, &TI_dayOfWeek
mov.w #TI_daysInMonth, r13 ; move the destination addr (word) to r13
mov.b &TI_month, r15
add.w r15, r13 ; add the month offset to the daysInMonth pointer
mov.b @r13, r14 ; r14 = number of days in the current month
cmp.b #0x01, &TI_month ; month '01' == FEB
jne compareDays ; special case for Feb due to leap years
getFebDays
mov.b &TI_FebDays, r14 ; r14 holds the number of days in the current Feb
compareDays
sub.b &TI_day, r14 ; r14 = number days in Month - current day value
jge return ; if r14 > 0 ... we still have days left
mov.b #0x01, &TI_day ; if not, roll to day 1
; fall down to increment months
;============================================================================
; incrementMonths
;============================================================================
incrementMonths
clrc
dadd.b #0x01, &TI_month ; increment month counter
cmp.b #0x12, &TI_month ; see if we've gone past the last month (11)
jl return ; if no return
resetMonth
clr.b &TI_month ; if so, back to January == 0
; and fall through to years
;============================================================================
; incrementYear - This algorithm will fail on 2400 A.D and not compute leap
;============================================================================
incrementYears
clrc
dadd.w #0x01, &TI_year ; add 1 to the year
testLeap mov.w &TI_year, r14 ; r14 = year
bit.w #0xFF, r14 ; called by C functions to test new year
jz notLeapYear ; all 2x00's up to 2400 are not leaps
bit.w #0x10, r14 ; test for odd numbered decade
jz evenTens
oddtens ; in odd tens digit decades (10s,30s,50s,...)
and.w #0x0F, r14
cmp.w #0x02, r14 ; year 2 is a leap year
jeq setLeapYear
cmp.w #0x06, r14 ; year 6 is a leap year
jeq setLeapYear
jmp notLeapYear
evenTens ; in even tens digit decades (20s,40s,60s,...)
and.w #0x0F, r14
cmp.w #0x00, r14 ; year 0 is a leap year
jeq setLeapYear
cmp.w #0x04, r14 ; year 4 is a leap year
jeq setLeapYear
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -