; 28-08-06
; Ejemplo 14
; Contador con un Display de cathodo comun
; PIC 16f84a
; MPLAB 7.30
; PROTEUS 6.9 SP3
; Veguepic
; sencillo contador continuo de 0 a 9 y demora un segundo cada cambio .
LIST P=16F84A, ; usar PIC 16F84A
#include <p16f84A.inc>
__CONFIG _CP_OFF&_PWRTE_ON&_WDT_OFF&_XT_OSC
; code protec off; power up timer on; watchdog off; osc XT
errorlevel -302 ; Elimina el mensaje "bank warning"
CBLOCK 0x20 ; Ubica los registros consecutivamente a partir de la ubicacion 0x20
PDel0 ; 0x20
PDel1 ; 0x21
PDel2 ; 0x22
UNIDADES ; 0x23
ENDC ; Fin de las registros
ORG 0
BSF STATUS,5 ; activa la pagina 1
MOVLW B'00000' ; carga 01111 en W
MOVWF TRISA ; puerto A todos salidas
MOVLW B'00000000' ; carga 11111111 en W
MOVWF TRISB ; puerto B todas salidas
BCF STATUS,5 ; volvemos a la pagina 0
CLRF PORTA ; ponemos a cero el puerto A
CLRF PORTB ; ponemos a cero el puerto B
CLRF UNIDADES ; ponemos a cero UNIDADES
MOVLW 0 ; ponemos a cero W
GOTO INICIO ; va a inicio
TABLA
ADDWF PCL,1 ; suma w (valor puerto A) con el valor de PCL
; (contador del programa) y lo guarda en PCL
; dp-a-b-c-d-e-f-g orden de los segmentos
RETLW B'1111110' ; 0, carga B'1111110' en W y retorna
RETLW B'0110000' ; 1, carga B'0110000' en W y retorna
RETLW B'1101101' ; 2, carga B'1101101' en W y retorna
RETLW B'1111001' ; 3, carga B'1111001' en W y retorna
RETLW B'0110011' ; 4, carga B'0110011' en W y retorna
RETLW B'1011011' ; 5, carga B'1011011' en W y retorna
RETLW B'1011111' ; 6, carga B'1011111' en W y retorna
RETLW B'1110000' ; 7, carga B'1110000' en W y retorna
RETLW B'1111111' ; 8, carga B'1111111' en W y retorna
RETLW B'1111011' ; 9, carga B'1111011' en W y retorna
RETLW B'1110111' ; A, carga B'1110111' en W y retorna
RETLW B'0011111' ; b, carga B'0011111' en W y retorna
RETLW B'1001110' ; C, carga B'1001110' en W y retorna
RETLW B'0111101' ; d, carga B'0111101' en W y retorna
RETLW B'1001111' ; E, carga B'1001111' en W y retorna
RETLW B'1000111' ; F, carga B'1000111' en W y retorna
INICIO ; etiqueta
CALL TABLA ; llamamos a TABLA
MOVWF PORTB ; mueve el dato al puerto B
CALL DEMORA
MOVLW 1 ; pones a 1 W
ADDWF UNIDADES,1 ; suma W a UNIDADES y lo guarda en UNIDADES
MOVF UNIDADES,0 ; mueve UNIDADES a W
BTFSS UNIDADES,4 ; comprueba si el bit 4 de CONTADOR es uno salta
GOTO INICIO ; va a INICIO
CLRF UNIDADES ; borra UNIDADES
MOVLW 0 ; pone a 1 W
GOTO INICIO ; va a inicio
;-------------------------------------------------------------
; Generado con PDEL ver SP r 1.0 el 27/08/2006 Hs 09:39:14 p.m.
; Descripcion: Delay 1000000 ciclos = 1 segundo
;-------------------------------------------------------------
DEMORA movlw .14 ; 1 set numero de repeticion (C)
movwf PDel0 ; 1 |
PLoop0 movlw .72 ; 1 set numero de repeticion (B)
movwf PDel1 ; 1 |
PLoop1 movlw .247 ; 1 set numero de repeticion (A)
movwf PDel2 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
decfsz PDel2, 1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (C)
goto PLoop0 ; 2 no, loop
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2 clrwdt ; 1 ciclo delay
return ; 2+2 Fin.
;-------------------------------------------------------------
END ; fin de programa