Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% encontró este documento útil (0 votos)
6 vistas14 páginas

Ejemplo 2024B

Descargar como pdf o txt
Descargar como pdf o txt
Descargar como pdf o txt
Está en la página 1/ 14

EJEMPLO N°01: Enciende un Led en el Puerto RB0

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

ORG 0
BSF STATUS,5 ; activa la pagina 1
MOVLW B'00000' ; carga 00000 en W
MOVWF TRISA ; Puerto A todas salidas
MOVLW B'00000000' ; carga 00000000 en W
MOVWF TRISB ; Puerto B todas salidas
BCF STATUS,5 ; volvemos a la pagina 0

CLRF PORTA ; APAGA TODOS LOS PINES DE A


CLRF PORTB ; APAGA TODOS LOS PINES DE B

INICIO ; etiqueta
BSF PORTB,0 ; pone a 1 RB0
GOTO INICIO ; va a inicio

END ; fin de programa


EJEMPLO N°02: Enciende y Apagar un Led en el Puerto RB0 cada 0.5 seg.

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
PDel0 equ 0C
PDel1 equ 0D

ORG 0
BSF STATUS,5 ; activa la pagina 1
MOVLW B'00000' ; carga 00000 en W
MOVWF TRISA ; Puerto A todas salidas
MOVLW B'00000000' ; carga 00000000 en W
MOVWF TRISB ; Puerto B todas salidas
BCF STATUS,5 ; volvemos a la pagina 0

CLRF PORTA ; APAGA TODOS LOS PINES DE A


CLRF PORTB ; APAGA TODOS LOS PINES DE B

INICIO ; etiqueta
BSF PORTB,0 ; pone a 1 RB0
CALL DEMORA ; llama a demora de 0,5 seg
BCF PORTB,0 ; pone a 0 RB0
CALL DEMORA ; llama a demora de 0,5 seg
GOTO INICIO ; va a inicio
;-------------------------------------------------------------
; La demora a sido generada con el programa PDEL
; Delay 250000 ciclos
;-------------------------------------------------------------
DEMORA movlw .197 ; 1 set numero de repeticion (B)
movwf PDel0 ;1
PLoop1 movlw .253 ; 1 set numero de repeticion (A)
movwf PDel1 ;1
PLoop2 clrwdt ; 1 clear watchdog
clrwdt ; 1 ciclo delay
decfsz PDel1,1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0,1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2
Return ; 2+2 Fin.
;---------------------------------------
END ; fin de programa
EJEMPLO N°03: Prender y apagar 4 leds (RB0 a RB3). 0,5 segundos prendido
y 0,5 segundos apagado con un 16F84A

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

PDel0 equ 0C
PDel1 equ 0D

ORG 0
BSF STATUS,5 ; activa la pagina 1
MOVLW B'00000' ; carga 00000 en W
MOVWF TRISA ; Puerto A todos salidas
MOVLW B'00000000' ; carga 00000000 en W
MOVWF TRISB ; Puerto B todos salidaS
BCF STATUS,5 ; volvemos a la pagina 0

CLRF PORTA ; APAGA TODOS LOS PINES DE A


CLRF PORTB ; APAGA TODOS LOS PINES DE B

INICIO ; etiqueta

MOVLW B'00001111' ; prendemos leds RB0 a RB3


MOVWF PORTB ; cargamos el puerto b

CALL DEMORA ; llama a demora de 0,5 seg

MOVLW B'00000000' ; apagamos leds RB0 a RB3


MOVWF PORTB ; cargamos el puerto b

CALL DEMORA ; llama a demora de 0,5 seg


GOTO INICIO ; va a inicio

;-------------------------------------------------------------
; La demora a sido generada con el programa PDEL
; Delay 500000 ciclos
;-------------------------------------------------------------
DEMORA movlw .239 ; 1 set numero de repeticion (B)
movwf PDel0 ;1
PLoop1 movlw .232 ; 1 set numero de repeticion (A)
movwf PDel1 ;1|
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2 goto PDelL3 ; 2 ciclos delay
PDelL3 clrwdt ; 1 ciclo delay
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0? (B)
goto PLoop1 ; 2 no, loop
PDelL4 goto PDelL5 ; 2 ciclos delay
PDelL5 goto PDelL6 ; 2 ciclos delay
PDelL6 goto PDelL7 ; 2 ciclos delay
PDelL7 clrwdt ; 1 ciclo delay
return ; 2+2 Fin.
;---------------------------------------
END ; fin de programa
EJEMPLO N°04: Efecto de luces tipo Auto Fantástico con un 16F84A por el
puerto B, RB0 a RB7

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

PDel0 equ 0C
PDel1 equ 0D

ORG 0
BSF STATUS,5 ; activa la pagina 1
MOVLW B'00000' ; carga 00000 en W
MOVWF TRISA ; Puerto A todas salidas
MOVLW B'00000000' ; carga 00000000 en W
MOVWF TRISB ; Puerto B todas salidas
BCF STATUS,5 ; volvemos a la pagina 0

CLRF PORTA ; APAGA TODOS LOS PINES DE A


CLRF PORTB ; APAGA TODOS LOS PINES DE B

INICIO
BSF PORTB,0 ; prendemos y apagamos
CALL DEMORA ; led por led del Puerto B: RB0
BCF PORTB,0

