;***************************************************************************************** ;Telescope Mount Controller III ;(c) Martin Cibulski ;**************************************************************************************** util_label_tab: .dw util_watch_call .db L_WRAM ,"UWACALL " .dw util_watch_var .db L_WRAM ,"UWAVAR " .dw util_watch_value .db L_BRAM ,"UWAVAL " .dw util_minstack .db L_WRAM ,"UMINSTACK " .dw 0 .db L_END , 0 ;*********************************************************************** ; ;Parameters: ;AKKU2/3/4/5 4 byte integer ;xh:xl ram location ;zh:zl character mask in program memory ;*********************************************************************** util_print_integer: push r18 push r19 push zl push zh movw r19:r18 ,r17:r16 ldi zl ,low(util_print_int_mask<<1) ldi zh ,high(util_print_int_mask<<1) ldi r16 ,low(9) ldi r17 ,high(9) call util_read_flash movw r17:r16 ,r19:r18 ldi r20 ,'+' tst r16 brpl util_print_int_positive com r17 ;make negative com r16 ldi r18 ,0xFF sub r17 ,r18 sbc r16 ,r18 ldi r20 ,'-' util_print_int_positive: rcall util_print_int_store ldi r18 ,high(10*60) ;10 degrees ldi r19 ,low(10*60) adiw xh:xl ,1 rcall util_print_int_count ldi r18 ,high(1*60) ldi r19 ,low(1*60) adiw xh:xl ,1 rcall util_print_int_count ldi r18 ,high(10) ldi r19 ,low(10) ldi r20 ,'0' adiw xh:xl ,2 rcall util_print_int_count ldi r18 ,high(1) ldi r19 ,low(1) adiw xh:xl ,1 rcall util_print_int_count pop zh pop zl pop r19 pop r18 ret util_print_int_mask: .db "+00:00 " .dd 600 .dd 60 .dd 10 .dd 1 ;*********************************************************************** util_print_int_count: ldi r20 ,'0' util_print_int_count_01: inc r20 sub r17 ,r19 sbc r16 ,r18 brcc util_print_int_count_01 dec r20 add r17 ,r19 adc r16 ,r18 ;*********************************************************************** util_print_int_store: ld r21 ,X st X ,r20 cp r20 ,r21 breq util_print_int_store_02 util_print_int_store_02: ret ;***************************************************************************************** .MACRO UWATCH_INIT ldi r16 ,high(@0) sts util_watch_var ,r16 ldi r16 ,low(@0) sts util_watch_var+1 ,r16 .ENDMACRO .MACRO UWATCH_SET call util_watch_set .ENDMACRO .MACRO UWATCH_CMP call util_watch .ENDMACRO .DSEG util_watch_call: .byte 2 util_watch_var: .byte 2 util_watch_value: .byte 1 .CSEG util_watch: push r24 push r25 push yl push yh in r24 ,SREG push r24 lds r24 ,util_watch_value ;check if value changed lds yh ,util_watch_var lds yl ,util_watch_var+1 ld r25 ,Y cp r25 ,r24 breq util_watch_nochange ;no sts util_watch_value ,r25 ;save new value in yh ,SPH in yl ,SPL ldd r24 ,Y+7 ;return adress, low ldd r25 ,Y+6 ;return adress, high sbiw r25:r24 ,2 ;adress of function call sts util_watch_call ,r25 sts util_watch_call+1 ,r24 util_watch_nochange: pop r24 out SREG ,r24 pop yh pop yl pop r25 pop r24 ret util_watch_set: push r25 push yl push yh lds yh ,util_watch_var lds yl ,util_watch_var+1 ld r25 ,Y sts util_watch_value ,r25 ;save new value pop yh pop yl pop r25 ret ;***************************************************************************************** .DSEG util_minstack: .byte 2 .CSEG util_minstack_check: push r16 push r17 push r18 push r19 push r20 in r20 ,sreg cli in r16 ,sph ;stackpointer SP in r17 ,spl lds r18 ,util_minstack+1 ;SP < smallest stackpointer ? cp r17 ,r18 lds r18 ,util_minstack cpc r17 ,r18 brcc util_msc_01 sts util_minstack ,r16 ;yes, save as new smallest stackpointer sts util_minstack+1 ,r17 util_msc_01: out sreg ,r20 ;restore interrupt flag pop r20 pop r19 pop r18 pop r17 pop r16 ret ;***************************************************************************************** ;Delay Routine ; util_delay_ms: push r17 push r18 .ifndef SIMULATE util_dms_00: ldi r17 ,21 util_dms_01: ldi r18 ,253 util_dms_02: dec r18 brne util_dms_02 dec r17 brne util_dms_01 dec r16 brne util_dms_00 .else clr r16 .endif pop r18 pop r17 ret ;***************************************************************************************** ;Delay Routine ; util_delay_microsec: nop nop nop nop nop nop nop nop nop nop dec r16 brne util_delay_microsec ret ;*****************************************************************************************