Está en la página 1de 3

; /--------------------------------------------------------------------------------------/

; Resumen de la rutina:
;
Lee el pin PA0 por medio del ADC
;
Si este es menor a 1 V, PA1=1 y PA2=0
;
Si es igual a 1V: PA1=1 y PA2=1
;
Si es mayor a 1V: PA1=0 y PA2=1
;
Por cada ciclo exite un retardo de 755 us
; /-------------------------------------------------------------------------------------/
LIST
p=P16f877
#include <p16f877.inc>
__CONFIG _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _CP_OFF & _WDT_OFF & _LVP_OFF
; /---------------------- IGUALDADES ---------------------------------------------------/
RP0
EQU
5
; Bit 5 del Registro STATUS
RP1
EQU
6
; Bit 6 del Registro STATUS
REF1
EQU
0xCF
; Umbral inferior (0.941V)
REF2
EQU
0xCC
; Umbral superior (1.058V)
; /---------------------- DEFINICION DE REGISTROS PARTICULARES ------------------------/
REGA
EQU
0x22
; Registro A
REGB
EQU
0x24
; Registro B
REGC
EQU
0x26
; Registro C
CASOS EQU
0x28
; Registro de Control de casos
; /---------------------- INICIALIZACION ----------------------------------------------/
ORG
0
; Posicin del vector RESET.
goto
INICIO ; Comienza el programa despus del vector de interrupcin.
ORG
4
goto
A_INT ; rutina de atencion de interrupciones
; /---------------------- PROGRAMA ----------------------------------------------------/
INICIO
call
PREPARA
; Rutina de Inicializacion de registros
LAZO
call
RETARD
; Subrutina de retardo de 100us
clrf
CASOS
bsf
ADCON0, 0
; Habilita ADC
bsf
ADCON0, 2
; Inicia conversion
CONV
btfsc ADCON0, 2
; polling del GO/~DONE
goto
CONV
bcf
ADCON0, 0
; Deshabilita interrupcion por A
DC
movlw
movwf
movlw
movwf

REF2
REGA
REF1
REGB

; umbral superior
; umbral inferior

; Verificando umbral superior


movf
ADRESH, 0
bcf
bcf
addwf
btfsc
call
btfsc
call

STATUS,
STATUS,
REGA, 1
STATUS, 0
SOL1
STATUS, 2
SOL1

2
0
;
;
;
;
;

; manda a cero el Z
; manda a cero el Carry-Out
REGA+ADRESH, guarda en REGA
Pregunta por carry out
solucion 1
Pregunta por Z
solucion 1

btfsc
goto

CASOS, 0
LAZO

; Verificando umbral intermedio


movf
ADRESH,
bcf
bcf
addwf REGB,
btfsc STATUS,
call
SOL2
btfsc STATUS,
call
SOL2
btfsc
goto

0
STATUS,
STATUS,
1
0
2

CASOS, 1
LAZO

; control de casos
; 1 caso activo

2
0
;
;
;
;
;

; mando a cero el Z
; mando a cero el Carry-Out
REGB+ADRESH, guarda en REGB
Pregunta por el carry out
solucion 2
pregunta por Z
solucion 2

; control de casos
; 2 caso activo

call
SOL3
; si no es sol1 o 2 es directamente la 3
goto
LAZO
; bucle infinito
; /------------ o ----------- o ----------- o ----------- o ----------- o -------------/
; /-------------------------- Sub-rutina de Inicializacion ----------------------------/
PREPARA
bcf
ADCON0, 0
; Deshabilitar Interrupcin del AD
C
clrf
INTCON
; Deshabilita cualquier otra interrupcio
n
bsf
bcf
movlw
movwf
leer solo ADRESH)

STATUS, RP0
STATUS, RP1

; Banco 1

b'0001110'
ADCON1
; PA0 anlogico, justificado a la izquierda (

movlw
movwf

0x01
TRISA

; PA0 como entrada, los otros como salid

clrf
clrf
clrf

TRISB
TRISC
TRISD

; PORTB salida
; PORTC salida
; PORTD salida

bcf
bcf

STATUS,RP0
STATUS,RP1

clrf
clrf
clrf
clrf

PORTA
PORTB
PORTD
PORTC

movlw
movwf

b'10000000'
ADCON0

; Banco 0

; Manda a cero los puertos A B C y D

; Tad=32*Tosc/4=32us y canal AN0

return
; /------------ o ----------- o ----------- o ----------- o ----------- o -------------/
; /------------ Rutinas de encendido de LEDS por caso ---------------------------------/
SOL1

bsf
bcf
bsf
return

PORTA, 1
PORTA, 2
CASOS, 0

; LED 1 on
; LED 2 off
; Indicador de SOL1 activa

bsf
bsf
bsf
return

PORTA, 1
PORTA, 2
CASOS, 1

;
;
;
;

bcf
bsf
return

PORTA, 1
PORTA, 2

; Solucion inferior
; LED 1 off
; LED 2 on

SOL2

SOL3

Solucion intermedia
LED 1 on
LED 2 on
Indicador de SOL2 activa

; /------------ o ----------- o ----------- o ----------- o ----------- o -------------/


; /--------------------------- Atencion de Interrupciones -----------------------------/
A_INT
return
; /------------ o ----------- o ----------- o ----------- o ----------- o -------------/
; /------------------------------- Retardo Adicional ----------------------------------/
RETARD
movlw 0xFF
; 256 en decimal
movwf REGC
SIGUE decfsz REGC, 1
; salta si llega a cero
goto
SIGUE
return
; /------------ o ----------- o ----------- o ----------- o ----------- o -------------/
DWTDG
return
end

También podría gustarte