Lo solucion=E9
El =FAnico problema que me queda es ver por que inyectando 4,09v en AN0 me entrega 239 en lugar de entregarme 1023 Supongo que debe andar por el lado de la tensi=F3n de referencia, sin embargo, indico que vref+ =3D vdd y vref- =3D vss por que configuro PCFG3:PCFG0 con 1110, que configura AN7:AN0 como D D D D D D D A, vref
Deber=EDa inyectar vref+/- por alg=FAn RA con valores 4,50v y 5,00v, pero me quedar=EDa m=E1s de un puerto como anal=F3gico, y en este proyecto, no puedo prescindir de ning=FAn puerto.
Este es el resultado. ;##########################################################################= #### ; Salida de Bater=EDa AN0 Decimal Binario ; M=EDnimo 11,50 v 4,50 v 225 ~ 226 0011100001 ~ 0011100010 ; M=E1ximo 13,10 v 4,09 v 238 ~ 239 0011101110 ~ 0011101111 ;##########################################################################= #### ; CABECERA **** ;************** list p=3DP16F877A ; list directive to define processor #include ; processor specific variable definitions
;--------------------------------------------------------------------------=
----
__CONFIG _XT_OSC & _DEBUG_OFF & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _CP_OFF & _DEBUG_OFF
;##########################################################################= #### ; VARIABLES **** ;***************
;------------------------------------------- ; 0x20 ~ 0x7F - Banco 0 | RP1 : 0 RP0 : 0 ;-------------------------------------------
w_temp equ 0x20 ; variable used for context saving status_temp equ 0x21 ; variable used for context saving pclath_temp equ 0x22 ; variable used for context saving ADbyte_bajo equ 0x23 ADbyte_alto equ 0x24 ; variables de los temporizadores CntCnvAD equ 0x25 Tmp25usDly0 equ 0x26 Tmp25usDly1 equ 0x27 PDel0 equ 0x28 PDel1 equ 0x29 T500mSegDly0 org 0x2A T500mSegDly1 org 0x2B
;##########################################################################= #### ; DIRECCIONES **** ;*****************
ORG 0x000 ; processor reset vector goto Inicio ; go to beginning of program ORG 0x004 ; interrupt vector location goto SDI org 0x005
;##########################################################################= #### ; INTERRUPCIONES **** ;********************
SDI movwf w_temp ; Copy W to TEMP register swapf STATUS, w ; Swap status to be saved into W clrf STATUS ; bank 0, regardless of current bank, Clears IRP,RP1,RP0 movwf status_temp ; Save status to bank zero STATUS_TEMP register movf PCLATH, w ; Only required if using pages 1, 2 and/or 3 movwf pclath_temp ; Save PCLATH into W clrf PCLATH ; Page zero, regardless of current page ;****************************************************************** ; ;---- seteos en el banco 1 ---------------------------------------- bcf STATUS, RP1 ; cambia al bsf STATUS, RP0 ; banco 1 ;------------------------------------------------------------------ movf ADRESL,0 ; Paso el valor de ADRESL a W. movwf ADbyte_bajo ; Paso el valor de W a ADbyte_bajo ;---- seteos en el banco 0 ---------------------------------------- bcf STATUS, RP1 ; cambia al bcf STATUS, RP0 ; banco 0 ;------------------------------------------------------------------ movf ADRESH,0 ; Paso el valor de ADRESH a W. movwf ADbyte_alto ; Paso el valor de W a ADbyte_alto nop ; Espero un tiempo de nop ; 2 veces el el tiempo de nop ; conversion A/D por bit. call EscrBatLed ; escribo el resultado ; ;****************************************************************** movf pclath_temp, w ; Restore PCLATH movwf PCLATH ; Move W into PCLATH swapf status_temp, w ; Swap STATUS_TEMP register into W;(sets bank to original state) movwf STATUS ; Move W into STATUS register swapf w_temp, f ; Swap W_TEMP swapf w_temp, w ; Swap W_TEMP into W bcf PIR1,ADIF ; borra la bandera de la interrupci=F3n retfie
;##########################################################################= #### ; Bater=EDa **** ;*************
TestBateria ; seteos en el banco 0
-------------------------------------------- bcf STATUS, RP1 ; cambia al bcf STATUS, RP0 ; banco 0 ;------------------------------------------------------------------ bsf ADCON0,2 ; Comienzo la conversion btfsc ADCON0,2 ; Verifica si la conversion goto $-1 ; ha sido completada. goto Config_Int ; Vuelvo a preparar el conversor A/D return ; queda a la espera de la int de fin de conversi=F3n
;--------------------------------------------------------------------------=
----
EscrBatLed ;------------------------- clrf PORTC clrf PORTD ;------------------------- btfsc ADbyte_alto, 0 bsf PORTD, 2 btfsc ADbyte_alto, 1 bsf PORTD, 3 btfsc ADbyte_alto, 2 bsf PORTC, 4 btfsc ADbyte_alto, 3 bsf PORTC, 5 btfsc ADbyte_alto, 4 bsf PORTC, 6 btfsc ADbyte_alto, 5 bsf PORTC, 7 btfsc ADbyte_alto, 6 bsf PORTD, 4 btfsc ADbyte_alto, 7 bsf PORTD, 5 btfsc ADbyte_bajo, 0 bsf PORTD, 6 btfsc ADbyte_bajo, 1 bsf PORTD, 7 call Tmp500mSeg return
;##########################################################################= #### ; INICIO **** ;************
Inicio clrf PCLATH ; ensure page bits are cleared ; seteos en el banco 1 -------------------------------------------- bcf STATUS, RP1 ; cambia al bsf STATUS, RP0 ; banco 1 ;------------------------------------------------------------------ ; configuraci=F3n de puertos ---------- movlw 0x01 movwf TRISA movlw 0x00 movwf TRISC movlw 0x00 movwf TRISD ; seteos en el banco 0 -------------------------------------------- bcf STATUS, RP1 ; cambia al bcf STATUS, RP0 ; banco 0 ;------------------------------------------------------------------ call AvisoInicio ; seteos en el banco 1 -------------------------------------------- bcf STATUS, RP1 ; cambia al bsf STATUS, RP0 ; banco 1 ;------------------------------------------------------------------ ; configuraci=F3n del conversor bcf ADCON1, ADFM ; justifico a la izquierda bcf ADCON1, ADCS2 ; Fosc/2 bsf ADCON1, PCFG3 bsf ADCON1, PCFG2 bsf ADCON1, PCFG1 bcf ADCON1, PCFG0 ; D D D D D D D A VDD VSS 1/0 ; seteos en el banco 0
-------------------------------------------- bcf STATUS, RP1 ; cambia al bcf STATUS, RP0 ; banco 0 ;------------------------------------------------------------------ bcf ADCON0, ADCS1 bcf ADCON0, ADCS0 ; Fosc/2 bcf ADCON0, CHS2 bcf ADCON0, CHS1 bcf ADCON0, CHS0 ; Channel 0 (AN0) bcf ADCON0, GO_DONE ; limpio y dentengo la conversion bsf ADCON0, ADON ; enciendo el m=F3dulo A/D
Config_Int ; seteos en el banco 0
-------------------------------------------- bcf STATUS, RP1 ; cambia al bcf STATUS, RP0 ; banco 0 ;------------------------------------------------------------------ bcf PIR1,ADIF ; Limpio la bandera de interrupcion del modulo A/ D. bsf INTCON,GIE ; Habilito las interrupciones tanto bsf INTCON,PEIE ; generales como perifericas. ; seteos en el banco 1 -------------------------------------------- bcf STATUS, RP1 ; cambia al bsf STATUS, RP0 ; banco 1 ;------------------------------------------------------------------ bsf PIE1,ADIE ; Habilito la interrupcion del convertidor A/D. ; seteos en el banco 0
-------------------------------------------- bcf STATUS, RP1 ; cambia al bcf STATUS, RP0 ; banco 0 ;------------------------------------------------------------------ goto Dormir
AvisoInicio clrf PORTC clrf PORTD bsf PORTD, 2 call PDelay bcf PORTD, 2 bsf PORTD, 3 call PDelay bcf PORTD, 3 bsf PORTC, 4 call PDelay bcf PORTC, 4 bsf PORTC, 5 call PDelay bcf PORTC, 5 bsf PORTC, 6 call PDelay bcf PORTC, 6 bsf PORTC, 7 call PDelay bcf PORTC, 7 bsf PORTD, 4 call PDelay bcf PORTD, 4 bsf PORTD, 5 call PDelay bcf PORTD, 5 bsf PORTD, 6 call PDelay bcf PORTD, 6 bsf PORTD, 7 call PDelay bcf PORTD, 7 ;------------------------------------------------------------------ return
;##########################################################################= #### ; Dormir **** ;************
Dormir clrf ADbyte_bajo clrf ADbyte_alto clrf CntCnvAD call EsperaConvAD call TestBateria goto Dormir
;##########################################################################= #### ; Temporizadores **** ;******************** PDelay movlw .197 ; 1 set number of repetitions (B) movwf PDel0 ; 1 | PLoop1 movlw .253 ; 1 set number of repetitions (A) movwf PDel1 ; 1 | PLoop2 clrwdt ; 1 clear watchdog clrwdt ; 1 cycle delay decfsz PDel1, 1 ; 1 + (1) is the time over? (A) goto PLoop2 ; 2 no, loop decfsz PDel0, 1 ; 1 + (1) is the time over? (B) goto PLoop1 ; 2 no, loop PDelL1 goto PDelL2 ; 2 cycles delay PDelL2 return ; 2+2 Done
;##########################################################################= #### ; Espera de adquisici=F3n del Conversor AD **** ;********************************************
EsperaConvAD movlw 0x30 ;Subrutina de espera para el movwf CntCnvAD ;tiempo de conversion. EsperaConvADLp decfsz CntCnvAD, 1 goto $-1 return ;##########################################################################= ####
end ; directive 'end of program'
;##########################################################################= ####