Beruflich Dokumente
Kultur Dokumente
Programación de microcontroladores
usos y aplicaciones.
ie
r.m n
e
he g
Desde Ensamblador a C.
in in
sp tro
Familias 8-bit de Microchip:
.e c
w le
PIC10F, PIC12F, PIC16F y PIC18F
w E
www.espinher.mx/cursos/microchip/
w er
nh
www.espinher.mx
cursos@espinher.mx
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
x ría
ie
r.m n
e
he g
in in
sp tro
.e c
w le
w E
w er
nh
r.m n
e
he g
uC uP
in in
sp tro
Microcontroladores Microprocesador
.e c
w le
Propósito específico
8-bit, 16-bit, 32-bit
Propósito general
32-bit a 64-bit
w E
w er
Lenguaje C o C++
Es
x ría
ie
Especificaciones
r.m n
e
he g
uC uP
in in
sp tro
Microcontroladores Microprocesador
.e c
Frecuencia de Frecuencia de
w le
operación operación
w E
<500MHz >1GHz
w er
RAM: Config
nh
> 131,072MB
x ría
ie
Aplicaciones
r.m n
e
he g
uC uP
in in
sp tro
Microcontroladores Microprocesador
.e c
• w le
Controlador Lógico
• Sistemas Operativos:
w E
Linux, Windows, RTOS
Programable o PLC • Computadoras:
w er
• Control de Motores
Teléfonos o Tabletas.
• Control Industrial
nh
• Comunicaciones:
• Control de LED
SATA, Bluray, Video,
Instrumentación
pi
•
Datos y voz.
• Sensores y procesos
Es
• Instrumentación
x ría
ie
Ejemplo de aplicación
r.m n
e
OS Linux Android
he g
in in
sp tro
uP
.e c
w le
w E
uC uC uC uC uC uC uC
w er
nh
pi
Es
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
Universo 32-bit
x ría
x ría
Familia de ARM
ie
r.m n
e
he g
Exynos 5 Samsung Galaxy
in in
Nvidia Tegra, 2, 3, 4
sp tro
Samsung Exynos 3110
.e c
Raspberry
ssd Pi 3
w le
w E
PIC32MZ dsPIC33
w er
Renesas Synergy
nh
STM32 “Discovery”
Es
x ría
automatización industrial
Elementos de un PLC
x ría
ie
Pantalla LCD:
r.m n
alfanumérica o gráfica,
e
Interfaz de Usuario:
monocromática o color,
he g
Teclado matricial, opción táctil
tablero de operador,
in in
botonera,
sp tro
Teclado USB
Comunicación:
.e c
Profibus, Modbus,
PLC
w le
Sensores analógicos:
temperatura, presión,
Fieldbus, AS-i,
HART, SERCOS,
Otro
PLC
w E
luxes, conteo, pH, Sinec, SyncNet,
humedad.
Ethernet,
w er
frecuencia, distancia de
Proceso
pi
Contactor:
Es
ie
r.m n
Puerto J excelente para
e
Puerto B para control bus paralelo de 8-bit
he g
de teclado matricial u
in in
otras entradas de
usuario
sp tro
• USART RS232,
.e c
RS485
w le
Convertidor Analógico a
•
•
SPI
I2C
Otros
uC
w E
Digital de 12-bit con
• Ethernet*
24 canales. • CAN Bus*
w er
Temporizadores
• WiFi*
13 canales
nh
pi
Es
Canales PWM
6 para control
Puerto D Puerto E Puerto F Puerto G
trifásico
x ría
18F87K90 VS. 18F4550
ie
r.m n
Característica PIC18F87K90 PIC18F4550
e
he g
ROM, RAM, EEPROM 128KB, 4KB, 1KB 32KB, 2KB, 0.2KB
in in
Frequencia Max 64MHz (62.5ns) 48MHz* (83.3ns)
sp tro
Puertos E/S ó I/O 69 pines ABCDFGHJ 35 pines ABCDE*
Puertos ADC 24 + 12 Diff 13
.e c
w le
Timers 8-bit/16-bit 6 / 5 = 13 1/3=4
w E
Canales PWM 3 (6) 1 (2)
USART, SPI, I2C 2, 2, 2 1, 1, 1
w er
Reloj Calendario A, M, S, D, H, M, s No
nh
Interrupciones Ext. 4 3
pi
he g
e
PIC18F87K90
r.m n
ie
x ría
Aplicación industrial
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
Aplicacion REAL
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
www.espinher.mx/cursos/microchip/
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
8-bit
x ría
ie
PIC10F322
r.m n
e
he g
in in
PIC16F877A
sp tro
.e c
w le
PIC18F4550
w E
w er
PIC18F87K90
nh
pi
Es
Ensamblador a C
Fundamentos: Registros de Funciones Especiales
x ría
SFR
ie
r.m n
e
he g
in in
sp tro
.e c
w le
w E
w er
nh
pi
Es
Es PIC10F322
pi
nh
w er
w E
w le
.e c
sp tro
76543210
in in
he g
e
r.m n
ie
x ría
0x70
Es
PIC16F877A
pi
nh
w er
w E
w le
.e c
sp tro
76543210
in in
he g
e
r.m n
ie
x ría
0xA8
Es
pi
PIC18F4550
nh
w er
w E
w le
.e c
sp tro
in in
76543210
he g
e
r.m n
ie
x ría
0x82
Special Features of the CPU
x ría
ie
r.m n
e
he g
in in
sp tro
.e c
w le
w E
w er
nh
pi
Es
}
pi
nh
w er
w E
w le
.e c
{
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
Bits de Configuración
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
Bits de Configuración
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
Bits de Configuración
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
Es
pi
nh
w er
w E
w le
.e c
sp tro
in in
he g
e
r.m n
ie
x ría
x ría
Configuración de puertos:
ie
r.m n
e
Habilitar si es para recibir información del exterior
he g
“Entrada”
in in
Registro TRISn = Unos 1111,1111
sp tro
1nput
.e c
w le
w E
Habilitar si es para entregar información al exterior
w er
“Salida”
nh
0utput
Es
Extraer e inyectar información al microcontrolador
x ría
ie
PIC10F322 PIC16F877A
PIC18F4550 PIC18F87K90
r.m n
Entrada Salida
6 pines 40 pines 40 pines 80 pines
e
he g
TRISA * TRISA TRISA TRISA 0xFF 0x00
in in
sp tro
TRISB TRISB TRISB 0xFF 0x00
.e c
w le
TRISD TRISD TRISD 0xFF 0x00
w E
TRISE * TRISE * TRISE 0xFF 0x00
w er
x ría
ie
PIC18F87K90 Valor
r.m n
Entrada Salida
80 pines Binario
e
he g
TRISA = 0xFF DIP Switch 1111,1111
in in
sp tro
TRISB = 0x00 LEDs 0000,0000
.e c
w le
TRISD = 0xaa 4 Entradas 4 Salidas 1010,1010
w E
TRISE = 0xFF Termostatos 1111,1111
w er
x ría
ie
Aplicación
TRISn PORTn
“Lógica positiva”
r.m n
e
0000,0000 1111,1111 Activa todas las electro-válvulas del puerto
he g
in in
0000,0000 0000,1111 Activa sólo 4 electro-válvulas del puerto
sp tro
0000,0000 0000,0001 Activa sólo 1 electro-válvulas del puerto
.e c
1111,1111 1111,1111 8 Termostatos están activados
w le
w E
1111,1111 0000,1111 Sólo 4 termostatos están activados
w er
ie
Fundamentos de Lenguaje Ensamblador
r.m n
e
Instrucción Significado Descripción
he g
in in
movlw Move Literal to Work WREG <= 0xAA
sp tro
movwf Move Work to Floc OSCCON <= WREG
movf Move Floc to Work WREG <= ADCON0
.e c
Bit TMR0ON de T0CON <= 0
bcf w le Bit Clear Floc
Bit 7 de T0CON <= 0
w E
Bit TMR0ON de T0CON <= 1
bsf Bit Set Floc
w er
ie
Fundamentos de Lenguaje Ensamblador
r.m n
Instrucción Operador Descripción
e
he g
0xAA
in in
movlw b’10101010’
WREG <= 0xAA
sp tro
.170
movwf OSCCON OSCCON <= WREG
.e c
movf ADCON0 WREG <= ADCON0
w le
T0CON,TMR0ON
Bit TMR0ON de T0CON <= 0
w E
bcf
T0CON,7 Bit 7 de T0CON <= 0
w er
x ría
Instrucción Operador Descripción
ie
Instrucción
addwf
Operador
ADRESL
WREG <=Descripción
WREG + ADRESL
r.m n
addlw
addwf
0xAA
ADRESL
WREG<=
WREG <=WREG
WREG++ADRESL
0xAA
e
subwf
addlw TMR0
0xAA WREG <= WREG
TMR0 + - 0xAA
WREG
he g
sublw
subwf
0x8F
TMR0
WREG
WREG <=
<= 0x8F
TMR0 - - WREG
WREG
in in
andwf
sublw PERRITO
0x8F WREG
WREG<=<=wreg
0x8F& -PERRITO
WREG
sp tro
andlw
andwf
0xC5
PERRITO
WREG<=<=wreg
WREG wreg& &PERRITO
0xC5
iorwf
andlw GATITO
0xC5 WREG
WREG<=<=wreg
wreg|&GATITO
0xC5
.e c
iorlw
iorwf
0x01
GATITO
WREG<=
WREG <=wreg
wreg||GATITO
0x01
xorwf
iorlw w le
OSCCON
0x01 WREG
WREG<=<=wreg
wreg^|OSCCON
0x01
w E
xorlw
xorwf
0x87
OSCCON
WREG<=
WREG <=wreg
wreg^^OSCCON
0x87
w er
clrf
xorlw T0CON
0x87 WREGT0CON <= 0x00
<= wreg ^ 0x87
clrf
decf T0CON
ADRESH Limpia con ceros
Decrementa en el registro
1 el T0CON
registro
nh
decf
decfsz ADRESH
PERRO Decrementay en
Decrementa 1 el si
brinca registro
es cero
pi
decfsz
incf PERRO
GATITO Decrementa
Incrementay en
brinca
1 el si es cero
registro
Es
incf
incfsz GATITO
CONTADOR Incrementa
Incrementay en
brinca
1 el si es cero
registro
swapf
incfsz TRISC
CONTADOR Incrementa
Intercambia y brinca
nibbles si es cero
el registro TRISC
comf PORTB Invierte cada bit del registro PORTB
Operaciones orientadas a BYTES y Literales
x ría
Instrucción Operador Descripción
ie
setf ADRESH ADRESH <= 0xFF
r.m n
e
btg PORTD,RD0 Cambia el estado del bit RD0
he g
cpfseq PERRITO Compara PERRITO, brinca si es =
in in
cpfsgt GATITO Compara GATITO, brinca si es >
sp tro
cpfslt T0CON Compara T0CON, brinca si es <
.e c
decfsz PERRO Decrementa y brinca si no es cero
incfsz w le
CONTADOR Incrementa y brinca si no es cero
w E
movff CONTA1,CONTA2 CONTA2 <= CONTA1
w er
x ría
ie
r.m n
e
he g
in in
sp tro
.e c
w le
w E
w er
nh
pi
Es
10F322 16F877A
18F4550 18F87K90