;
;          "mlan_3a.txt"    microLAN
;   ,    +5   GND
;              CRC8
;
;     DS18...20   
;  
;    
;
;------------------------------------------------------
;  " "   L_APD=0
;      :
;    ,   
;        L_APU=1, L_APD=0  M_DAT=1
;        L_APU  L_APU
;     M_DAT
;  L_APU=0 (    "")
;
;------------------------------------------------------
;
; ------------  ------------
;
; tm20      equ 7
; tm26      equ 9
; tm46      equ 16
; tm80      equ 27
; tm86      equ 29
; tm400     equ 134
; tm480     equ 161 ;    1 =1uS
; m_cfg9      equ 0b00011111 ;  9 ,   93,75 mS
; m_cfg10     equ 0b00111111 ;  10 ,   187,5 mS
; m_cfg11     equ 0b01011111 ;  11 ,   375 mS
; m_cfg12     equ 0b01111111 ;  12 ,   750 mS
; mk_conv_t   equ 0x44 ; (CONVERT T)    
; mk_rd_spad  equ 0xBE ; (READ SCRATCHPAD)   ""  DS18B20
; mk_wr_spad  equ 0x4E ; (WRITE SCRATCHPAD)   Th:Tl:Config   DS18B20
; mk_wr_eep   equ 0x48 ; (COPY SCRATCHPAD)   Th:Tl:Config
;                      ;   DS18B20  EEPROM DS18B20
; mk_rd_eep   equ 0xB8 ; (RECALL E2)   Th:Tl:Config
;                      ;  EEPROM DS18B20   DS18B20
; mk_scip_rom equ 0xCC ; (SKIP ROM)  "   "
;                      ;        
;                      ; 
; mk_read_rom equ 0x33 ; (READ ROM)   DS18B20   
;                      ;    (   8   
;                      ;  family code, 6  serial number   CRC )
; 
; M_DAT  equ 2 ; (0)    
; L_APU  equ 1 ; (1)    APU
; L_APD  equ 0 ; (3)    APD
;    flags
; m_erd   equ 0 ;   " mLAN  "
;             ;    
; m_ecrc  equ 1 ;     CRC   mLAN
;             ;    
;
; ---  GPR ---
;  udata_ovr    #define nameX nameY
; gradus_l    equ tmp_0 ;    
; gradus_h    equ tmp_1 ;    
; th_us1      equ tmp_2 ;    / 
; tl_us2      equ tmp_3 ;    / 
; m_cfg       equ tmp_4 ;    DS18B20
; m_res0      equ tmp_5 ; ,  0xFF
; m_res1      equ tmp_6 ; ,  0x0C
; m_res2      equ tmp_7 ; ,  0x10
; m_crc       equ tmp_8 ;   
; m_data      equ tmp_9 ;    /
; m_cntp      equ tmp_a ;   
; m_cntb      equ tmp_b ;   / 
; m_mcntt     equ tmp_c ;   (djnz cntt_mlan,$ = 2 )
; m_flags     equ tmp_d ;   uLAN
; m_tmp_fsr   equ tmp_e ;   fsr     m_
; m_summ      equ tmp_f ;     CRC
; port_m      equ PORTA ; ()  
;
;------------------------------------------------------------------------
;
MN   CODE
;
;---------------------------------------
; DTTC -   reset    
; ""
m_dttc
  bsf port_m,L_APU ;  
  bcf m_flags,m_erd
  nop
  nop
  nop
  bsf port_m,L_APD ;   
  movlw tm480
  movwf m_mcntt
tmm0
  decfsz m_mcntt,f
  goto tmm0 ;     480uS
  bcf port_m,L_APD ;  L_APD
  nop
  nop
  nop
  movlw .26 ;  M_DAT   +    2
  movwf m_cntb ;    M_DAT  20uS   480uS
m_tstpp
  movlw tm20
  movwf m_mcntt
m_tstpp1
  decfsz m_mcntt,f
  goto m_tstpp1
  btfss port_m,M_DAT ;   M_DAT=0
   goto wait_mdh
  decfsz m_cntb,f
  goto m_tstpp
  bsf m_flags,m_erd ;        - m_erd=1
wait_mdh
  btfss port_m,M_DAT ;     (M_DAT=1)
  goto wait_mdh
  bcf port_m,L_APU ;  
  movlw tm400
  movwf m_mcntt ;    400uS
