]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - avr/timer.asm
* FAT buffer on ATmega328
[avrcpm.git] / avr / timer.asm
index 402c9c9093b1871dc2b7c93b3c2e96e956cc01d9..5a4cc12280bfe81584629340a7a22ac06f0fc6cd 100644 (file)
@@ -300,7 +300,7 @@ clkput_l:
        dec     temp3
        brne    clkput_l
        sei
-#if I2C
+#if I2C_SUPPORT
        rcall   rtc_set                 ; set hardware clock
 #endif
        ret
@@ -364,10 +364,10 @@ bcdbin2:
        swap    temp2
        andi    temp2,0x0f
        andi    temp,0x0f               ;temp  = low digit
-       mov     _tmp0,temp2
+       mov     r0,temp2
        ldi     temp2,10
-       mul     temp2,_tmp0             ;high digit * 10
-       add     temp,_tmp0              ;high digit * 10 + low digit
+       mul     temp2,r0                ;high digit * 10
+       add     temp,r0                 ;high digit * 10 + low digit
        pop     temp2
        ret
 
@@ -379,13 +379,13 @@ bcdbin4:
        ldi     temp2,100
        mul     temp,temp2
        pop     temp
-       mov     temp2,_tmp1
-       add     temp,_tmp0
+       mov     temp2,r1
+       add     temp,r0
        adc     temp2,_0
        ret
 
 
-#if I2C
+#if I2C_SUPPORT
 
 ; ----------------------------------------------
 ; Set software clock from hardware clock
@@ -410,7 +410,7 @@ rtc_get:
        brmi    rtc_get_e               ;i2c error
 
        ldd     temp3,z+1               ;save year
-       ldd     temp4,z+2
+       ldd     xl,   z+2
 
        ldi     temp2,2                 ;register pointer. 2 = secs
        std     z+1,temp2
@@ -420,6 +420,7 @@ rtc_get:
        tst     temp
        brmi    rtc_get_e
 
+       mov     temp2,xl                ;year century
        ldd     temp,z+4                ;get year
        rol     temp
        rol     temp
@@ -427,8 +428,8 @@ rtc_get:
        eor     temp,temp3
        andi    temp,0x03
        breq    rtc_get_1
-       inc     temp3
-       adc     temp4,_0
+       subi    temp3, low(-1)  
+       sbci    temp2, high(-1)
 rtc_get_1:
        ldiw    x,clock
        cli
@@ -451,7 +452,7 @@ rtc_get_1:
        rcall   bcdbin2
        st      x+,temp                 ;store month
        st      x+,temp3                ;store year
-       st      x+,temp4                ;store year century
+       st      x+,temp2                ;store year century
        sei
 
 rtc_get_e:
@@ -468,7 +469,7 @@ rtc_get_e:
 ; 
 ; Register:    temp2:  s
 ;              temp3:  m
-;              temp4:  h
+;              xh:     h
 ;              xl:     D
 ;              temp:   M
 ;              yl:     Yl
@@ -479,7 +480,7 @@ rtc_set:
        cli
        ldd     temp2,z+0               ;sec
        ldd     temp3,z+1               ;min
-       ldd     temp4,z+2               ;hours
+       ldd     xh,z+2                  ;hours
        ldd     xl,z+3                  ;day
        ldd     temp,z+4                ;month
        ldd     yl,z+5                  ;yearl
@@ -496,7 +497,7 @@ rtc_set:
        andi    xl,0xc0
        or      temp,xl                 ;   combine with day
        push    temp                    ;-2 save year/day
-       mov     temp,temp4
+       mov     temp,xh
        rcall   binbcd2
        push    temp                    ;-3 save hours
        mov     temp,temp3
@@ -535,7 +536,7 @@ rtc_set:
        out     sph,zh
 
        ret
-#endif
+#endif /* I2C_SUPPORT */
 
 ; ----------------------------------------------
 ; 
@@ -629,6 +630,8 @@ ts_loop:
 ;
        
 timer_print:
+       push    r15             ;
+       push    r14             ;
        push    yh
        push    yl
        ldiw    z,timer_ms
@@ -658,14 +661,14 @@ tp_s:
        ld      yh,z+
        sbc     temp2,yh
 
-       ldd     temp3,z+timerofs
+       ldd     r14,z+timerofs
        ld      yl,z+
-       sbc     temp3,yl
+       sbc     r14,yl
 
        sei
-       ldd     temp4,z+timerofs
+       ldd     r15,z+timerofs
        ld      yh,z+
-       sbc     temp4,yh
+       sbc     r15,yh
        
        printnewline
        printstring "Timer running. Elapsed: "
@@ -674,16 +677,20 @@ tp_s:
        printstring "."
        pop     temp
        pop     temp2
-       ldi     temp3,0
-       ldi     temp4,0
+       clr     r14
+       clr     r15
        rcall   print_ultoa
        printstring "s."
 
        pop     yl
        pop     yh
+       pop     r14
+       pop     r15
        ret
        
 uptime_print:
+       push    r15
+       push    r14
        ldiw    z,cnt_1ms
        cli
        ld      temp,z+
@@ -693,9 +700,9 @@ uptime_print:
        
        ld      temp,z+
        ld      temp2,z+
-       ld      temp3,z+
+       ld      r14,z+
        sei
-       ld      temp4,z+
+       ld      r15,z+
        
        printnewline
        printstring "Uptime: "
@@ -703,13 +710,15 @@ uptime_print:
        rcall   print_ultoa
        printstring ","
 
-       ldi     temp3,0
-       ldi     temp4,0
+       clr     r14
+       clr     r15
        pop     temp2
        pop     temp
        rcall print_ultoa
        printstring "s."
 
+       pop     r14
+       pop     r15
        ret
 
 ; vim:set ts=8 noet nowrap