TODOPIC
Microcontroladores PIC => Todo en microcontroladores PIC => Mensaje iniciado por: LucasBols en 24 de Febrero de 2009, 02:43:56
-
Hola
Tengo un 16F877A y estoy haciendo pruebas infructuosas para convertir un voltaje que entra por AN0, el voltaje está en un rango 4,20~5,00 v.
Cuando energizo el PIC, los 10 bits de ADRH y ADRL ( los 8+2 en 1) quedan en alto aunque cambie el voltaje de AN0. Escribí el procedimiento de adquisición como indica el datasheet, y estoy en un punto muerto, no se por donde continuar.
El proceso que realizo es el siguiente:
;##############################################################################
; CABECERA ****
;**************
list p=P16F877A ; list directive to define processor
#include <P16F877A.INC> ; 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
Tmp25usDly0 equ 0x25
Tmp25usDly1 equ 0x26
PDel0 equ 0x27
PDel1 equ 0x28
T500mSegDly0 org 0x29
T500mSegDly1 org 0x2A
;##############################################################################
; 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
;----------------------------------------------------------------------
;
btfss PIR1, ADIF
goto SDI_Fin_AD
movlw ADRESH
movwf ADbyte_alto
movlw ADRESL
movwf ADbyte_bajo
call EscrBatLed
bcf PIR1, ADIF
bcf ADCON0, ADON ; apaga el módolo A/D
SDI_Fin_AD
;
;----------------------------------------------------------------------
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
; borra la bandera de la interrupción
retfie
;##############################################################################
; Batería ****
;*************
TestBateria ; Configure analog pins/voltage reference and digital I/O
bcf STATUS, RP1 ; cambia al -----------------------
bsf STATUS, RP0 ; **** BANCO 1 |
bsf ADCON1, PCFG3 ; AN7 AN6 AN5 AN4 AN3 AN2 AN1 AN0
bsf ADCON1, PCFG2 ; D D D D D D D A
bsf ADCON1, PCFG1 ; PCFG3 PCFG2 PCFG1 PCFG0
bcf ADCON1, PCFG0 ; 1 1 1 0
bcf ADCON1, ADFM ; Left justified. Six (6) Least Significant bits of ADRESL are read as ‘0’.
bcf STATUS, RP1 ; vuelve al -----------------------
bcf STATUS, RP0 ; **** BANCO 0 |
; Select A/D input channel
bcf ADCON0, CHS2 ; 000 = Channel 0 (AN0)
bcf ADCON0, CHS1
bcf ADCON0, CHS0
; Select A/D conversion clock
bcf STATUS, RP1 ; cambia al -----------------------
bsf STATUS, RP0 ; **** BANCO 1 |
bcf ADCON1, ADCS2 ; A/D Conversion Clock Select bit
bcf STATUS, RP1 ; vuelve al -----------------------
bcf STATUS, RP0 ; **** BANCO 0 |
bsf ADCON0, ADCS1 ; FOSC/32 Maximum Device Frequency 20 Mhz
bcf ADCON0, ADCS0
; Turn on A/D module
bsf ADCON0, ADON
; Wait the required acquisition time
call Tmp500mSeg
; Start conversion
bsf ADCON0, GO_DONE
; Configure A/D interrupt
bcf PIR1, ADIF
bsf PIE1, ADIE
bsf INTCON, PEIE
bsf INTCON, GIE
return ; queda a la espera de la int de fin de conversión
;------------------------------------------------------------------------------
EscrBatLed ;-------------------------
clrf PORTC
clrf PORTD
;-------------------------
btfss ADbyte_alto, 0
bcf PORTD, 2
bsf PORTD, 2
btfss ADbyte_alto, 1
bcf PORTD, 3
bsf PORTD, 3
btfss ADbyte_alto, 2
bcf PORTC, 4
bsf PORTC, 4
btfss ADbyte_alto, 3
bcf PORTC, 5
bsf PORTC, 5
btfss ADbyte_alto, 4
bcf PORTC, 6
bsf PORTC, 6
btfss ADbyte_alto, 5
bcf PORTC, 7
bsf PORTC, 7
btfss ADbyte_alto, 6
bcf PORTD, 4
bsf PORTD, 4
btfss ADbyte_alto, 7
bcf PORTD, 5
bsf PORTD, 5
btfss ADbyte_bajo, 0
bcf PORTD, 6
bsf PORTD, 6
btfss ADbyte_bajo, 1
bcf PORTD, 7
bsf PORTD, 7
return
;##############################################################################
; INICIO ****
;************
Inicio clrf PCLATH ; ensure page bits are cleared
; seteos en el banco 0 ------------------------------------------------
bcf STATUS, RP1 ; cambia al
bcf STATUS, RP0 ; banco 0
bcf T1CON, TMR1CS ; Internal clock (FOSC/4)
bcf T1CON, TMR1ON ; Stops Timer1
bcf T2CON, TMR2ON ; Timer2 is off
movlw 0x00
movwf CCP1CON ; Capture/Compare/PWM disabled (resets CCP1 module)
movlw 0x00
movwf CCP2CON ; Capture/Compare/PWM disabled (resets CCP2 module)
bcf SSPCON, SSPEN ; Disables the serial port and configures these pins as I/O port pins
bcf RCSTA, SPEN ; Serial port disabled
; seteos en el banco 1 ------------------------------------------------
bcf STATUS, RP1 ; cambia al
bsf STATUS, RP0 ; banco 1
; otros seteos ----------------------
bcf OPTION_REG, NOT_RBPU ; PORTB pull-ups are disabled
bcf OPTION_REG, INTEDG ; Interrupt on falling edge of RB0/INT pin
bcf OPTION_REG, T0CS ; Internal instruction cycle clock (CLKO)
bsf OPTION_REG, T0SE ; Increment TMR0 on high-to-low transition on RA4/T0CKI pin
bcf OPTION_REG, PSA ; Prescaler is assigned to the Timer0 module
bcf INTCON, GIE ; Disables all unmasked interrupts ####
bcf INTCON, PEIE ; Disables all peripheral interrupts ####
bcf INTCON, TMR0IE ; Disables the TMR0 interrupt
bcf INTCON, INTE ; Disables the RB0/INT external interrupt ####
bcf INTCON, RBIE ; Disables the RB port change interrupt ####
bcf PIE1, PSPIE ; Disables the PSP read/write interrupt
bsf PIE1, ADIE ; Enables the A/D converter interrupt ####
bcf PIE1, RCIE ; Disables the USART receive interrupt
bcf PIE1, TXIE ; Disables the USART transmit interrupt
bcf PIE1, SSPIE ; Disables the SSP interrupt
bcf PIE1, CCP1IE ; Disables the CCP1 interrupt
bcf PIE1, TMR2IE ; Disables the TMR2 to PR2 match interrupt
bcf PIE1, TMR1IE ; Disables the TMR1 overflow interrupt
bcf PIE2, CMIE ; Disable the comparator interrupt
bcf PIE2, EEIE ; Disable EEPROM write interrupt
bcf PIE2, BCLIE ; Disable bus collision interrupt
bcf PIE2, CCP2IE ; Disables the CCP2 interrupt
bcf TRISE, PSPMODE ; PORTD functions in general purpose I/O mode
movlw 0x07
movwf CMCON ; Comparators Off
; configuración de puertos ----------
movlw 0x01
movwf TRISA
movlw 0x00
movwf TRISC
movlw 0x00
movwf TRISD
; seteos en el banco 2 --------------------------------------------
bsf STATUS, RP1 ; cambia al
bcf STATUS, RP0 ; banco 2
; seteos en el banco 3 --------------------------------------------
bsf STATUS, RP1 ; cambia al
bsf STATUS, RP0 ; banco 3
bcf STATUS, RP1 ; vuelve al
bcf STATUS, RP0 ; banco 0
;------------------------------------------------------------------
goto Dormir
;##############################################################################
; Dormir ****
;************
Dormir call TestBateria
call Tmp500mSeg
goto Dormir
;##############################################################################
; Temporizadores ****
;********************
Tmp25us movlw .44 ; 1 set number of repetitions (B)
movwf Tmp25usDly0 ; 1 |
Tmp25usLp1 movlw .141 ; 1 set number of repetitions (A)
movwf Tmp25usDly1 ; 1 |
Tmp25usLp2 clrwdt ; 1 clear watchdog
decfsz Tmp25usDly1, 1 ; 1 + (1) is the time over? (A)
goto Tmp25usLp2 ; 2 no, loop
decfsz Tmp25usDly0, 1 ; 1 + (1) is the time over? (B)
goto Tmp25usLp1 ; 2 no, loop
Tmp25usDLp1 goto Tmp25usDLp2 ; 2 cycles delay
Tmp25usDLp2 clrwdt ; 1 cycle delay
return ; 2+2 Done
;------------------------------------------------------------------------------
;-------------------------------------------------------------
; Code generated by PDEL ver 1.0 on 14/02/2009 at 09:57:58 p.m.
; Description: Waits 250000 cycles
;-------------------------------------------------------------
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
;-------------------------------------------------------------
; Code generated by PDEL ver 1.0 on 23/02/2009 at 04:40:04 p.m.
; Description: Waits 500000 cycles
;-------------------------------------------------------------
Tmp500mSeg movlw .239 ; 1 set number of repetitions (B)
movwf T500mSegDly0 ; 1 |
T500mSegLp1 movlw .232 ; 1 set number of repetitions (A)
movwf T500mSegDly1 ; 1 |
T500mSegLp2 clrwdt ; 1 clear watchdog
T500mSegDlL1 goto T500mSegDlL2 ; 2 cycles delay
T500mSegDlL2 goto T500mSegDlL3 ; 2 cycles delay
T500mSegDlL3 clrwdt ; 1 cycle delay
decfsz T500mSegDly1, 1 ; 1 + (1) is the time over? (A)
goto T500mSegLp2 ; 2 no, loop
decfsz T500mSegDly0, 1 ; 1 + (1) is the time over? (B)
goto T500mSegLp1 ; 2 no, loop
T500mSegDlL4 goto T500mSegDlL5 ; 2 cycles delay
T500mSegDlL5 goto T500mSegDlL6 ; 2 cycles delay
T500mSegDlL6 goto T500mSegDlL7 ; 2 cycles delay
T500mSegDlL7 clrwdt ; 1 cycle delay
return ; 2+2 Done
;-------------------------------------------------------------
;##############################################################################
end
;##############################################################################
Muchísimas gracias por cualquier ayuda o pista.
Saludos.-
-
A VER si esto te sirve de ayuda como referencia:
;Los dispositivos PIC16F87X disponen de un convertidor A/D de 10 bits de resolución y 5 u 8
;canales de entrada analógica. La tensión de referencia determina la resolución por bit:
;(Res. = Vref/1024). Con 5 Vref=4.8 mV/Bit; con 2.5 Vref=2.4 mV/Bit
;
;El ejemplo propone realizar la conversión de la tensión presente en el canal RA3/AN3. Esta
;se puede variar con el potenciómetro AN3 alojado en la tarjeta Micro'PIC Trainer. El resul-
;tado de la conversión se visualiza, en binario, sobre la pantalla LCD.
List p=16F873 ;Tipo de procesador
include "P16F873.INC" ;Definiciones de registros internos
Lcd_var equ 0x20 ;Variables de las rutinas LCD
Temporal_1 equ 0x22 ;Variable temporal
org 0x00 ;Vector de Reset
goto Inicio
org 0x05 ;Salva el vector de interrupción
include "LCD_CXX.INC" ;Incluye rutinas de manejo del LCD
;Visualiza: Esta rutina coge los 10 bits resultantes de la conversión, presentes en ADRESH
;y ADRESL, los convierte a caracteres ACII (0 o 1) y los visualiza sobre el LCD.
Visualiza: movlw 0x80
call LCD_REG ;Sitúa el cursor del LCD
movlw .9
movwf Temporal_1 ;Nº de caracteres a visualizar
Visual_loop bsf STATUS,RP0
rlf ADRESL,F
bcf STATUS,RP0
rlf ADRESH,F ;Rotación del siguiente bit
btfsc STATUS,C ;Testea el bit a visualizar
goto Bit_1 ;Está a 1
movlw '0'
goto Visu_1
Bit_1 movlw '1'
Visu_1 call LCD_DATO ;Visualiza el "0" o el "1" sobre el LCD
decfsz Temporal_1,F ;Siguiente caracter
goto Visual_loop
return
;Programa principal
Inicio clrf PORTA
clrf PORTB
bsf STATUS,RP0 ;Selecciona banco 1
movlw b'00000110'
movwf ADCON1 ;Puerta A E/S digitales
clrf TRISB ;Puerta B se configura como salida
clrf TRISA ;RA4-RA0 salidas
movlw b'11001111'
movwf OPTION_REG ;Preescaler de 128 asociado al WDT
bcf STATUS,RP0 ;Selecciona banco 0
call UP_LCD ;Configura E/S para el LCD
call LCD_INI ;Secuencia de inicio del LCD
movlw b'00001100'
call LCD_REG ;LCD On, cursor y blink Off
;Se activa el ADC y se selecciona el canal RA3/AN3. Frecuencia de trabajo Fosc/32
movlw b'10011001'
movwf ADCON0 ;ADC en On, seleciona canal AN3
Loop clrwdt
bsf STATUS,RP0 ;Selecciona página 1
movlw b'00011111'
movwf TRISA ;Puerta A entradas
clrf ADCON1 ;Puerta A entradas analógicas
bcf STATUS,RP0 ;Selecciona página 0
bcf PIR1,ADIF ;Restaura el flag del conversor AD
nop
bsf ADCON0,GO ;Inicia la conversión
ADC_Wait btfss PIR1,ADIF ;Fin de conversión ??
goto ADC_Wait ;Todavía no
;Las líneas de la Puerta A se reconfiguran como salidas digitales para la visualización
bsf STATUS,RP0 ;Selecciona banco 1
movlw b'00000110'
movwf ADCON1 ;Puerta A digital
bcf STATUS,RP0 ;Selecciona banco 0
call UP_LCD ;Reconfigura E/S para el LCD
call Visualiza ;Visualiza el resultado de la conversión
goto Loop
end ;Fin del programa fuente
-
Lo solucioné, gracias pibe
El único 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ón de referencia, sin embargo, indico que vref+ = vdd y vref- = vss por que configuro PCFG3:PCFG0 con 1110, que configura AN7:AN0 como D D D D D D D A, vref+ = vdd y vref- = vss.
Debería inyectar vref+/- por algún RA con valores 4,50v y 5,00v, pero me quedaría más de un puerto como analógico, y en este proyecto, no puedo prescindir de ningún puerto.
Este es el resultado.
;##############################################################################
; Salida de Batería AN0 Decimal Binario
; Mínimo 11,50 v 4,50 v 225 ~ 226 0011100001 ~ 0011100010
; Máximo 13,10 v 4,09 v 238 ~ 239 0011101110 ~ 0011101111
;##############################################################################
; CABECERA ****
;**************
list p=P16F877A ; list directive to define processor
#include <P16F877A.INC> ; 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ón
retfie
;##############################################################################
; Batería ****
;*************
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ón
;------------------------------------------------------------------------------
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ón 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ón 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ódulo 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ón 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'
;##############################################################################