guia02-InstruccionesBasicas
-
Upload
percy-bryan-jove -
Category
Documents
-
view
218 -
download
0
Transcript of guia02-InstruccionesBasicas
-
8/18/2019 guia02-InstruccionesBasicas
1/8
UNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONAL DE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCO
MICROPROCESADORESMICROPROCESADORESMICROPROCESADORESMICROPROCESADORES
GUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIO ECP 1 de 8
I. TEMA : INSTRUCCIONES BASICAS DEL PIC 16F84A
II.
OBJETIVOS
El estudiante al finalizar la práctica será capaz de:
• Identificar las instrucciones ensamblador básicas del PIC 16F84.
• Escribir programas básicos en el lenguaje ensamblador del PIC 16F84.
III.
TRABAJO PREPARATORIO
•
Conocimiento de la arquitectura del microcontrolador 16F84A• Conocer el uso del IDE MPLAB para el desarrollo de aplicaciones en el lenguaje
ensamblador del microcontrolador 16F84A
IV.
MARCO TEORICO
Las características y capacidad de un procesador están definidas por el conjunto de
instrucciones que esta pone a disposición del programador. Por tal razón, es fundamental
conocer el conjunto de instrucciones del microcontrolador que estamos utilizando en la
presente asignatura.
Si bien es cierto que se puede escribir programas para el PIC 16F84A utilizando
lenguajes de alto nivel como el C o el Basic, que permitirían tiempos de desarrollo más
rápidos; en la asignatura, orientada al estudio de los microprocesadores y su
arquitectura, estudiaremos y utilizaremos el lenguaje ensamblador del PIC 16F84A.
El PIC 16F84A comprende un conjunto de 35 instrucciones. Un número pequeño
comparado con las más de 300 instrucciones que tiene un microprocesador como el
Pentium IV de Intel.
Clasificaremos, para su estudio, las instrucciones del microcontrolador 16F84A como
instrucciones básicas e instrucciones avanzadas
INSTRUCCIONES BASICAS
Dentro de estas incluimos las instrucciones aritméticas, de movimiento, lógicas, de
complemento, de puesta en cero, de intercambio y de rotación.
-
8/18/2019 guia02-InstruccionesBasicas
2/8
UNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONAL DE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCO
MICROPROCESADORESMICROPROCESADORESMICROPROCESADORESMICROPROCESADORES
GUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIO ECP 2 de 8
INSTRUCCIONES DE COPIA (MOVIMIENTO)
MOVLW Move Literal to W – Mover literal a W
Sintaxis Operandos Operación Indicadores
movlw k 0 ≤ k ≤ 255 K => W Ninguno
Mueve los 8 bits del literal 'k' al registro de trabajo 'W'.
MOVWF Move W to f – Mover W a F
Sintaxis Operandos Operación Indicadores
movwf f 0≤ f
≤ 127 W => f Ninguno
Mueve el contenido del registro de trabajo 'W' al registro 'f'.
MOVF Move f – Mover F
Sintaxis Operandos Operación Indicadores
movf f,d 0 ≤ f ≤ 127, d ∈ [0,1] f => d Z
Mueve el contenido del registro 'f' al registro destino indicado con 'd'. Si 'd=0' el destino es el registro de trabajo'W'. Si 'd=1' el destino es el propio registro 'f'. El indicador 'Z' del registro 'STATUS' queda afectado: 'Z=1' si el
contenido movido es CERO.
INSTRUCCIONES DE SUMA
ADDLW Add Literal to W – Sumar literal a W
Sintaxis Operandos Operación Indicadores
addlw k 0 ≤ k ≤ 255 k + W => W C, DC, Z
Suma los 8 bits del literal 'k' con el registro de trabajo 'W' y el resultado lo almacena en el registro de trabajo 'W'.
ADDWF Add W and f – Sumar W y F
Sintaxis Operandos Operación Indicadores
addwf f,d 0 ≤ f ≤ 127, d ∈ [0,1] f + W => d C, DC, Z
Suma el contenido del registro 'f' al contenido del registro de trabajo 'W' y el resultado se almacena en el destino'd'. Si 'd=0' el destino es el registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'.
-
8/18/2019 guia02-InstruccionesBasicas
3/8
UNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONAL DE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCO
MICROPROCESADORESMICROPROCESADORESMICROPROCESADORESMICROPROCESADORES
GUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIO ECP 3 de 8
INSTRUCCIONES DE SUSTRACCIÓN
SUBLW Subtract W from Literal – Restar W de literal
Sintaxis Operandos Operación Indicadores
sublw k 0 ≤ k ≤ 255 k - W => W C, DC, Z
Resta de los 8 bits del literal 'k' el contenido del registro de trabajo 'W' y el resultado lo almacena en el registro detrabajo 'W'.
SUBWF Subtract W from f – Restar W de F
Sintaxis Operandos Operación Indicadores
subwf f,d 0 ≤ f ≤ 127, d ∈ [0,1] f - W => d C, DC, Z
Resta del contenido del registro 'f' el contenido del registro de trabajo 'W' y el resultado se almacena en el destino
'd'. Si 'd=0' el destino es el registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'.
INSTRUCCIONES DE PUESTA EN CERO
CLRW Clear W – Limpiar W
Sintaxis Operandos Operación Indicadores clrw ninguno 0 => W Z
Carga cero al registro de trabajo 'W' y se establece el indicador cero, 'Z=1'.
CLRF Clear f – Limpiar F
Sintaxis Operandos Operación Indicadores
clrf f 0 ≤ f ≤ 127 0 => f Z
Carga cero al registro 'f' y se establece el indicador cero, 'Z=1'.
INSTRUCCIONES DE INCREMENTO Y DECREMENTO
DECF Decrement f – Decrementar F
Sintaxis Operandos Operación Indicadores
decf f,d 0 ≤ f ≤ 127, d ∈ [0,1] f - 1 => d Z
Decrementa el contenido del registro 'f'. Si 'd=0' el destino es el registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'. Si el resultado del incremento es cero, se establece el indicador cero, 'Z=1'.
-
8/18/2019 guia02-InstruccionesBasicas
4/8
UNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONAL DE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCO
MICROPROCESADORESMICROPROCESADORESMICROPROCESADORESMICROPROCESADORES
GUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIO ECP 4 de 8
INCF Increment f – Incrementar F
Sintaxis Operandos Operación Indicadores
incf f,d 0 ≤ f ≤ 127, d ∈ [0,1] f + 1 => d Z
Incrementa el contenido del registro 'f'. Si 'd=0' el destino es el registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'. Si el resultado del decremento es cero, se establece el indicador cero, 'Z=1'.
INSTRUCCIÓN LÓGICA Y (AND)
ANDLW And Literal with W – And literal con W
Sintaxis Operandos Operación Indicadores
andlw k 0 ≤ k ≤ 255 k .AND. W => W Z
Efectúa la operación AND de los 8 bits del literal 'k' con el registro 'W' y almacena el resultado en 'W'. Actualizael indicador 'Z'.
ANDWF And W with f – And W con F
Sintaxis Operandos Operación Indicadores
andwf f,d 0 ≤ f ≤ 127, d ∈ [0,1] f .AND. W => d Z
Efectúa la operación AND del contenido del registro 'f' con el registro 'W' y almacena el resultado en 'd'. Si 'd=0'el destino es el registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'. Actualiza el indicador 'Z'.
INSTRUCCIÓN LÓGICA O – INCLUSIVA (OR)
IORLW Inclusive OR Literal with W – Or literal con W
Sintaxis Operandos Operación Indicadores
iorlw k 0 ≤ k ≤ 255 k .OR. W => W Z
Efectúa la operación OR de los 8 bits del literal 'k' con el registro 'W' y almacena el resultado en 'W'. Actualiza elindicador 'Z'.
IORWF Includive OR W with f – Or W con F
Sintaxis Operandos Operación Indicadores
iorwf f,d 0 ≤ f ≤ 127, d ∈ [0,1] f .OR. W => d Z
Efectúa la operación OR del contenido del registro 'f' con el registro 'W' y almacena el resultado en 'd'. Si 'd=0' eldestino es el registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'. Actualiza el indicador 'Z'.
-
8/18/2019 guia02-InstruccionesBasicas
5/8
UNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONAL DE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCO
MICROPROCESADORESMICROPROCESADORESMICROPROCESADORESMICROPROCESADORES
GUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIO ECP 5 de 8
INSTRUCCIÓN LÓGICA O – EXCLUSIVA (XOR)
XORLW Exclusive OR Literal with W – Xor literal con W
Sintaxis Operandos Operación Indicadores
xorlw k 0 ≤ k ≤ 255 k .XOR. W => W Z
Efectúa la operación XOR de los 8 bits del literal 'k' con el registro 'W' y almacena el resultado en 'W'. Actualizael indicador 'Z'.
XORWF Exclusive OR W with f – Xor W con F
Sintaxis Operandos Operación Indicadores
xorwf f,d 0 ≤ f ≤ 127, d ∈ [0,1] f .XOR. W => d Z
Efectúa la operación XOR del contenido del registro 'f' con el registro 'W' y almacena el resultado en 'd'. Si 'd=0'
el destino es el registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'. Actualiza el indicador 'Z'.
INSTRUCCIÓN DE COMPLEMENTO
COMF Complement f – complementar F
Sintaxis Operandos Operación Indicadores comf f,d 0 ≤ f ≤ 127, d ∈ [0,1] ~f => d Z
Efectúa el complemento bit a bit del contenido del registro 'f' y almacena el resultado en 'd'. Si 'd=0' el destino esel registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'. Actualiza el indicador 'Z'.
INSTRUCCIÓN DE INTERCAMBIO DE NIBBLES
SWAPF Swap Nibbles in f – Intercambiar nibbles en F
Sintaxis Operandos Operación Indicadores
swapf f,d 0 ≤ f ≤ 127, d ∈ [0,1] f[3:0]=>d[7:4],f[7:4]=>d[3:0] ninguno
Efectúa el intercambio del nibble menos significativo con el nibble más significativo del registro 'f' y almacena el
resultado en 'd'. Si 'd=0' el destino es el registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'. Actualiza el indicador 'Z'.
-
8/18/2019 guia02-InstruccionesBasicas
6/8
UNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONAL DE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCO
MICROPROCESADORESMICROPROCESADORESMICROPROCESADORESMICROPROCESADORES
GUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIO ECP 6 de 8
INSTRUCCIONES DE ROTACIÓN
RLF Rotate Left f through Carry – Rotar F a la izquierda a través del bit de Acarreo
Sintaxis Operandos Operación Indicadores
rlf f,d 0 ≤ f ≤ 127, d ∈ [0,1] C
Rota un bit a la izquierda, el contenido del registro 'f' pasando por el indicador de acarreo 'C' y almacena elresultado en 'd'. Si 'd=0' el destino es el registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'. Actualiza el indicador 'C'.
RRF Rotate Right f through Carry - Rotar F a la derecha a través del bit de Acarreo
Sintaxis Operandos Operación Indicadores
rrf f,d 0 ≤ f ≤ 127, d ∈ [0,1] C
Rota un bit a la derecha, el contenido del registro 'f' pasando por el indicador de acarreo 'C' y almacena el
resultado en 'd'. Si 'd=0' el destino es el registro de trabajo 'W'. Si 'd=1' el destino es el propio registro 'f'. Actualiza el indicador 'C'.
V. DESARROLLO DE LA PRACTICA
1. Escriba un programa que calcule la diferencia de dos números de 8 bits, sin utilizar
las instrucciones de sustracción
Solución
;*******************************************************;
; Nombre : apComplemento ;
; Proposito : Calcula la diferencia entre dos variables ;
; Autor : Edwin Carrasco ;
; FCreacion : 31/12/2007 ;
; FModificacion : ------ ;
;*******************************************************;
LIST P=16f84A ; Modelo de PIC utilizado
INCLUDE ; Contiene definiciones de elementos del PIC
;********DATOS
num1 equ 0xA ; primer numero
num2 equ 0xB ; segundo numero
-
8/18/2019 guia02-InstruccionesBasicas
7/8
UNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONAL DE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCO
MICROPROCESADORESMICROPROCESADORESMICROPROCESADORESMICROPROCESADORES
GUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIO ECP 7 de 8
resul equ 0xC ; almacena la diferencia
;********CODIGOORG 0 ; Indica donde comienza el programa
Inicio
movlw .20 ; W
-
8/18/2019 guia02-InstruccionesBasicas
8/8
UNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONALUNIVERSIDAD NACIONAL DE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCODE SAN ANTONIO ABAD DEL CUSCO
MICROPROCESADORESMICROPROCESADORESMICROPROCESADORESMICROPROCESADORES
GUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIOGUIA DE LABORATORIO ECP 8 de 8
xorwf v1, 1 ; v1