Académique Documents
Professionnel Documents
Culture Documents
Tema 6: Microcontroladores
Carlos Garre del Olmo
Microcontroladores
Contenidos
MICROPROCESADORES
Palabra de Configuracin
MICROPROCESADORES
Modo SLEEP
MICROPROCESADORES
PIC16F87xA
MICROPROCESADORES
16F876A: 28 pines.
16F877A: Exactamente igual pero con 40 pines (3 ms analgicos, y 9
ms digitales). Comparten el mismo datasheet!
16F873A: Versin reducida del 16F876 (/2 las tres memorias).
16F874A: Versin reducida del 16F877 (/2 las tres memorias).
Nos centramos en el 16F876A:
Arquitectura PIC16F876A
MICROPROCESADORES
16F876A: Interrupciones
MICROPROCESADORES
10
1.
Configurar mdulo A/D: TRIS (=entradas), PCFG, ADFM (=1), ADCS (=001),
ADON (=1).
Configurar interrupciones: ADIF (=0), ADIE (=1), PEIE (=1), GIE (=1). PEIE
es la mscara para todas las interrupciones nuevas con respecto al 16F84
(llamadas interrupciones de perifricos).
Seleccionar un canal (CHS).
Activar el bit GO/DONE Momento en el que muestreamos.
Esperar fin de conversin:
2.
3.
4.
5.
6.
7.
11
Microcontroladores
Contenidos
MICROPROCESADORES
12
Entornos de Desarrollo
MICROPROCESADORES
13
ADDWF f,d:
Si d=0: W = W + f.
Si d=1: f = W + f
f es un registro de 0 a 127: direccionamiento directo o indirecto (INDF).
Modifica flags Z, C, DC.
CLRF f: f = 0.
CLRW: W = 0.
COMF f,d: W/f = NOT(f).
DECF f,d: W/f = f 1
DECFSZ f,d: SZ = Skip if Zero. Si el resultado del decremento es 0, entonces
convierte la prxima instruccin en un NOP.
MOVF f,d: W/f = f.
MOVWF f: f = W.
RLF f,d: Rotate Left through carry.
SUBWF f,d: W/f = f W
SWAPF f,d: d<7,4> = f<3:0>; d<3,0> = f<7,4>
ANDWF, INCF, INCFSZ, IORWF, NOP, RRF, XORWF.
ESCUELA TCNICA SUPERIOR DE
INGENIERA INFORMTICA
14
Operaciones de Bit:
BCF f,b: Pone a 0 el bit b del registro f.
BSF f,b: Pone a 1 el bit b del registro f.
BTFSC f,b: Si el bit b del registro f es 0, convertimos la siguiente instruccin en un
NOP.
BTFSS f,b: Si el bit b del registro f es 1, convertimos la siguiente instruccin en un
NOP.
Operaciones de Control:
CALL k:
PC se guarda en la pila.
PC<10:0> = k (k es de 11 bits).
PC<12:11> = PCLATH<4:3> (PCLATH se usa para cambiar de pgina).
Es una instruccin de 2 ciclos!
15
ADDLW k: W = W + k (k es de 8 bits).
ANDLW k: W = W and k
processor
IORLW k: W = W or k
radix DEC
MOVLW k: W = k
PORTA
EQU
0x05
SUBLW k: W = k W
OPTION EQU
0x03
XORLW k: W = W xor k
TRISA
EQU
0x85
RP0
EQU
16F84A
GOTO main
main
BSF
CLRF
BCF
BCF
BSF
GOTO
PORTA,0
PORTA,0
loop
loop
; Apagamos led
; Encendemos led
; bucle infinito...
END
ESCUELA TCNICA SUPERIOR DE
INGENIERA INFORMTICA
16
PIC16: Programacin en C
MICROPROCESADORES
#include <pic16f876a.h>
void main(void)
{
TRISA = 0; // Puerto A = salidas
// Bucle infinito...
while (1)
{
RA0 = 0; // Apagamos led
RA0 = 1; // Encendemos led
}
}
17
Proceso de Desarrollo
MICROPROCESADORES
1.
2.
3.
4.
5.
6.
7.
8.
18