;DS18B20.inc CBLOCK R_Bits R_Bytes R_Dato R_TMSB R_TLSB R_TL R_Int R_Med R_Ext R_Mando R_Cuenta R_Signo R_Temp R_Valor R_Band R_Frac R_Apunta R_Cen R_Dec R_Uni ENDC #DEFINE Bus PORTA,3 C_Salta equ 0xcc C_onverT equ 0x44 C_AlaAl equ 0x4e ;comando escribir alarmas C_TL equ 0x83 ;-3 grados centigrados C_TH equ 0x28 ;+40 grados centigrados C_Bits equ 0x8 ;bits por registro C_Bytes equ 0x2 C_LeePiz equ 0xbe menos equ 0xfa blanco equ 0x20 cero equ 0x30 punto equ 0x2e cinco equ 0x35 ALTA_IMP MACRO ;entrada, alta impedancia BANCO1 bsf Bus ;bus va a nivel alto por pull-up BANCO0 ENDM BAJO MACRO ;salida BANCO1 bcf Bus ; BANCO0 bcf Bus ;bus va a nivel bajo ENDM Tempe call Saludo call Salta call Escribe call ConverT call Escribe call Sennal call Saludo call Salta call Escribe call LeePiza ;lee pizarra call Escribe goto LeeByte ReTemp movwf R_Temp goto LeeByte ReSig movwf R_Signo call Saludo call Conver call Salida call Flotante return Saludo call PulReset call PulPrese return PulReset ALTA_IMP BAJO call Ret500u ALTA_IMP call Ret20u return PulPrese Prese btfsc Bus goto Prese Recu btfss Bus goto Recu return Salta movlw C_Salta return Escribe movwf R_Mando movlw 0x8 movwf R_Cuenta ALTA_IMP Envia BAJO Gira rrf R_Mando,f btfss STATUS,C goto ManCero ManUno ALTA_IMP goto Espera ManCero BAJO Espera call Ret50u ALTA_IMP Decrece decfsz R_Cuenta,f goto Envia return LeePiza movlw C_LeePiz return LeeByte movlw 0x8 movwf R_Bytes clrf R_Dato ALTA_IMP LeeBit BAJO nop ALTA_IMP call Ret10u bcf STATUS,C btfsc Bus bsf STATUS,C rrf R_Dato,f call Ret50u ALTA_IMP decfsz R_Bytes goto LeeBit movf R_Dato,w btfsc R_Band,2 goto Subsec ;ir a vueltas subsecuentes movwf R_TLSB bsf R_Band,2 ;bandera para identificar primera vuelta bsf R_Band,3 ;bandera para identificar byte de signo goto ReTemp ;o byte del valor de temperatura Subsec btfsc R_Band,3 goto Libram subwf R_TLSB,w btfsc STATUS,Z goto cabo movfw R_Dato movwf R_TLSB bsf R_Band,3 goto ReTemp Libram bcf R_Band,3 goto ReSig Sennal ALTA_IMP EspSen btfss Bus ;0 en proceso, 1 hecha la conversion goto EspSen call Ret1s nop return ConverT movlw C_onverT return Conver call SigVal call Signo call HayFrac call HeBCD call ASCII return SigVal clrf R_Frac movlw 0x3 movwf R_Cuenta Recorre bsf STATUS,C rrf R_Signo,f rrf R_Temp,f rrf R_Frac,f decfsz R_Cuenta goto Recorre bcf STATUS,C rrf R_Temp,f rrf R_Frac,f movlw 0x4 movwf R_Cuenta Acomoda bcf STATUS,C rrf R_Frac,f decfsz R_Cuenta goto Acomoda return Signo bcf R_Band,0 bcf STATUS,Z movlw 0xff andwf R_Signo,w btfsc STATUS,Z goto SigNeg SigPos bsf R_Band,0 return SigNeg bcf R_Band,0 return HayFrac bcf STATUS,Z movlw 0x0 iorwf R_Frac,w btfsc STATUS,Z goto NoFrac movlw 0xc andwf R_Frac,w btfsc STATUS,Z goto Frac1 btfsc R_Frac,3 goto Para5u8 btfss R_Frac,2 goto Para5 goto Para3 Para5u8 btfsc R_Frac,2 goto Para8 goto Para5 Para3 call Frac3 goto EsFrac Para5 call Frac5 goto EsFrac Para8 call Frac8 goto EsFrac Frac1 movlw 0x31 movwf Digito3 return Frac3 movlw 0x33 movwf Digito3 return Frac5 movlw 0x35 movwf Digito3 return Frac8 movlw 0x38 movwf Digito3 return NoFrac bcf R_Band,1 return EsFrac bsf R_Band,1 return HeBCD movfw R_Temp clrf R_Cen clrf R_Dec movwf R_Uni Resta movlw 0xa subwf R_Uni,w btfss STATUS,C goto BCDNib IncDec movwf R_Uni incf R_Dec,f movlw 0xa subwf R_Dec,w btfss STATUS,C goto Resta IncCen clrf R_Dec incf R_Cen,f goto Resta BCDNib swapf R_Dec,w addwf R_Uni,w return ASCII movlw 0x30 iorwf R_Cen iorwf R_Dec iorwf R_Uni return Salida btfsc R_Band,0 ; es Neg? goto Pos Neg movlw menos Pos ;movf R_Cen,w ;movwf PORTB ;call puda Dece movf R_Dec,w movwf Digito1 Uni movf R_Uni,w movwf Digito2 btfsc R_Band,1 ; es Frac? goto Frac goto Nom Frac movfw Digito3 return Nom movlw cero movwf Digito3 return Flotante movlw punto movwf Punto return espacio movlw 0x5 goto MICROS Ret10u movlw 0x2 goto MICROS Ret13u movlw 0x3 nop goto MICROS Ret20u movlw 0x5 nop goto MICROS Ret50u movlw 0xf goto MICROS Ret60u movlw 0x13 goto MICROS Ret70u movlw 0x16 goto MICROS Ret500u movlw 0xA6 goto MICROS MICROS movwf R_Int Bucle decfsz R_Int,f goto Bucle return Ret50m movlw 0X40 ;50 milisegundos goto MILIS MILIS movwf R_Ext Ext movlw 0xff movwf R_Int Int decfsz R_Int,f goto Int decfsz R_Ext,f goto Ext return Ret1s movlw 0x6 goto SEG SEG movwf R_Ext Peri movlw 0xd9 movwf R_Med Medio movlw 0xff movwf R_Int Inter decfsz R_Int,f goto Inter decfsz R_Med,f goto Medio decfsz R_Ext,f goto Peri return