tmm1
  decfsz m_mcntt,f
  goto tmm1
  return
;
;---------------------------------------
;
;      microLAN
;  call rxb1
;       m_data
m_rxb1
  bsf port_m,L_APU ;  
  nop
  nop
  movlw 8
  movwf m_cntb
rexik
   bsf port_m,L_APD ;   
   movlw 4
   movwf m_mcntt
tmm2
   decfsz m_mcntt,f
   goto tmm2
   bcf port_m,L_APD ;   
   movlw 3
   movwf m_mcntt
tmm2a
   decfsz m_mcntt,f
   goto tmm2a
   bcf STATUS,C
   btfss port_m,M_DAT
   goto grbt
   bsf STATUS,C
grbt
   rrf m_data,f
   movlw tm46
   movwf m_mcntt
tmm3
   decfsz m_mcntt,f
   goto tmm3
   decfsz m_cntb,f
   goto rexik
  bcf port_m,L_APU ;  
  nop
  nop
  return
;
;---------------------------------------
;
;      microLAN
;       m_data
;  call txb1
m_txb1
  bsf port_m,L_APU ;  
  nop
  nop
  movlw 8
  movwf m_cntb
texik
   bsf port_m,L_APD ;   
   movlw 4
   movwf m_mcntt
tmm4
   decfsz m_mcntt,f
   goto tmm4
   rrf m_data,f
   btfsc STATUS,C ;   L_APD=1 (M_DAT=STATUS.C=0)
   bcf port_m,L_APD ;  M_DAT=1  STATUS.C=1 (L_APD=0)
   movlw tm46
   movwf m_mcntt
tmm5
   decfsz m_mcntt,f
   goto tmm5 ;  ~45uS
   bcf port_m,L_APD ;  L_APD=0
   nop
   nop
    decfsz m_cntb,f
    goto texik
   bcf port_m,L_APU ;  
   nop
   nop
  return
;
;---------------------------------------
;
; CRC -     9  (8 +CRC)
;  8  -      
;      tmp_0-tmp_8 
;    !
m_crck
   bcf m_flags,m_ecrc ;   
   movf FSR,w
   movwf m_tmp_fsr ;   FSR
   movlw gradus_l ;     
   movwf FSR
   movlw 9
   movwf m_cntp ;    9 ( 8   )
   clrf m_summ ;   
l_crc1
    movlw 8
    movwf m_cntb ;   =8
    movf INDF,w ;      W
    movwf m_data ;      m_data
l_crc2
    xorwf m_summ,f ; xor  0,   
    rrf m_summ,w ;       0
    btfss STATUS,C
    goto p_crc1 ;    
    movlw 0x18
    xorwf m_summ,f ;    
p_crc1
    rrf m_summ,f ;      
    rrf m_data,w
    rrf m_data,f ;    
    movf m_data,w ;   W (   m_data)
   decfsz m_cntb,f ;    - 1
   goto l_crc2 ;   l_crc2  m_cntb   0
   incf FSR,f ;  
   decfsz m_cntp,f ;   - 1
   goto l_crc1 ;   l_crc1   
   tstf m_summ ;  CRC    0
   btfss STATUS,Z
   bsf m_flags,m_ecrc ;  m_summ   0  m_ecrc=1
  movf m_tmp_fsr,w
  movwf FSR ;  FSR  
  return
;
;---------------------------------------
;
;    
;
term_strt
  call m_dttc
  movlw mk_scip_rom
  movwf m_data
  call m_txb1
  movlw mk_conv_t
  movwf m_data
  call m_txb1
 return
;
;---------------------------------------
;
;      
;
m_rd9
   movf FSR,w
   movwf m_tmp_fsr ;   FSR
   movlw 9
   movwf m_cntp
   movlw gradus_l
   movwf FSR
    call m_dttc
    movlw mk_scip_rom
    movwf m_data
    call m_txb1
    movlw mk_rd_spad
    movwf m_data
    call m_txb1
l_rd9
   call m_rxb1
   movf m_data,w
   movwf INDF
   incf FSR,f
   decfsz m_cntp,f
   goto l_rd9
  movf m_tmp_fsr,w
  movwf FSR ;  FSR  
  return
;
;---------------------------------------
;