Documentos de Académico
Documentos de Profesional
Documentos de Cultura
P=16F877A
INCLUDE <P16F877A.INC>
CBLOCK 0x0C
Distancia
; Se expresar en centmetros.
;contador
ENDC
;Definimos puertos a utilizar
#DEFINE Disparo PORTA,1
#DEFINE Eco
PORTA,0
EQU
.3
MaximaDistancia
EQU
.250
TMR0_Carga60micros
EQU
ORG
goto
Inicio
ORG
goto
ServicioInterrupcion
Inicio
bsf STATUS,RP0;bsf-setea el bit- bit set file...pasamos de Banco 0 a Banco 1
; (sirve para configurar como entrada 1 o salida 0)...se carga W en TRISA
movlw b'00000000';declramos los puertos en esta caso b como salida
movwf TRISB
bcf STATUS,RP0
CLRF PORTB
BCF STATUS,RP0 ; Ir banco 1
CLRF PORTA
BSF STATUS,RP0
movlw CONF_ADCON1 ; Configurar el PORTA como digital
movwf ADCON1;registro del de configuracion paca configurar la I/O A/D
movlw b'010000' ; PORTA como entrada
movwf TRISA
bsf
STATUS,RP0;Pasamos al banco 1
bcf
bsf
Eco
movlw
b'00000000'
movwf
bcf
STATUS,RP0;pasmos al banco 0
bcf
Disparo
clrf
Distancia
; Inicializa el registro.
clrf CONT;se vuelve a poner en cero el contador dado que aque es donde se
realiza el bucle cerrado
bsf
Disparo
call
Retardo_10micros
Disparo
bcf
en cero.
Espera_Eco_1
btfss Eco
goto
Espera_Eco_1
movlw
flanco de subida.
movwf
TMR0_Carga60micros
TMR0
; Carga el Timer
movlw
b'10100000'
movwf
INTCON
Espera_Eco_0
btfsc Eco
goto
Espera_Eco_0
; del SRF04.
clrf
INTCON
Prohbe interrup.
call
BTFSC STATUS,Z
BCF PRUEBA1
MOVFW CONTADOR;mueve la variable de f al registro w
SUBLW .10
simulando un if
BTFSS STATUS,C
BSF PRUEBA1
BTFSC STATUS,Z
BCF PRUEBA2
MOVFW CONTADOR;mueve la variable de f al registro w
SUBLW .9
simulando un if
BTFSS STATUS,C
BSF PRUEBA2
BTFSC STATUS,Z
BCF PRUEBA3
MOVFW CONTADOR;mueve la variable de f al registro w
SUBLW .8
simulando un if
BTFSS STATUS,C
BSF PRUEBA3
BTFSC STATUS,Z
BCF PRUEBA4
MOVFW CONTADOR;mueve la variable de f al registro w
SUBLW .7
simulando un if
BTFSS STATUS,C
BSF PRUEBA4
;CLRF CONT
Fin
;movlw
.0
;movwf
CONT
goto
; Carga el Timer 0.
Principal
TMR0_Carga60micros
movwf
TMR0;cargamos al timer0
; Carga el Timer 0.
.1
"incf"
addwf Distancia,F
movlw
mximo valor.
MaximaDistancia
btfsc STATUS,C
movwf
Distancia
;INCF CONT,1
bcf
retfie;retorna de la interupcion
INCLUDE <RETARDOS.INC>
END