3 ; Copyright (C) 2010 Leo C.
5 ; This file is part of avrcpm.
7 ; avrcpm is free software: you can redistribute it and/or modify it
8 ; under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation, either version 3 of the License, or
10 ; (at your option) any later version.
12 ; avrcpm is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
17 ; You should have received a copy of the GNU General Public License
18 ; along with avrcpm. If not, see <http://www.gnu.org/licenses/>.
34 ; don't change order here, clock put/get depends on it.
35 cntms_out: ; register for ms
37 utime_io: ; register for uptime.
44 .equ timer_size = timer_top - timer_base
46 .equ utofs = cnt_1ms-cntms_out
47 .equ timerofs = cnt_1ms-timer_ms
52 .byte 7 ;Format (bin): s m h D M YY
53 .equ clkofs = clock-clk_out
57 ; ------------- system timer 1ms ---------------
60 ; Timer/Counter1 Compare Match B interrupt
74 #if DRAM_8BIT /* Implies software uart */
75 lds zl,srx_char_to ;try to decrement character timout
77 brcs syscl0 ;timer was 0 before (not running)
78 sts srx_char_to,zl ;timer is running, store new value
94 lds zl,cnt_1ms ;count milli seconds
99 cpi zl,low(1000) ;one second ?
100 ldi zl,high(1000) ;doesn't change flags
149 ldiw z,dayspm_tab*2 - 1
150 lds temp,clock+4 ;month
153 lpm zh,z ;days this month
155 brne syscl_clknl ;february, may be leap year
156 lds zl,(clock+5) ;year
174 lds zl,clock+5 ;low year
178 lds zl,clock+6 ;high year
194 .db 31,28,31,30,31,30
195 .db 31,31,30,31,30,31
197 ; ----------------------------------------------
204 sts delay_timer1,temp
206 lds temp,delay_timer1
211 ; ----------------------------------------------
216 breq clkget_copy ;lowest byte requestet, latch clock
249 ret ;req. byte in temp
251 ; ----------------------------------------------
259 breq clkput_copy ;lowest byte stored, latch clock
288 rcall rtc_set ; set hardware clock
293 ; ----------------------------------------------
295 ; convert binary to bcd
296 ; (only range 0 - 99)
344 ; convert bcd to binary
348 mov temp2,temp ;temp2 = high digit
351 andi temp,0x0f ;temp = low digit
354 mul temp2,_tmp0 ;high digit * 10
355 add temp,_tmp0 ;high digit * 10 + low digit
375 ; ----------------------------------------------
376 ; Set software clock from hardware clock
379 push _0 ;Placeholder for month/weekday
383 ldi temp,0x10 ;register address
384 push temp ;save reg adr/placeholder for sec
387 ldi temp,0xA0 ;PCF8583 slave address
393 rcall i2c_read ;get year (stored in RTC-RAM addr. 10h)
397 ldd temp3,z+1 ;save year
400 ldi temp2,2 ;register pointer. 2 = secs
408 ldd temp,z+4 ;get year
421 ldd temp,z+1 ;get seconds
424 ldd temp,z+2 ;get minutes
427 ldd temp,z+3 ;get hours
430 ldd temp,z+4 ;get day
434 ldd temp,z+5 ;get months
437 st x+,temp ;store month
438 st x+,temp3 ;store year
439 st x+,temp4 ;store year century
451 ;----------------------------------------------
452 ; Set hardware clock from software clock
474 push temp ;-1 save month
477 mov xl,yl ; least significant 2 bits of year
482 or temp,xl ; combine with day
483 push temp ;-2 save year/day
486 push temp ;-3 save hours
489 push temp ;-4 save min
492 push temp ;-5 save sec
494 push _0 ;-6 1/10s, 1/100s
495 ldi temp,0x84 ; stop count, alarm enable
497 push _0 ;-8 register address
500 ldi temp,0xA0 ; PCF8583 slave address
505 ldi temp,0x04 ;enable counting
509 std z+3,yh ;store year in RTC RAM
516 addiw z,8 ;remove buffer from stack
525 ; ----------------------------------------------
530 subi temp2,TIMER_MSECS
531 brcs utimget_end ;Port number in range?
533 breq utimget_copy ;lowest byte requestet, latch clock
535 brsh utimget_end ;Port number to high?
560 brcs utput__end ;Port number in range?
565 cpi temp,starttimercmd
567 cpi temp,quitTimerCmd
569 cpi temp,printTimerCmd
584 breq utput__copy ;lowest byte requestet, latch clock
586 brsh utput__end ;Port number to high?
631 ; put ms on stack (16 bit)
666 printstring "Timer running. Elapsed: "
698 printstring "Uptime: "
712 ; vim:set ts=8 noet nowrap