; 689 - 256 = 433 --> 433 * (355/1023) = 15155 --> 151°C
; 1023 - 000 = 1023 --> 1023 * (355/1023) = 35805 --> 358°C
; Si AN0 > AN1 = temperatura sobre cero grados centígrados. Temp = +XXX°C
; Si AN0 < AN1 = temperatura bajo cero grados centígrados. Temp = -XXX°C
;
; Si AN0 > AN1 = (Valor de AN0) - (Valor de AN1) = (Valor Temp.)
; Si AN0 < AN1 = (Valor de AN1) - (Valor de AN0) = (Valor Temp.)
;
; Una vez obtenido el Valor Temp:
;
; (Valor Temp.) * (355 / 1023) = Temp ---> si usamos conversor de 10 bits
; (Valor Temp.) * (355 / 255) = Temp ---> si usamos conversor de 8 bits
;
; donde: 355 = VREF+ * 100
; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
; | |
; | ARREGLO DE TEMPERATURA +/- XXX °C |
; | |
; | IF = +XXX °C = 366/1023 = 358 --> 36 = 24h |
; | |
; | IF = -XXX °C = 355/1023 = 347 --> 35 = 23h |
; | |
; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LIST P=16F877A
INCLUDE <P16F877A.INC>
errorlevel -207
errorlevel -302
errorlevel -306
CBLOCK 0X20
ART_BIN_H
ART_BIN_L
ART_CNTBCDX
ART_UNIDAD
ART_DECENT
ART_CENTEN
ART_UNMILL
ART_DEMILL
ART_CONTBITS
ART_COCIN_H
ART_COCIN_L
ART_RESTO
ART_DIVID_L
ART_DIVID_H
ART_DIVISOR
ART_MULTIR_H
ART_MULTIR_L
ART_MULTID_H
ART_MULTID_L
ART_PRODC_2H
ART_PRODC_2L
ART_PRODC_1H
ART_PRODC_1L
ART_OPERN_1H
ART_OPERN_1L
ART_OPERN_2H
ART_OPERN_2L
DT_ADRESH
DT_ADRESL
BIT_QIF
DTMP1
COMP_H1
COMP_L1
COMP_H2
COMP_L2
TEMP_H2
TEMP_L2
TEMP_H1
TEMP_L1
TMD1
TMD2
ENDC
ORG 2007h
DW 3F7Ah
ORG 0000h
BANKSEL TRISA
CLRF TRISB
MOVLW 0XC5 ; ADFM = 1 ADRESL |8| ADRESH |2|
MOVWF ADCON1 ; PCFGX = 5
BSF TRISA,0 ; AN0 = ANALOG INPUT
BSF TRISA,1 ; AN1 = ANALOG INPUT
BSF TRISA,3 ; AN3 = VREF+
BANKSEL PORTA
CLRF PORTB
CALL LCD_INNI
MOVLW 0C9h
CALL SEND_CMMD
MOVLW 0DFh
CALL SEND_DATA
MOVLW 'C'
CALL SEND_DATA
RETORNA MOVFW COMP_H2
XORWF TEMP_H2,W
BNZ IGUALQ1
MOVFW COMP_L2
XORWF TEMP_L2,W
BNZ IGUALQ1
MOVFW COMP_H1
XORWF TEMP_H1,W
BNZ IGUALQ1
MOVFW COMP_L1
XORWF TEMP_L1,W
BNZ IGUALQ1
MOVLW 0X81 ; Fosc/64, Canal 0, A/D activo
MOVWF ADCON0
CALL READ_ADC
MOVFW DT_ADRESH
MOVWF COMP_H2
MOVFW DT_ADRESL
MOVWF COMP_L2
MOVLW 0X89 ; Fosc/64, Canal 1, A/D activo
MOVWF ADCON0
CALL READ_ADC
MOVFW DT_ADRESH
MOVWF COMP_H1
MOVFW DT_ADRESL
MOVWF COMP_L1
GOTO RETORNA
IGUALQ1
MOVLW 0X81 ; Fosc/64, Canal 0, A/D activo
MOVWF ADCON0
CALL READ_ADC
MOVFW DT_ADRESH
MOVWF COMP_H2
MOVWF TEMP_H2
MOVFW DT_ADRESL
MOVWF COMP_L2
MOVWF TEMP_L2
MOVLW 0X89 ; Fosc/64, Canal 1, A/D activo
MOVWF ADCON0
CALL READ_ADC
MOVFW DT_ADRESH
MOVWF COMP_H1
MOVWF TEMP_H1
MOVFW DT_ADRESL
MOVWF COMP_L1
MOVWF TEMP_L1
MOVFW COMP_H1
XORWF COMP_H2,W
BZ CUT_X1
MOVFW COMP_H1
SUBWF COMP_H2,W
BC UNO_X ; COMP_H2 ES MAYOR
GOTO DOS_X ; COMP_H1 ES MAYOR O IGUAL
CUT_X1 MOVFW COMP_L1
XORWF COMP_H1,W
BZ UNO_X
MOVFW COMP_L1
SUBWF COMP_L2,W
BC UNO_X ; COMP_L2 ES MAYOR
GOTO DOS_X ; COMP_L1 ES MAYOR O IGUAL
UNO_X BSF BIT_QIF,0
MOVFW COMP_H2
MOVWF ART_OPERN_2H ; DATO
MOVFW COMP_L2 ; MAYOR
MOVWF ART_OPERN_2L ;
MOVFW COMP_H1
MOVWF ART_OPERN_1H ; DATO
MOVFW COMP_L1 ; MENOR
MOVWF ART_OPERN_1L ;
MOVLW 000h
MOVWF ART_MULTIR_H
MOVLW 023h
MOVWF ART_MULTIR_L
GOTO TRES_X
DOS_X BCF BIT_QIF,0
MOVFW COMP_H1
MOVWF ART_OPERN_2H ; DATO
MOVFW COMP_L1 ; MAYOR
MOVWF ART_OPERN_2L ;
MOVFW COMP_H2
MOVWF ART_OPERN_1H ; DATO
MOVFW COMP_L2 ; MENOR
MOVWF ART_OPERN_1L ;
MOVLW 000h
MOVWF ART_MULTIR_H
MOVLW 024h
MOVWF ART_MULTIR_L
TRES_X CALL ARIT_RESTA_16BIT ; RES = ART_OPERN_2H/2L
MOVFW ART_OPERN_2H
MOVWF ART_MULTID_H
MOVFW ART_OPERN_2L
MOVWF ART_MULTID_L
CALL ARIT_MULTIPLICA_16BIT
MOVFW ART_PRODC_1H
MOVWF ART_BIN_H
MOVFW ART_PRODC_1L
MOVWF ART_BIN_L
CALL ARIT_BIN_BCD_16BIT
MOVLW 0C5h
CALL SEND_CMMD
BTFSS BIT_QIF,0
GOTO NTX1
GOTO NTX2
NTX1 MOVLW '-'
CALL SEND_DATA
GOTO NTX3
NTX2 MOVLW '+'
CALL SEND_DATA
NTX3 MOVFW ART_DEMILL
ADDLW 030h
CALL SEND_DATA
MOVFW ART_UNMILL
ADDLW 030h
CALL SEND_DATA
MOVFW ART_CENTEN
ADDLW 030h
CALL SEND_DATA
GOTO RETORNA
;::::::::::::: Zone of Sub-Rutine :::::::::::::
READ_ADC MOVLW .10
CALL TM_XML
BSF ADCON0,GO_DONE
BTFSC ADCON0,GO_DONE
GOTO $-1
MOVFW ADRESH
MOVWF DT_ADRESH
BANKSEL ADRESL
MOVFW ADRESL
BANKSEL PORTA
MOVWF DT_ADRESL
RETURN
LCD_INNI CLRF PORTB
CALL TM_20M
MOVLW b'00110000'
MOVWF PORTB
CALL ENABLE_CMD
MOVLW .5
CALL TM_XML
MOVLW b'00110000'
MOVWF PORTB
CALL ENABLE_CMD
CALL TM_XUS
MOVLW b'00110000'
MOVWF PORTB
CALL ENABLE_CMD
MOVLW .5
CALL TM_20US
MOVLW b'00100000'
MOVWF PORTB
CALL ENABLE_CMD
MOVLW .5
CALL TM_20US
MOVLW b'00101000' ; LCD de 2 líneas
CALL SEND_CMMD ; y caracteres de 5x7 puntos.
MOVLW b'00000001' ; Pantalla encendida y limpia
CALL SEND_CMMD ; Cursor al principio de la línea 1.
MOVLW b'00001100' ; Cursor apagado.
CALL SEND_CMMD
MOVLW b'00000110' ; Cursor en modo incrementar.
CALL SEND_CMMD
RETURN
SEND_DATA MOVWF DTMP1
ANDLW 0F0h
IORLW 0X04
MOVWF PORTB
CALL ENABLE_DTT
SWAPF DTMP1,W
ANDLW 0F0h
IORLW 0X04
MOVWF PORTB
CALL ENABLE_DTT
RETURN
SEND_CMMD MOVWF DTMP1
ANDLW 0F0h
MOVWF PORTB
CALL ENABLE_CMD
SWAPF DTMP1,W
ANDLW 0F0h
MOVWF PORTB
CALL ENABLE_CMD
RETURN
ENABLE_CMD BSF PORTB,3
MOVLW .2
CALL TM_XML
BCF PORTB,3
MOVLW .2
CALL TM_XML
RETURN
ENABLE_DTT BSF PORTB,3
MOVLW .11
CALL TM_20US
BCF PORTB,3
MOVLW .11
CALL TM_20US
RETURN
ARIT_BIN_BCD_16BIT
MOVF ART_BIN_H,W
MOVWF ART_DIVID_H
MOVF ART_BIN_L,W
MOVWF ART_DIVID_L
MOVLW .5
MOVWF ART_CNTBCDX
MOVLW ART_UNIDAD
MOVWF FSR
ARIT_DIGITOBCD
MOVLW .10
MOVWF ART_DIVISOR
CALL ARIT_DIVIDE_16BIT
MOVWF INDF
INCF FSR,F
MOVF ART_COCIN_H,W
MOVWF ART_DIVID_H
MOVF ART_COCIN_L,W
MOVWF ART_DIVID_L
DECFSZ ART_CNTBCDX,F
GOTO ARIT_DIGITOBCD
RETURN
ARIT_DIVIDE_16BIT
CLRF ART_COCIN_H
CLRF ART_COCIN_L
CLRF ART_RESTO
MOVLW .16
MOVWF ART_CONTBITS
ARIT_DIVIDEBIT16
RLF ART_DIVID_L,F
RLF ART_DIVID_H,F
RLF ART_RESTO,F
MOVF ART_DIVISOR,W
SUBWF ART_RESTO,W
BTFSC STATUS,C
MOVWF ART_RESTO
RLF ART_COCIN_L,F
RLF ART_COCIN_H,F
DECFSZ ART_CONTBITS,F
GOTO ARIT_DIVIDEBIT16
MOVF ART_RESTO,W
RETURN
ARIT_MULTIPLICA_16BIT
CLRF ART_PRODC_1H
CLRF ART_PRODC_1L
CLRF ART_PRODC_2H
CLRF ART_PRODC_2L
MOVLW .16
MOVWF ART_CONTBITS
ARIT_MULTIPLICA16BIT
RRF ART_MULTIR_H,F
RRF ART_MULTIR_L,F
BTFSS STATUS,C
GOTO ARIT_MULTIPLICADOR_BITCERO
MOVF ART_MULTID_L,W
ADDWF ART_PRODC_2L,F
BTFSC STATUS,C
INCF ART_PRODC_2H,F
MOVF ART_MULTID_H,W
ADDWF ART_PRODC_2H,F
ARIT_MULTIPLICADOR_BITCERO
RRF ART_PRODC_2H,F
RRF ART_PRODC_2L,F
RRF ART_PRODC_1H,F
RRF ART_PRODC_1L,F
DECFSZ ART_CONTBITS,F
GOTO ARIT_MULTIPLICA16BIT
RETURN
ARIT_RESTA_16BIT
COMF ART_OPERN_1H,F
COMF ART_OPERN_1L,F
MOVLW .1
ADDWF ART_OPERN_1L,F
BTFSC STATUS,C
INCF ART_OPERN_1H,F
MOVF ART_OPERN_1L,W
ARIT_SUMA_16BIT
MOVF ART_OPERN_1L,W
ADDWF ART_OPERN_2L,F
BTFSC STATUS,C
INCF ART_OPERN_1H,F
MOVF ART_OPERN_1H,W
ADDWF ART_OPERN_2H,F
RETURN
TM_XML MOVWF TMD1 ; de 1mS hasta 255mS
MOVLW .248
MOVWF TMD2
NOP
DECFSZ TMD2,F
GOTO $-2
DECFSZ TMD1,F
GOTO $-6
RETURN
TM_XUS MOVLW .48 ; 200uS
TM_20US MOVWF TMD2
NOP
DECFSZ TMD2,F
GOTO $-2
NOP
NOP
NOP
RETURN
TM_20M MOVLW .20 ; 20mS
MOVWF TMD1
MOVLW .248
MOVWF TMD2
NOP
DECFSZ TMD2,F
GOTO $-2
DECFSZ TMD1,F
GOTO $-6
TM_79M MOVLW .18 ; 79uS
MOVWF TMD2
NOP
DECFSZ TMD2,F
GOTO $-2
NOP
NOP
RETURN
;::::::::::::: Zone of Sub-Rutine :::::::::::::
END