⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtc_calendar.s43

📁 msp430板子红外驱动
💻 S43
📖 第 1 页 / 共 2 页
字号:
;******************************************************************************
;   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 implimented
;
;   Typical Cycle Count per function:
;   incrementSeconds            15
;   incrementMinutes            15
;   incrementHours              28
;   incrementDays               38
;   incrementMonths             15
;   incrementYears              37
;   setDate                     815
;
;   Memory Usage:               645 bytes
;
;   L. Westlund
;   Version    1.2
;   Texas Instruments, Inc
;   January 2005
;******************************************************************************
;Change log
;
;1.3 - Passes all Suite tests - L.Westlund
;1.2 - Added setDate and daylight savings time functionality - L.Westlund
;1.1 - Condensed code for size by removing jumps - L.Westlund
;1.0 - Inital version - L.Westlund
;******************************************************************************


            ;Variables
            MODULE    RTC
            PUBLIC    second
            PUBLIC    minute
            PUBLIC    hour
            PUBLIC    day
            PUBLIC    month
            PUBLIC    year
            PUBLIC    PM
            PUBLIC    FebDays
            PUBLIC    dayOfWeek
            PUBLIC    dayLightZone
            ;Functions
            PUBLIC  incrementSeconds
            PUBLIC  incrementMinutes
            PUBLIC  incrementHours
            PUBLIC  incrementDays
            PUBLIC  incrementMonths
            PUBLIC  incrementYears
            PUBLIC  testLeap
            PUBLIC  setDate

            RSEG      DATA16_N
year        DS 2
second      DS 1
minute      DS 1
hour        DS 1
day         DS 1
month       DS 1
PM          DS 1
FebDays     DS 1
dayOfWeek   DS 1
dayLightZone DS 1

            RSEG      DATA16_ID
;            DC16      0x2004
;            DC8       0x00
;            DC8       0x00
;            DC8       0x12
;            DC8       0x01
;            DC8       0x00
;            DC8       0x00
;            DC8       0x29
;            DC8       0x00
;            DC8       0x01
            RSEG      DATA16_C
daysInMonth DC8 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30
            DC8 0x31, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x30, 0x31
mNumbers    DC8 0x00, 0x03, 0x02, 0x05, 0x00, 0x03, 0x05, 0x01, 0x04, 0x06, 0x02, 0x04

            RSEG    CODE                    ; Code is relocatable
;============================================================================
; incrementSeconds
;============================================================================
incrementSeconds
            clrc
            dadd.b  #0x01,   &second        ; tick one second
            cmp.b   #0x60,   &second        ; see if we've hit 60 seconds
            jne     return                  ; if not, return
            clr.b   &second                 ; if so, go back to 00
                                            ; fall down to increment minutes
;============================================================================
; incrementMinutes
;============================================================================
incrementMinutes
            clrc
            dadd.b  #0x01,   &minute        ; tick one minute
            cmp.b   #0x60,   &minute        ; see if we've hit 60 minutes
            jne     return                  ; if not, return
            clr.b   &minute                 ; if so, go back to 00
                                            ; fall down to increment hours
;============================================================================
; incrementHours
;============================================================================
incrementHours
            clrc
            mov.b   &hour,   r14
            dadd.b  #0x01,   r14
            cmp.b   #0x01,   &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   &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,   &PM            ; change PM value
returnHours
            mov.b   r14,     &hour
return      ret
notSwitchPM
            cmp.b   #0x13,   r14            ; see if we've hit 13
            jne     returnHours             ; if not, return
            mov.b   #0x01,   &hour          ; if so, 13 o'clock == 1 o'clock
            ret                             ; return to save CPU cycles
rollAM
            clr.b   &PM                     ; clear PM, now it is AM
            mov.b   r14,    &hour           ; save hour value
                                            ; fall down to increment days

;============================================================================
; incrementDays
;============================================================================
incrementDays
            clrc
            dadd.b  #0x01,   &day           ; add a day
            cmp.b   #0x06,   &dayOfWeek     ; see if it is Sat, end of week
            jl      notSat
            mov.b   #0xFF,   &dayOfWeek
notSat      add.b   #0x01,   &dayOfWeek
            mov.w   #daysInMonth, r13       ; move the destination addr (word) to r13
            mov.b   &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,   &month         ; month '01' == FEB
            jne     compareDays             ; special case for Feb due to leap years
getFebDays
            mov.b   &FebDays, r14           ; r14 holds the number of days in the current Feb
compareDays
            sub.b   &day,    r14            ; r14 = number days in Month - current day value
            jge     return                  ; if r14 > 0 ... we still have days left
            mov.b   #0x01,   &day           ; if not, roll to day 1
                                            ; fall down to increment months

;============================================================================
; incrementMonths
;============================================================================
incrementMonths
            clrc
            dadd.b  #0x01,   &month         ; increment month counter
            cmp.b   #0x12,   &month         ; see if we've gone past the last month (11)
            jl      return                  ; if no return
resetMonth
            clr.b   &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,   &year          ; add 1 to the year
testLeap    mov.w   &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
            cmp.w   #0x08,   r14            ; year 8 is a leap year
            jeq     setLeapYear
            jmp     notLeapYear
setLeapYear
            mov.b   #0x29,   &FebDays
            ret
notLeapYear
            mov.b   #0x28,   &FebDays

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -