;
;         "lb_ext_disp.txt"      
;
;------------------------------------------------------------
;
WDT_off:
      wdr
        ; Clear WDRF in MCUSR
      in tmp0,MCUSR
      cbr tmp0,(1<<WDRF)
      out MCUSR,tmp0
        ; Write logical one to WDCE and WDE
        ; Keep old prescaler setting to prevent unintentional Watchdog Reset
      in  tmp0,WDTCSR
      ori tmp0,(1<<WDCE)|(1<<WDE)
      out WDTCSR,tmp0
        ; Turn off WDT
      cbr tmp0,(1<<WDE)
      out WDTCSR,tmp0
    ret
;------------------------------------------------------------
;    bfr1:bfr0,   
; rdbf+0=, rdbf+1=, rdbf+2=, rdbf+3=
; rdbf+5=  ( )
bin_dec:
	push tmp0
  push tmp1
  push tmp3
 x10t:
   ldi tmp1,high(10000)
   ldi tmp0,low(10000)
  rcall xt_rept
   sts (dp_rdbf+4),tmp3
 x1t:
   ldi tmp1,high(1000)
   ldi tmp0,low(1000)
  rcall xt_rept
   sts (dp_rdbf+3),tmp3
 x10d:
   clr tmp1
   ldi tmp0,100
  rcall xt_rept
   sts (dp_rdbf+2),tmp3
 x1d:
   ldi tmp0,10
   clr tmp3
  xt_b:
    inc tmp3
    sub bfr0,tmp0
    brcc xt_b
    add bfr0,tmp0
    dec tmp3
  sts (dp_rdbf+1),tmp3
  sts dp_rdbf,bfr0
	pop tmp3
	pop tmp1
	pop tmp0
 ret
;----------------------
xt_rept:
   clr tmp3
 xt_a:
    inc tmp3
    sub bfr0,tmp0
    sbc bfr1,tmp1
    brcc xt_a
   add bfr0,tmp0
   adc bfr1,tmp1
   dec tmp3
  ret
;
;------------------------------------------------------------
;
bin_seg:
  push tmp0
  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 tmp0
 ret
;----------------------
sg_rept:
   ldwi z,znak
   ld tmp0,x
   add zl,tmp0
   brcc sg_rt0
   inc zh
 sg_rt0:
   lsl zl
   rol zh
   lpm tmp0,z
   st x+,tmp0
  ret
;
;------------------------------------------------------------
;
;   CRC7 Dallas uLAN (control)
crck:
   ldwi x,net_buf ; x=r0
   ldi tmp0,(0xFF - (1<<er_crc))
   and dp_flags,tmp0 ; er_crc=0
   clr tmp0 ;
   clr tmp1 ;
   clr tmp3 ;
   ldi cntw,8
 big_lp:
    ld tmp0,x+ ;      tmp0
    mov tmp1,tmp0 ;      tmp1
    ldi cntb,8 ;   =8
 low_lp:
     eor tmp0,tmp3 ; xor  0,   tmp0
     ror tmp0 ;  xor  0    
              ;   
     brbc SREG_C,crcpt0 ;       0
              ;     crcpt0
     ldi tmp0,0x18
     eor tmp3,tmp0 ;    
 crcpt0:
     ror tmp3 ;      Y
    ror tmp1 ;    ,
             ;      
     mov tmp0,tmp1 ;   tmp0
      dec cntb
      brne low_lp
       dec cntw
        brne big_lp
    tst tmp3
    breq crcpt1 ; jz - norma
    ldi tmp0,(1<<er_crc)
    or dp_flags,tmp0 ; er_crc=1
  crcpt1:
    ret
;
;------------------------------------------------------------
;