BSF PORTB,1
CALL DEMORA
BCF PORTB,1

BSF PORTB,2
CALL DEMORA
BCF PORTB,2

BSF PORTB,3
CALL DEMORA
BCF PORTB,3

BSF PORTB,4
CALL DEMORA
BCF PORTB,4

BSF PORTB,5
CALL DEMORA
BCF PORTB,5

BSF PORTB,6
CALL DEMORA
BCF PORTB,6

BSF PORTB,7
CALL DEMORA
BCF PORTB,7

BSF PORTB,6
CALL DEMORA
BCF PORTB,6

BSF PORTB,5
CALL DEMORA
BCF PORTB,5

BSF PORTB,4
CALL DEMORA
BCF PORTB,4

BSF PORTB,3
CALL DEMORA
BCF PORTB,3

BSF PORTB,2
CALL DEMORA
BCF PORTB,2

BSF PORTB,1
CALL DEMORA
BCF PORTB,1

GOTO INICIO ; Salta a inicio

;-------------------------------------------------------------
; La demora a sido generada con el programa PDEL
; Descripcion: Delay 100000 ciclos - 100 ms
;-------------------------------------------------------------
DEMORA movlw .110 ; 1 set numero de repeticion (B)
movwf PDel0 ;1
PLoop1 movlw .181 ; 1 set numero de repeticion (A)
movwf PDel1 ;1
PLoop2 clrwdt ; 1 clear watchdog
clrwdt ; 1 ciclo delay
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2 goto PDelL3 ; 2 ciclos delay
PDelL3 clrwdt ; 1 ciclo delay
return ; 2+2 Fin.
;-------------------------------------------------------------
END ; fin de programa
EJEMPLO N°05: Detectar 1 uno por el Puerto A y encender un led por el
Puerto B

;ENCIENDE UN LED CON UN SWITCH


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
ORG 0
BSF STATUS,5 ; activa la pagina 1
MOVLW B'00001' ; carga 00001 en W pONE DE ENTRADA RA0
MOVWF TRISA ; puerto a todos salidas
MOVLW B'00000000' ; carga 00000000 en W
MOVWF TRISB ; puerto b todos salidaS
BCF STATUS,5 ; volvemos a la pagina 0
CLRF PORTA ; APAGA TODOS LOS PINES DE A
CLRF PORTB ; APAGA TODOS LOS PINES DE B
INICIO
BTFSS PORTA,0 ; EVALUA SI HAY UN 1 EN RA0
GOTO INICIO ; SI NO DETECTA UN 1, REGRESA A INICIO
BSF PORTB,0 ; SI DETECTA UN 1, PONE 1 RB0
GOTO APAGAR ; SALTA A APAGAR
APAGAR
BTFSC PORTA,0 ; EVALUA POR UN 0 EN RA0
GOTO APAGAR ; SINO DETECTA UN 0 REGRESA A APAGAR
BCF PORTB,0 ; SI DETECTA UN 0 PONE A 0 RB0
GOTO INICIO ; REGRESA A INICIO
END
EJEMPLO N°06: Detectar RA0 a RA3 y su valor sale en RB0 a RB3 con Lógica Negativa

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

VAR ; variable

ORG 0
BSF STATUS,5 ; activa la pagina 1
MOVLW B'11111' ; carga 11111 en W
MOVWF TRISA ; puerto A todos Entrada
MOVLW B'00000000' ; carga 00000000 en W
MOVWF TRISB ; puerto B todas Salida
;BCF OPTION_REG,7 ; activa pull-up en puerto B
BCF STATUS,5 ; volvemos a la pagina 0

CLRF PORTA ; ponemos a cero el puerto A

INICIO ; etiqueta
CLRF VAR ; ponemos a cero VAR
BTFSC PORTA,0 ; si RB0 es 0 salta 1 linea
BSF VAR,0 ; pone 1 el bit 0 de VAR, encendido
BTFSC PORTA,1 ; si RB1 es 0 salta 1 linea
BSF VAR,1 ; pone 1 el bit 1 de vAR, encendido
BTFSC PORTA,2 ; si RB2 es 0 salta 1 linea
BSF VAR,2 ; pone 1 el bit 2 de VAR, encendido
BTFSC PORTA,3 ; si RB3 es 0 salta 1 linea
BSF VAR,3 ; pone 1 el bit 3 de VAR, encendido

COMF VAR,0 ; complementa VAR y carga en W (*)


MOVWF PORTB ; carga W en PORTB

GOTO INICIO ; salta a INICIO

END ; fin de programa


EJEMPLO N°07: Detectar el dato en el Puerto A y sale por el Puerto B

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
ORG 0
BSF STATUS,5 ; activa la pagina 1
MOVLW B'11111' ; carga 11111 en W PONE DE ENTRADA RA0
MOVWF TRISA ; Puerto A todas Entradas
MOVLW B'00000000' ; carga 00000000 en W
MOVWF TRISB ; Puerto B todas SalidaS
BCF STATUS,5 ; volvemos a la pagina 0

CLRF PORTB ; APAGA TODOS LOS PINES DE B

INICIO
MOVF PORTA,W
MOVWF PORTB
GOTO INICIO ; REGRESA A INICIO

END

También podría gustarte