;
;         "lb_ext_disp.txt"      
;
;------------------------------------------------------------
;
WDT_off:
      wdr
        ; Clear WDRF in MCUSR
      in r16,MCUSR
      cbr r16,(1<<WDRF)
      out MCUSR,r16
        ; Write logical one to WDCE and WDE
        ; Keep old prescaler setting to prevent unintentional Watchdog Reset
      in  r16,WDTCSR
      ori r16,(1<<WDCE)|(1<<WDE)
      out WDTCSR,r16
        ; Turn off WDT
      cbr r16,(1<<WDE)
      out WDTCSR,r16
    ret
;------------------------------------------------------------
;    bfr1:bfr0,   
; rdbf+0=, rdbf+1=, rdbf+2=, rdbf+3=
; rdbf+5=  ( )
bin_dec:
	push r16
  push r17
  push r19
 x10t:
   ldi r17,high(10000)
   ldi r16,low(10000)
  rcall xt_rept
   sts (dp_rdbf+4),r19
 x1t:
   ldi r17,high(1000)
   ldi r16,low(1000)
  rcall xt_rept
   sts (dp_rdbf+3),r19
 x10d:
   clr r17
   ldi r16,100
  rcall xt_rept
   sts (dp_rdbf+2),r19
 x1d:
   ldi r16,10
   clr r19
  xt_b:
    inc r19
    sub bfr0,r16
    brcc xt_b
    add bfr0,r16
    dec r19
  sts (dp_rdbf+1),r19
  sts dp_rdbf,bfr0
	pop r19
	pop r17
	pop r16
 ret
;----------------------
xt_rept:
   clr r19
 xt_a:
    inc r19
    sub bfr0,r16
    sbc bfr1,r17
    brcc xt_a
   add bfr0,r16
   adc bfr1,r17
   dec r19
  ret
;
;------------------------------------------------------------
;
bin_seg:
  push r16
  push zl
  push zh
  push xl
  push xh
  ldwi x,dp_rdbf
 rcall sg_rept ; x1
 rcall sg_rept ; x10
 rcall sg_rept ; x100
 rcall sg_rept ; x1000
  pop xh
  pop xl
  pop zh
  pop zl
  pop r16
 ret
;----------------------
sg_rept:
   ldwi z,znak
   ld r16,x
   add zl,r16
   brcc sg_rt0
   inc zh
 sg_rt0:
   lsl zl
   rol zh
   lpm r16,z
   st x+,r16
  ret
;
;------------------------------------------------------------
;