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

📄 rtc_calendar.asm

📁 24位AD压力实验板 protell99se打开
💻 ASM
📖 第 1 页 / 共 2 页
字号:
            cmp.w   #0x08,   r14            ; year 8 is a leap year
            jeq     setLeapYear
            jmp     notLeapYear
setLeapYear
            mov.b   #0x29,   &TI_FebDays
            ret
notLeapYear
            mov.b   #0x28,   &TI_FebDays
            ret

;============================================================================
; Returns hour in 24 hour format
;============================================================================
get24Hour
            tst.b  &TI_PM
            jnz    afternoon
            cmp.b  #0x12,    &TI_hour
            jeq    zero_hour
            mov.b  &TI_hour, r12
            ret
zero_hour   clr    r12
            ret
afternoon   mov.b  &TI_hour, r12
            cmp    #0x12,    r12
            jeq    return
            clrc
            dadd.b #0x12,    r12
            ret

;============================================================================
; Tests whether this is a dalights savings day in the US
;============================================================================
US_DS_TEST
           cmp.b    #0x02,   r14            ; see if it is 2
           jne      noDS
           tst.b    &TI_PM                  ; see if it is in AM
           jnz      noDS
           cmp.b    #0x03,   &TI_month      ; see if it is April
           jeq      firstSunday_April_US
           cmp.b    #0x09,   &TI_month      ; see if it is Oct
           jeq      lastSunday_October_US
           jmp      noDS

firstSunday_April_US
           call     #firstSunday
           tst.b    r15                     ; return register for function
           jnz      start_US_DS
           jmp      noDS
start_US_DS
           mov.b    #0x03,   &TI_hour
           mov.b    #0x01,   &TI_dayLightSavings
           ret

lastSunday_October_US
           tst.b    &TI_dayLightSavings
           jz       noDS
           call     #lastSunday
           tst.b    r15                     ; return register for function
           jnz      end_US_DS
           jmp      noDS
end_US_DS
           mov.b    #0x01,   &TI_hour
           clr.b    &TI_dayLightSavings
           ret


;============================================================================
; Tests whether this is a dalights savings day in the EU
;============================================================================
EU_DS_TEST
           cmp.b    #0x13,   r14            ; see if it is 1
           jne      noDS
           tst.b    &TI_PM                  ; see if it is in AM
           jnz      noDS
           cmp.b    #0x02,   &TI_month      ; see if it is March
           jeq      lastSunday_March_EU
           cmp.b    #0x09,   &TI_month      ; see if it is Oct
           jeq      lastSunday_October_EU
           jmp      noDS

lastSunday_March_EU
           call     #lastSunday
           tst.b    r15                     ; return register for function
           jnz      start_EU_DS
           jmp      noDS
start_EU_DS
           mov.b    #0x02,   &TI_hour
           mov.b    #0x01,   &TI_dayLightSavings
           ret

lastSunday_October_EU
           tst.b    &TI_dayLightSavings
           jz       noDS
           call     #lastSunday
           tst.b    r15                     ; return register for function
           jnz      end_EU_DS
           jmp      noDS
end_EU_DS
           mov.b    #0x12, &TI_hour
           clr.b    &TI_dayLightSavings
           ret

;============================================================================
; firstSunday - returns a 1 in r15 if this is the first sunday in a month, 0 otherwise
;============================================================================
firstSunday
          tst.b    &TI_dayOfWeek
          jnz      returnZero
          cmp.b    #0x08,    &TI_day
          jge      returnZero
          mov.b    #0x01,    r15
          ret

;============================================================================
; lastSunday - returns a 1 in r15 if this is the last sunday in a month with 31 days, 0 otherwise
;============================================================================
lastSunday
           tst.b    &TI_dayOfWeek
           jnz      returnZero
           cmp.b    #0x25,   &TI_day
           jl       returnZero
           mov.b    #0x01,   r15
           ret

returnZero clr      r15
           ret

;============================================================================
; setDate (y, m, d) - Call this function to set the date to a specified date
;============================================================================
setDate
            push.w  r6
            push.w  r7
            push.w  r8
            push.w  r11                     ; save scratch registers
            mov.b   #0x01,   &TI_dayLightSavings
            mov.b   r14,     r6             ; day into r6
            mov.b   r13,     r7             ; month into r7
            mov.w   r12,     r8             ; year into r8
            cmp.b   #0x03,   r7             ; see if month == Jan or Feb
            jge     skipMarch
            dec.w   r8                      ; if so, act as though it is the previous year (for leaps)
skipMarch
            mov.w   r8,      r11            ; r11 is working y value
            mov.w   r8,      r12            ; year
            rra.w   r12                     ; y / 4
            rra.w   r12

            add.w   r12,     r11            ; r11 = y + (y/4)
            mov.w   r8,      r12            ; y / 100
            mov.w   #0x64,   r14            ; 100 decimal
            call    #divide                 ; r12 = y/100
            sub.w   r12,     r11            ; r11 = y + (y/4)-(y/100)
            rra.w   r12                     ; y/400 = (y/100)>>2
            rra.w   r12
            add.w   r12,     r11
            dec.w   r7
            mov.b   TI_mNumbers(r7), r10
            inc.w   r7
            add.w   r10,     r11
            add.w   r6,      r11
            mov.w   r11,     r12
            mov.b   #0x07,   r14
            call    #modulus
            mov.b   r14,     &TI_dayOfWeek

            mov.b   r6,      r12
            call    #BIN2BCD4
            mov.b   r13,     &TI_day

            mov.b   r7,      r12
            dec.b   r12
            call    #BIN2BCD4
            mov.b   r13,     &TI_month

            cmp.b   #0x03,   r7             ; see if month == Jan or Feb
            jge     skipMarchReset
            inc.w   r8                      ; If so, year needs to be added to to reset
skipMarchReset
            mov.w   r8,      r12
            call    #BIN2BCD4
            mov.w   r13,     &TI_year
            call    #testLeap
            pop.w   r11
            pop.w   r8
            pop.w   r7
            pop.w   r6
            ret
;============================================================================
BIN2BCD4  ; Subroutine converts binary number R12 -> Packed 4- digit BCD R13
;           Input:  R12  0000 - 0FFFh, R15 working register
;           Output: R13  0000 - 4095
;============================================================================
            mov.w   #16,     r15            ; Loop Counter
            clr.w   r13                     ; 0 -> RESULT LSD
BIN1        rla.w   r12                     ; Binary MSB to carry
            dadd.w  r13,     r13            ; RESULT x2 LSD
            dec.w   r15                     ; Through?
            jnz     BIN1                    ; Not through
            ret                             ;
;============================================================================
; modulus - returns 14 = r12%r14
;============================================================================
modulus
            mov.w   r14,     r15
            mov.w   r12,     r13
            clr.w   r14
            mov.w   #0x1,    r12
labelM2     rla.w   r13
            rlc.w   r14
            cmp.w   r15,     r14
            jnc     labelM1
            sub.w   r15,     r14
labelM1     rlc.w   r12
            jnc     labelM2
            ret
;============================================================================
; divide - returns r12 = r12 / r14
;============================================================================
divide
            mov.w   r14,     r15
            mov.w   r12,     r13
            clr.w   r14
            mov.w   #0x1,    r12
label       rla.w   r13
            rlc.w   r14
            cmp.w   r15,     r14
            jnc     label2
            sub.w   r15,     r14
label2      rlc.w   r12
            jnc     label
            ret

            .end

⌨️ 快捷键说明

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