Microcontroladores 1ra Parte
-
Upload
jair-eviel-barrios-deluquez -
Category
Documents
-
view
3.626 -
download
5
description
Transcript of Microcontroladores 1ra Parte
![Page 1: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/1.jpg)
MICROCONTROLADORES
M.Sc. César Augusto Peña C.
Profesor de planta – Ingeniería mecatrónicaUniversidad de Pamplona
![Page 2: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/2.jpg)
MICROCONTROLADOR
• Circuito integrado programable capaz de ejecutar las ordenes o comandos que están grabados en su memoria.
• Es un computador dedicado destinado a gobernar una tarea en específico por lo cual tiene unas características limitadas (pero con una gran potencialidad).
![Page 3: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/3.jpg)
APLICACIÓN DE µC
Frenos ABS, Vidrios electricos, Espejos electricos, aire acondicionado,Air Bag, Radio, pantallas de video, reloj, tacometro, velocimetro,
inyectores, enfriamiento del motor, etc…
![Page 4: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/4.jpg)
APLICACIÓN DE µC
![Page 5: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/5.jpg)
APLICACIÓN DE µC
![Page 6: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/6.jpg)
APLICACIÓN DE µC
![Page 7: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/7.jpg)
APLICACIÓN DE µC
![Page 8: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/8.jpg)
APLICACIÓN DE µC
![Page 9: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/9.jpg)
APLICACIÓN DE µC
![Page 10: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/10.jpg)
APLICACIÓN DE µC
![Page 11: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/11.jpg)
APLICACIÓN DE µC
![Page 12: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/12.jpg)
APLICACIÓN DE µC
![Page 14: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/14.jpg)
DIFERENCIA µP y µC
CPU ROM
RAMPUERTOS
PERIFERICOS
MICROCONTROLADOR
CPU
ROM
RAM
PUERTOS
PERIFERICOS
MICROPROCESADOR
![Page 15: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/15.jpg)
PIC 16F84A
• Programación con 35 instrucciones• Max. Velocidad de operación - 20 MHz• Memoria de programa de 1024 palabras• 68 bytes de memoria RAM • 64 bytes de memoria EEPROM• Instrucciones de 14-bit • Datos de 8-bit
• cuatro Interrupciones- Externa por el pin RB0/INT- Desbordamiento timer TMR0- Cambios sobre los pines PORTB<7:4>- Completar escritura EEPROM
![Page 16: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/16.jpg)
ARQUITECTURA PROCESADORES
Memoria de
Instrucciones
+
Datos
Unidad
Central
De
Proceso
Bus común dedirecciones
8
Bus de Datos e
Instrucciones
Arquitectura Von Neumann
![Page 17: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/17.jpg)
ARQUITECTURA PROCESADORES
Memoria de
Instrucciones
1K x 14
Unidad
Central
De
Proceso
Memoria de
Datos
512 x 8
10
Bus de dirección de instrucciones
14
Bus de instrucciones
9
Bus direcciónde datos
8
Bus de Datos
Arquitectura Harvard (memoria de instrucciones y datos independientes)
![Page 18: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/18.jpg)
MEMORIA DE PROGRAMA
• ROM: Se graba en el chip durante el proceso de su fabricación.
• EPROM: Se graba desde un periférico especial de un PC. Posee una ventana de cristal, la cual es sometida a rayos ultravioleta para ser borrada.
• OTP: Se graba como la EPROM, pero una sola vez.• EEPROM: Procesos de escritura/borrado electricamente
con un PC. Garantizan 1’000.000 ciclos E/B.• FLASH: Procesos de escritura/borrado electricamente
con un PC. Garantizan 1’000 ciclos E/B. Son de Bajo consumo y mayor confiabilidad.
![Page 19: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/19.jpg)
MEMORIA DE PROGRAMAVECTOR RESET
VECTOR INTERRUPCIÓN
0000 H
0004 H
03FF H
NO IMPLEMENTADO
0400 H
1FFF H13 0
1kEEPROM
PC
NIVEL 1
NIVEL 2
NIVEL 3
NIVEL 8
.
.
.
![Page 20: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/20.jpg)
MEMORIA DE DATOSINDFTMR0PCL
ESTADOFSR
68 REGISTROSDE PROPOSITO
GENERAL
SFRPUERTO APUERTO B
EEDATAEEADRPCLATHINTCON
GPR
INDFOPTION
PCLESTADO
FSR
MAPEADOS ENEL BANCO 0
TRIS ATRIS B
EECON1EECON2PCLATHINTCON
BANCO 0 BANCO 1
![Page 21: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/21.jpg)
CONFIGURACIÓN PUERTOS PIC16F84
1 1 1 1 0 0 0 0RB7 . . . RB0
REGISTRO TRISB (BANCO 1)
Si el bit asociado al pin esta:• 0 el pin actúa como salida• 1 el pin actúa como entrada
- - - 1 0 1 0 0RA4 . . . RA0
REGISTRO TRISA (BANCO 1)
Pines de salida:• RB3, RB2, RB1, RB0, RA3, RA1, RA0
Pines de entrada:RB7, RB6, RB5, RA4, RA2
![Page 22: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/22.jpg)
USO PUERTOS PIC16F84
1 1 1 1 0 0 0 0
Entradas Salidas
REGISTRO TRISB (BANCO 1)
0 1 0 1 0 0 1 1
REGISTRO PORTB (BANCO 0)
RB7 . . . RB0
![Page 23: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/23.jpg)
REGISTRO DE ESTADO
IRP RP1 RP0 TO# PD# Z DC C7 6 5 4 3 2 1 0
R/W R/W R/W R R R/W R/W R/W
RP1-RP0:00 – Accede al banco 001 – Accede al banco 1
Z: Cero1 – El resultado de una instrucción lógico-aritmética ha sido 00 – El resultado de una instrucción lógico-aritmética NO ha sido 0
DC: (acarreo o llevada en el 4 bit)1 – Ocurre Acarreo0 – No ocurrio Acarreo
C: (acarreo o llevada en el 8 bit)1 – Ocurre Acarreo0 – No ocurrio Acarreo
![Page 24: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/24.jpg)
INSTRUCCIÓN MOVLW k
0 0 0 0 0 1 1 1REGISTRO DE TRABAJO W (WORK)
K W
Ejm: (obsérvese las diferentes formas en que se expresa el decimal 7movlw d’7’movlw .7movlw b’00000111’
x x x x x x x xREGISTRO DE TRABAJO W (WORK)
movlw .7
![Page 25: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/25.jpg)
INSTRUCCIÓN MOVWF f
REGISTRO DE TRABAJO W (WORK)
W F
Ejm: movwf PORTB
1 0 1 1 0 1 0 1Registro W
Movwf PORTB
x x x x x x x xRegistro PORTB
0 0 0 0 0 0 0 0Registro TRISB
1 0 1 1 0 1 0 1Registro PORTB
![Page 26: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/26.jpg)
INSTRUCCIÓN MOVF f,dF Destino
Si d = 0 El destino es WSi d = 1 El destino es la misma fuente
Ejemplo 1:
1 1 0 0 1 1 1 0PORTB
movf PORTB,0
1 1 0 0 1 1 1 0W
Ejemplo 2:
0 0 0 0 0 0 0 0PORTB
movf PORTB,10 0 0 0 0 0 0 0
PORTB
R. ESTADO <2> : Z = 1
R. ESTADO <2> : Z = 0
![Page 27: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/27.jpg)
INSTRUCCIÓN BSF f,b
1 f,b
Ejm:bsf PORTB,1
x x x x x x x xPORTB
bsf PORTB,1 x x x x x x 1 xPORTB
![Page 28: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/28.jpg)
INSTRUCCIÓN BCF f,b
0 f,b
Ejm:bcf PORTB,7
x x x x x x x xPORTB
bcf PORTB,7 0 x x x x x x xPORTB
![Page 29: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/29.jpg)
INSTRUCCIÓN CLRF f
00h f1 z
Ejm:clrf PORTA
x x x x x x x xPORTA
clrf PORTA
0 0 0 0 0 0 0 0PORTA
R. ESTADO <2> : Z = 1
![Page 30: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/30.jpg)
PROGRAMACIÓN;AUTOR: CÉSAR AUGUSTO PEÑA c;PIC: 16F84A;FUNCION: Prende un LED (RA0) si un pulsador NA (RB0) envia un 1 logico;CARACTERISTICAS:;OSCILADOR: XT;WATCHDOG TIMER: OFF;POWER UP TIMER: ON;CODE PROTECT: OFF
INCLUDE "P16F84A.Inc"
ORG 00goto INICIOORG 05
INICIO bsf STATUS,RP0 ;Salta al banco 1clrf TRISA ;Puerto A como salidamovlw b'00000001'movwf TRISB ;RB0 como entradabcf STATUS,RP0 ;Salta al banco 0clrf PORTA ;Pone un 0 logico en las salidasclrf PORTB ;Pone un 0 logico en las salidas
CICLO movf PORTB,0 ;W = PORTBmovwf PORTA ;PORTA = Wgoto CICLOEND
Objetivo: RA0 = RB0 (podria ser una alarma primitiva)
![Page 31: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/31.jpg)
PROGRAMACIÓNINCLUDE "P16F84A.Inc"
;************************** DEFINICION DE REGISTROS*****************************CBLOCK .12
VALOR1ENDC
;*************************************PROGRAMA***************************************ORG 00GOTO INICIO
ORG 05;**************************CONFIGURACION DE PUERTOS**************************INICIO bsf STATUS,5 ;Salta al banco 1
movlw b'11111'movwf TRISA ;Puerto A como entradaclrf TRISB ;Puerto B como salidabcf STATUS,5 ;Salta al banco 0
;__________________________________________________clrf PORTB ;borra puerto B por seguridadmovf PORTA,0 ;W = PORTAmovwf VALOR1 ;VALOR1 = Wmovf VALOR1,1 ;Z=1 si PORTA = b'0000'movlw .7 ;W = 7 (decimal)movwf PORTB ;PORTB = 7 (decimal)movf PORTB,1 ;Z=0 debido a PORTB no es igual ceroEND
Objetivo: Observar en la simulación el funcionamiento del bit Z (cero)
![Page 32: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/32.jpg)
TIPOS DE OSCILADORES
FOSCILACIÓN REXT CEXT
625 KHz 10 K 20 pF80 KHz 10 K 220 pF80 Hz 10 K 0.1 pF
OSCILADOR TIPO RC:
![Page 33: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/33.jpg)
TIPOS DE OSCILADORESOSCILADOR TIPO HS – XT - LP:
![Page 34: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/34.jpg)
FRECUENCIA DE FUNCIONAMIENTO
• Con la frecuencia de trabajo se establece la velocidad en la ejecución de las instrucciones.
1 CicloInstrucción= 4 * TReloj
TReloj = 1 / FrecuenciaTrabajo
TReloj = Periodo del relojfTrabajo = Frecuencia de trabajo
![Page 35: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/35.jpg)
FRECUENCIA DE FUNCIONAMIENTO
1 CicloInstrucción= 4 * TReloj
TReloj = 1 / FrecuenciaTrabajo
Cristal de 4 MHz:
TReloj = 1 / 4000000 = 250ns
1 CicloInstrucción= 4 * 250ns = 1µs
![Page 36: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/36.jpg)
FRECUENCIA DE FUNCIONAMIENTO
Las instrucciones se ejecutan en un tiempo igual a un CicloInstrucción excepto las de salto que tardan dos.
Un programa contiene 100 instrucciones de las cuales 25 son de salto (cristal de 4 MHz)
1 CicloInstrucción= 4 / FrecuenciaTrabajo = 1µs
El programa tarda: 75 * CicloInstrucción+ 25 * 2 * CicloInstrucción
El programa tarda: 125 µs
![Page 37: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/37.jpg)
INSTRUCCIÓN DECFSZ f,d(f – 1) f o W
Ejm: decfsz REG1,1 ;REG1 = REG1 – 1goto SUBRUTINA1 ;si REG1 ≠ 0 se ejecuta la instruccióngoto SUBRUTINA2 ;si REG1 = 0 se ejecuta la instrucción
0 0 0 0 0 0 0 1REG10 0 0 0 0 0 1 1REG1
Ejm: decfsz REG1,1goto SUBRUTINA1goto SUBRUTINA2
Ejm: decfsz REG1,1goto SUBRUTINA1goto SUBRUTINA2
![Page 38: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/38.jpg)
RETARDOS;REGISTROS PARA CONSTRUIR RUTINA DE RETARDO
CBLOCK .12REG1, REG2, REG3
ENDC;VALORES PARA CONSTRUIR RUTINA DE RETARDOVALOR1 EQU d'70' ; retardo 1053850 microsegundosVALOR2 EQU d'70'VALOR3 EQU d'70‘
;SUBRUTINA DE RETARDO:RETARDO movlw VALOR1 ;W = 70
movwf REG1 ;REG1 = WTRES movlw VALOR2 ;W = 70
movwf REG2 ;REG2 = WDOS movlw VALOR3 ;W = 70
movwf REG3 ;REG3 = WUNO decfsz REG3,1 ;DECREMENTA REG3 Y SI QUEDA “0” SALTA A UNO
goto UNOdecfsz REG2,1 ;DECREMENTA REG2 Y SI QUEDA “0” SALTA A DOSgoto DOSdecfsz REG1,1 ;DECREMENTA REG1 Y SI QUEDA “0” SALTA A TRESgoto TRESretlw 0
Total de ciclos = ((valor3*3 + 5) * valor2 + 5) * valor1
![Page 39: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/39.jpg)
INSTRUCCIÓN BTFSC f,bSalta si f<b> = 0
Ejm: btfsc REG1,7 ;verifica el valor del bit 7 de REG1goto SUBRUTINA1 ;si REG1<7>=1 se ejecuta la instruccióngoto SUBRUTINA2 ;si REG1<7>=0 se ejecuta la instrucción
0 0 1 0 0 0 0 1REG11 0 1 0 0 0 1 1REG1
Ejm: btfsc REG1,7goto SUBRUTINA1goto SUBRUTINA2
Ejm: btfsc REG1,7goto SUBRUTINA1goto SUBRUTINA2
![Page 40: Microcontroladores 1ra Parte](https://reader033.fdocuments.mx/reader033/viewer/2022050918/543e15f8afaf9fb40a8b4ef7/html5/thumbnails/40.jpg)
INSTRUCCIÓN BTFSS f,bSalta si f<b> = 1
Ejm: btfss REG1,7 ;verifica el valor del bit 7 de REG1goto SUBRUTINA1 ;si REG1<7>=0 se ejecuta la instruccióngoto SUBRUTINA2 ;si REG1<7>=1 se ejecuta la instrucción
1 0 1 0 0 0 0 1REG10 0 1 0 0 0 1 1REG1
Ejm: btfss REG1,7goto SUBRUTINA1goto SUBRUTINA2
Ejm: btfss REG1,7goto SUBRUTINA1goto SUBRUTINA2