Vous êtes sur la page 1sur 18

Microcontrolador PIC16F87x

1.1. Enumeracion de caractersticas


La familia de microcontroladores de Microchip PIC16F87x est compuesta por 4 a modelos diferentes denominados: PIC16F873, PIC16F874, PIC16F876 y PIC16F877.

1.1.1. Prestaciones
35 instrucciones (compatibles con el juego de instrucciones de toda la familia PIC16).
Cada instruccion dura un ciclo de instruccion (4 ciclos de reloj) a excepcion de las que involucran saltos (2 ciclos de instruccion).
Velocidad: 20 MHz (T = 50 ns), ciclo de instruccion: 200 ns.
Hasta 8k x 14 memoria de programa Flash.
Hasta 368 x 8 memoria de datos RAM, vol til. a
Hasta 256 x 8 memoria de datos EEPROM, no vol til. a
Hasta 14 fuentes de interrupcion diferentes (segun modelo).
Pila hardware de 8 niveles.
Direccionamiento directo, indirecto y relativo.
Power-on reset (POR). Reset de arranque.
Power-up Timer (PWRT): temporizador de arranque y Oscillator Startup Timer (OST): temporizador de arranque del oscilador.
Watchdog Timer (WDT): temporizador perro guardi n, con red RC integrada. a

Proteccion del codigo programable.


Modo de bajo consumo con la instruccion SLEEP.
Tipo de oscilador seleccionable.
Diseno est tico de baja potencia y alta velocidad. a
Programable en el sistema (ICSP: In-Circuit Serial Programming).
In-Circuit Debugging (ICD): depuracion en circuito.
Posibilidad de leer/escribir en la memoria de programa: posibilidad de implementar un programa cargador de arranque (bootloader).
Tension de alimentacion variable entre 2.0 V y 5.5 V.
E/S de alta corriente (m ximo 25 mA). a
Bajo consumo: < 2mA @ 5V, 4 MHz < 1uA en modo SLEEP.

1.1.2. Perif ricos integrados e


Temporizador/contador TMR0, de 8 bits con pre-escala de 8 bits.
Temporizador/contador TMR1, de 16 bits con pre-escala. Funciona en modo SLEEP va cristal externo.
Temporizador/contador TMR2, de 8 bits con registro periodo de 8 bits, pre-escala y post-escala.
Dos modulos CCP: Captura/Comparacion/PWM (Pulse Width Modulation: Mo dulacion por Anchura de Pulsos). Captura de 16 bits (m xima resolucion: 12.5 ns). a Comparacion de 16 bits (m xima resolucion: 200 ns). a PWM (m xima resolucion: 10 bits). a
Conversor Analogico/Digital de 10 bits multicanal (5 u 8 dependiendo del modelo).
Puerto serie sncrono (MSSP: Master Synchronous Serial Port). Compatible SPI (Serial Peripheral Interface) en modo maestro. Compatible I2C (Inter-Integrated Circuit) en modos maestro y esclavo.
Receptor/Transmisor Serie Asncrono/Sncrono Universal (USART) tambi n lla e mado Serial Communications Interface (SCI) con deteccion de direcciones de 9 bits.

Puerto paralelo esclavo (PSP: Parallel Slave Port) de 8 bits con control externo a trav s de senales /RD, /WR y /CS. e
Brown-out reset (BOR): reset al bajar la tension de alimentacion por debajo de un umbral (4 V).

1.2. Modelos y caractersticas particulares


Las diferencias entre los modelos se resumen en la siguiente tabla:
Key Features PICmicro Mid-Range Reference Manual (DS33023) Operating Frequency Resets (and Delays) FLASH Program Memory (14-bit words) Data Memory (bytes) EEPROM Data Memory Interrupts I/O Ports Timers Capture/Compare/PWM modules Serial Communications Parallel Communications 10-bit Analog-to-Digital Module Instruction Set PIC16F873 DC - 20 MHz POR, BOR (PWRT, OST) 4K 192 128 13 Ports A,B,C 3 2 MSSP, USART 5 input channels 35 Instructions PIC16F874 DC - 20 MHz POR, BOR (PWRT, OST) 4K 192 128 14 Ports A,B,C,D,E 3 2 MSSP, USART PSP 8 input channels 35 Instructions PIC16F876 DC - 20 MHz POR, BOR (PWRT, OST) 8K 368 256 13 Ports A,B,C 3 2 MSSP, USART 5 input channels 35 Instructions PIC16F877 DC - 20 MHz POR, BOR (PWRT, OST) 8K 368 256 14 Ports A,B,C,D,E 3 2 MSSP, USART PSP 8 input channels 35 Instructions

Existen estos mismos modelos en su revision A (ej.: PIC16F877A). Segun el fabrican te no hay ninguna diferencia salvo el m todo de grabacion empleado y quiz s alguna e a variacion sin importancia en sus caractersticas el ctricas. e Tambi n existen los modelos LF (ej.: PIC16LF877A) de menor consumo y que puee den funcionar a tensiones de alimentacion de hasta 2.0 voltios, frente a los 4.0 voltios de los modelos normales.

1.3. Patillaje
PIC16F873 y PIC16F876 Tienen un encapsulado de 28 patillas como se puede ver en la gura:

DIP, SOIC
MCLR/VPP/THV RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS VSS OSC1/CLKIN OSC2/CLKOUT RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL 1 2 3 4 5 6 7 8 9 10 11 12 13 14 28 27 26 25 24 23 22 21 20 19 18 17 16 15 RB7/PGD RB6/PGC RB5 RB4 RB3/PGM RB2 RB1 RB0/INT VDD VSS RC7/RX/DT RC6/TX/CK RC5/SDO RC4/SDI/SDA

PIC16F874 y PIC16F877 Tienen un encapsulado de 40 patillas como se puede ver en la gura:

PDIP
MCLR/VPP/THV RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS RE0/RD/AN5 RE1/WR/AN6 RE2/CS/AN7 VDD VSS OSC1/CLKIN OSC2/CLKOUT RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RD0/PSP0 RD1/PSP1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 RB7/PGD RB6/PGC RB5 RB4 RB3/PGM RB2 RB1 RB0/INT VDD VSS RD7/PSP7 RD6/PSP6 RD5/PSP5 RD4/PSP4 RC7/RX/DT RC6/TX/CK RC5/SDO RC4/SDI/SDA RD3/PSP3 RD2/PSP2

Descripcion del patillaje En los siguientes esquemas se describe el patillaje de estos microcontroladores:

PIC16F877/874

PIC16F876/873

Pin Name OSC1/CLKIN OSC2/CLKOUT

DIP Pin# 13 14

PLCC Pin# 14 15

QFP Pin# 30 31

I/O/P Type I O

Buffer Type ST/CMOS(4)

Description Oscillator crystal input/external clock source input. Oscillator crystal output. Connects to crystal or resonator in crystal oscillator mode. In RC mode, OSC2 pin outputs CLKOUT which has 1/4 the frequency of OSC1, and denotes the instruction cycle rate. Master clear (reset) input or programming voltage input or high voltage test mode control. This pin is an active low reset to the device. PORTA is a bi-directional I/O port. RA0 can also be analog input0 RA1 can also be analog input1 RA2 can also be analog input2 or negative analog reference voltage RA3 can also be analog input3 or positive analog reference voltage RA4 can also be the clock input to the Timer0 timer/ counter. Output is open drain type. RA5 can also be analog input4 or the slave select for the synchronous serial port. PORTB is a bi-directional I/O port. PORTB can be software programmed for internal weak pull-up on all inputs.

MCLR/VPP/THV

18

I/P

ST

RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/SS/AN4

2 3 4 5 6 7

3 4 5 6 7 8

19 20 21 22 23 24

I/O I/O I/O I/O I/O I/O

TTL TTL TTL TTL ST TTL

RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD

33 34 35 36 37 38 39 40

36 37 38 39 41 42 43 44

8 9 10 11 14 15 16 17

I/O I/O I/O I/O I/O I/O I/O I/O

TTL/ST(1) TTL TTL TTL TTL TTL TTL/ST(2) TTL/ST(2)

RB0 can also be the external interrupt pin.

RB3 can also be the low voltage programming input Interrupt on change pin. Interrupt on change pin. Interrupt on change pin or In-Circuit Debugger pin. Serial programming clock. Interrupt on change pin or In-Circuit Debugger pin. Serial programming data. PORTC is a bi-directional I/O port.

RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT Legend: Note 1: 2: 3: 4: I = input

15 16 17 18 23 24 25 26

16 18 19 20 25 26 27 29

32 35 36 37 42 43 44 1

I/O I/O I/O I/O I/O I/O I/O I/O

ST ST ST ST ST ST ST ST

RC0 can also be the Timer1 oscillator output or a Timer1 clock input. RC1 can also be the Timer1 oscillator input or Capture2 input/Compare2 output/PWM2 output. RC2 can also be the Capture1 input/Compare1 output/ PWM1 output. RC3 can also be the synchronous serial clock input/output for both SPI and I2C modes. RC4 can also be the SPI Data In (SPI mode) or data I/O (I2C mode). RC5 can also be the SPI Data Out (SPI mode). RC6 can also be the USART Asynchronous Transmit or Synchronous Clock. RC7 can also be the USART Asynchronous Receive or Synchronous Data.

O = output I/O = input/output P = power = Not used TTL = TTL input ST = Schmitt Trigger input This buffer is a Schmitt Trigger input when configured as an external interrupt. This buffer is a Schmitt Trigger input when used in serial programming mode. This buffer is a Schmitt Trigger input when configured as general purpose I/O and a TTL input when used in the Parallel Slave Port mode (for interfacing to a microprocessor bus). This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.

Pin Name

DIP Pin#

PLCC Pin#

QFP Pin#

I/O/P Type

Buffer Type

Description PORTD is a bi-directional I/O port or parallel slave port when interfacing to a microprocessor bus.

RD0/PSP0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7

19 20 21 22 27 28 29 30

21 22 23 24 30 31 32 33

38 39 40 41 2 3 4 5

I/O I/O I/O I/O I/O I/O I/O I/O

ST/TTL(3) ST/TTL(3) ST/TTL(3) ST/TTL(3) ST/TTL(3) ST/TTL(3) ST/TTL(3) ST/TTL(3) PORTE is a bi-directional I/O port. ST/TTL(3) ST/TTL(3) ST/TTL(3) RE0 can also be read control for the parallel slave port, or analog input5. RE1 can also be write control for the parallel slave port, or analog input6. RE2 can also be select control for the parallel slave port, or analog input7. Ground reference for logic and I/O pins. Positive supply for logic and I/O pins. These pins are not internally connected. These pins should be left unconnected.

RE0/RD/AN5 RE1/WR/AN6 RE2/CS/AN7 VSS VDD NC Legend: Note 1: 2: 3: 4: I = input

8 9 10 12,31 11,32

9 10 11 13,34 12,35 1,17,28, 40

25 26 27 6,29 7,28 12,13, 33,34

I/O I/O I/O P P

O = output I/O = input/output P = power = Not used TTL = TTL input ST = Schmitt Trigger input This buffer is a Schmitt Trigger input when configured as an external interrupt. This buffer is a Schmitt Trigger input when used in serial programming mode. This buffer is a Schmitt Trigger input when configured as general purpose I/O and a TTL input when used in the Parallel Slave Port mode (for interfacing to a microprocessor bus). This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.

1.4. Arquitectura interna


1.4.1. Modelos 16F874 y 16F877
Device PIC16F874 PIC16F877 Program FLASH 4K 8K Data Memory 192 Bytes 368 Bytes
13 FLASH Program Memory 8 Level Stack (13-bit) Program Bus 14 Instruction reg Direct Addr 7 Program Counter

Data EEPROM 128 Bytes 256 Bytes


Data Bus 8 PORTA RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS PORTB RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT PORTD W reg RD7/PSP7:RD0/PSP0

RAM File Registers

RAM Addr (1)

Addr MUX 8 Indirect Addr

FSR reg STATUS reg 8 3 PORTC

Power-up Timer Instruction Decode & Control Timing Generation OSC1/CLKIN OSC2/CLKOUT Oscillator Start-up Timer Power-on Reset Watchdog Timer Brown-out Reset In-Circuit Debugger Low-Voltage Programming 8

MUX

ALU

Parallel Slave Port

PORTE RE0/AN5/RD RE1/AN6/WR

MCLR

VDD, VSS

RE2/AN7/CS

Timer0

Timer1

Timer2

10-bit A/D

Data EEPROM

CCP1,2

Synchronous Serial Port

USART

1.4.2. Modelos 16F873 y 16F876


Device PIC16F873 PIC16F876 Program FLASH 4K 8K Data Memory 192 Bytes 368 Bytes
13 Program Counter FLASH Program Memory 8 Level Stack (13-bit) Program Bus 14 Instruction reg Direct Addr 7

Data EEPROM 128 Bytes 256 Bytes


Data Bus 8 PORTA RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS PORTB RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT

RAM File Registers

RAM Addr (1)

Addr MUX 8 Indirect Addr

FSR reg STATUS reg 8 3 PORTC

Power-up Timer Instruction Decode & Control Timing Generation OSC1/CLKIN OSC2/CLKOUT Oscillator Start-up Timer Power-on Reset Watchdog Timer Brown-out Reset In-Circuit Debugger Low-Voltage Programming 8

MUX

ALU

W reg

MCLR

VDD, VSS

Timer0

Timer1

Timer2

10-bit A/D

Data EEPROM

CCP1,2

Synchronous Serial Port

USART

1.5. Organizacion de la memoria


La memoria se divide en memoria de programa y memoria de datos ya que esta familia de microcontroladores implementan una arquitectura Harvard.

1.5.1. Memoria de programa


Se direcciona con el contador de programa que tiene 13 bits.
En el microcontrolador PIC16F877/876 la memoria es de 8k x 14 bit.
En el microcontrolador PIC17F874/873 la memoria es de 4k x 14 bit.
El microcontrolador comienza la ejecucion en la posicion 0 de la memoria de programa.
Cuando se produce una interrupcion se salta a la posicion 4 de la memoria de programa.
Dispone de una pila hardware de 8 niveles para los retornos de las subrutinas o interrupciones exclusivamente.
a La memoria de programa est dividida en bloques o p ginas de 2k x14 bits. Esto a ser importante cuando usemos las instrucciones de salto (GOTO o CALL). a
PC<12:0>

CALL, RETURN RETFIE, RETLW

13

Stack Level 1 Stack Level 2

Stack Level 8

Reset Vector

0000h

Interrupt Vector

0004h 0005h

Page 0 07FFh 0800h Page 1 On-Chip Program Memory Page 2 17FFh 1800h Page 3 1FFFh 0FFFh 1000h

1.5.2. Memoria de datos


La memoria de datos est dividida en dos bloques: uno implementado en RAM y a que describimos a continuacion y otro bloque independiente implementado en memoria EEPROM que se ver m s adelante. La memoria RAM de datos tiene las siguientes a a caractersticas:
En el microcontrolador PIC16F877/876 la RAM es de 368 bytes.
En el microcontrolador PIC16F874/873 la RAM es de 192 bytes.
Est dividida en 4 bancos de 128 posiciones. a
Hay que seleccionar el banco accesible mediante los bits STATUS.RP1:RP0.
En las primeras 32 posiciones de la RAM se encuentran mapeados los registros de proposito especco (SFR: Special Function Registers).
El resto ser n posiciones para los registros de proposito general (GPR: General a Purpose Registers).

1.5.3. Registros de proposito especco


A continuacion se muestra un esquema general:

File Address Indirect addr.(*) TMR0 PCL STATUS FSR PORTA PORTB PORTC PORTD (1) PORTE (1) PCLATH INTCON PIR1 PIR2 TMR1L TMR1H T1CON TMR2 T2CON SSPBUF SSPCON CCPR1L CCPR1H CCP1CON RCSTA TXREG RCREG CCPR2L CCPR2H CCP2CON ADRESH ADCON0 00h 01h 02h 03h 04h 05h 06h 07h 08h 09h 0Ah 0Bh 0Ch 0Dh 0Eh 0Fh 10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1Ah 1Bh 1Ch 1Dh 1Eh 1Fh 20h Indirect addr.(*) 80h OPTION_REG 81h PCL 82h STATUS 83h FSR 84h TRISA 85h TRISB 86h TRISC 87h TRISD (1) 88h TRISE (1) 89h PCLATH 8Ah INTCON 8Bh PIE1 8Ch PIE2 8Dh PCON 8Eh 8Fh 90h 91h SSPCON2 PR2 92h SSPADD 93h SSPSTAT 94h 95h 96h 97h 98h TXSTA 99h SPBRG 9Ah 9Bh 9Ch 9Dh ADRESL 9Eh 9Fh ADCON1 A0h General Purpose Register 80 Bytes accesses 70h-7Fh 7Fh Bank 0 Bank 1 Indirect addr.(*) 100h 101h TMR0 102h PCL 103h STATUS 104h FSR 105h 106h PORTB 107h 108h 109h 10Ah PCLATH 10Bh INTCON 10Ch EEDATA EEADR 10Dh 10Eh EEDATH 10Fh EEADRH 110h 111h 112h 113h 114h 115h 116h General 117h Purpose 118h Register 119h 16 Bytes 11Ah 11Bh 11Ch 11Dh 11Eh 11Fh 120h Indirect addr.(*) OPTION_REG PCL STATUS FSR TRISB 180h 181h 182h 183h 184h 185h 186h 187h 188h 189h 18Ah 18Bh 18Ch 18Dh 18Eh 18Fh 190h 191h 192h 193h 194h 195h 196h 197h 198h 199h 19Ah 19Bh 19Ch 19Dh 19Eh 19Fh 1A0h General Purpose Register 80 Bytes accesses 70h - 7Fh Bank 3

PCLATH INTCON EECON1 EECON2 Reserved(2) Reserved(2)

General Purpose Register 16 Bytes

General Purpose Register 96 Bytes

EFh F0h FFh

General Purpose Register 80 Bytes accesses 70h-7Fh Bank 2

16Fh 170h 17Fh

1EFh 1F0h 1FFh

Unimplemented data memory locations, read as 0. * Not a physical register. Note 1: These registers are not implemented on 28-pin devices. 2: These registers are reserved, maintain these registers clear.

Descripcion de algunos registros


STATUS. Presente en todos los bancos. Registro de estado y control.

STATUS
Bit 7 6 5 4 3 2 1 Bit 0

IRP

RP1

RP0

/TO

/PD

DC

IRP Seleccion de banco para direccionamiento indirecto. 0: Selecciona bancos 0 y 1. 1: Selecciona bancos 2 y 3. RP1:RP0 Seleccion de banco con direccionamiento directo. 00: 01: 10: 11: Banco 0. Banco 1. Banco 2. Banco 3.

/TO Indica un desbordamiento del temporizador del perro guardi n. a 0: Desbordamiento (timeout) del perro guardi n. a 1: Despu s de un arranque normal, o la ejecucion de las instrucciones CLRWDT o SLEEP. e /PD Indica el paso al modo de bajo consumo (power down). 0: Ejecutada una instruccion SLEEP. 1: Despu s de un arranque o la ejecucion de CLRWDT. e Z Cero. 0: El resultado de la ultima instruccion aritm tica o logica no fue cero. e 1: El resultado de la ultima instruccion aritm tica o logica fue cero. e DC Acarreo de dgito o semiacarreo. 0: No hubo acarreo. 1: Acarreo hacia el bit 4. C Acarreo o la que me llevo despu s de la ultima operacion aritm tica o logica. e e 0: No hubo acarreo. 1: Acarreo hacia el bit 9.
OPTION_REG. Presente en los bancos 1 y 3. Registro de opciones.

OPTION REG
Bit 7 6 5 4 3 2 1 Bit 0

/RBPU

INTEDG

T0CS

T0SE

PSA

PS2

PS1

PS0

/RBPU Bit de habilitacion de las resistencias internas de pull-up del PORTB. 0: Activado. 1: Desactivado. INTEDG Seleccion del anco del pin RB0/INT. 0: Flanco de bajada. 1: Flanco de subida. T0CS Seleccion de la fuente de reloj para el temporizador 0.

0: Ciclo de instruccion interno. Equivale a 4 ciclos de reloj del microcontrolador. 1: Transicion en la patilla RA4/T0CKI. T0SE Seleccion de anco para la fuente externa del temporizador 0. 0: Se incrementar en el anco de subida de RA4/T0CKI. a 1: Se incrementar en el anco de bajada de RA4/T0CKI. a PSA Asignacion del divisor de frecuencia. 0: Pre-escala asignada al temporizador TMR0. 1: Divisor asignado al perro guardi n (WDT) como post-escala. a PS2:PS0 Divisor de frecuencia. Bits 000 001 010 011 100 101 110 111
PSA=0 (TMR0) 1:2 1:4 1:8 1:16 1:32 1:64 1:128 1:256
PSA=1 (WDT) 1:1 1:2 1:4 1:8 1:16 1:32 1:64 1:128

INTCON. Presente en todos los bancos. Registro de control y noticacion de interrupciones. INTCON
Bit 7 6 5 4 3 2 1 Bit 0

GIE

PEIE

T0IE

INTE

RBIE

T0IF

INTF

RBIF

GIE Habilitacion global de las interrupciones. 0: Deshabilita. 1: Habilita. PEIE Habilitacion de las interrupciones de los perif ricos, a trav s de los registros PIR1 y PIR2. e e 0: Deshabilita. 1: Habilita. T0IE Habilitacion de la interrupcion debida al temporizador TMR0. 0: Deshabilita. 1: Habilita. INTE Habilitacion de la interrupcion debida a la patilla RB0/INT. 0: Deshabilita. 1: Habilita. RBIE Habilitacion de la interrupcion debida al cambio en la entrada en las patillas RB4, RB5, RB6, RB7. 0: Deshabilita. 1: Habilita. T0IF Notica el desbordamiento del temporizador TMR0. 0: No paso nada. 1: Se desbordo TMR0. Hay que borrarlo por software.

INTF Notica que ocurrio el anco seleccionado en la patilla RB0/INT. 0: No paso nada. 1: Detectado anco programado en RB0/INT. Hay que borrarlo por software. RBIF Detectado un cambio en la entrada en las patillas RB4, RB5, RB6, RB7. 0: No paso nada. 1: Cambio detectado. Hay que borrarlo por software. Para que sea efectivo antes hay que leer el puerto B.
PIE1. Presente en el banco 1. Registro de interrupciones de los perif ricos. e

PIE1
Bit 7 6 5 4 3 2 1 Bit 0

PSPIE

ADIE

RCIE

TXIE

SSPIE

CCP1IE

TMR2IE

TMR1IE

PSPIE Habilitacion de la interrupcion por lectura o escritura en el puerto paralelo esclavo (modulo PSP). 0: Deshabilita. 1: Habilita. ADIE Habilitacion de las interrupcion del conversor AD. 0: Deshabilita. 1: Habilita. RCIE Habilitacion de la interrupcion debida a la recepcion del modulo USART. 0: Deshabilita. 1: Habilita. TXIE Habilitacion de la interrupcion debida a la transmision del modulo USART. 0: Deshabilita. 1: Habilita. SSPIE Habilitacion de la interrupcion debida al modulo MSSP. 0: Deshabilita. 1: Habilita. CCP1IE Habilitacion de la interrupcion debida al modulo CCP1. 0: Deshabilita. 1: Habilita. TMR2IE Habilitacion de la interrupcion debida al alcance del periodo (PR2) por el temporizador TMR2. 0: Deshabilita. 1: Habilita. TMR1IE Habilitacion de la interrupcion debida al desbordamiento del temporizador TMR1. 0: Deshabilita. 1: Habilita.

PIR1. Presente en el banco 0. Registro de noticacion de las interrupciones de los perif ricos. Son bits pegajosos: deben ponerse de nuevo a cero por software. e

PIR1
Bit 7 6 5 4 3 2 1 Bit 0

PSPIF

ADIF

RCIF

TXIF

SSPIF

CCP1IF

TMR2IF

TMR1IF

PSPIF Noticacion de lectura o escritura en el puerto paralelo esclavo (modulo PSP). 0: No paso nada. 1: Se escribio o se leyo del modulo PSP. ADIF Noticacion de la nalizacion de una conversion del modulo AD. 0: No paso nada. 1: Conversion completada. RCIF Noticacion de la recepcion de un dato por el modulo USART. 0: No paso nada. 1: El bufer de recepcion est lleno en el modulo USART. a TXIF Noticacion de una transmision realizada en el modulo USART. 0: No paso nada. 1: El bufer de transmision est vaco. a SSPIF Noticacion de evento ocurrido en el modulo MSSP. 0: No paso nada. 1: Ocurrio algo: SPI Transmision o recepcion nalizada. I2C Esclavo Transmision o recepcion nalizada. I2C Maestro Transmision o recepcion nalizada. I2C Maestro Condicion start realizada. I2C Maestro Condicion stop realizada. I2C Maestro Condicion restart realizada. I2C Maestro Secuencia ACK realizada. I2C Maestro Ocurrio una condicion start cuando el modulo estaba ocioso (arbitraje de bus multimaestro). I2C Maestro Ocurrio una condicion stop cuando el modulo estaba ocioso (arbitraje de bus multimaestro). CCP1IF Noticacion de suceso del modulo CCP1. 0: No ocurrio nada. 1: Ocurrio una captura o una comparacion en el modulo CCP1. TMR2IF Noticacion de que TMR2 alcanzo PR2. 0: No paso nada. 1: Fin de cuenta. TMR1IF Noticacion del desbordamiento de TMR1. 0: No paso nada. 1: Desbordamiento de TMR1.
PIE2. Presente en el banco 1. Registro de interrupciones de los perif ricos. e

PIE2
Bit 7 6 5 4 3 2 1 Bit 0

EEIE

BCLIE

CCP2IE

EEIE Habilita la interrupcion debida a la nalizacion de la escritura en la memoria EEPROM (de datos o de programa). 0: Interrupcion no permitida. 1: Interrupcion permitida. BCLIE Habilita la interrupcion debida a una colision en el bus I2C (modo maestro). 0: Interrupcion no permitida. 1: Interrupcion permitida. CCP2IE Habilita la interrupcion debida al modulo CCP2. 0: Interrupcion no permitida. 1: Interrupcion permitida.

PIR2. Presente en el banco 0. Registro de noticacion de las interrupciones de los perif ricos. e PIR2
Bit 7 6 5 4 3 2 1 Bit 0

EEIF

BCLIF

CCP2IF

EEIF Noticacion de que la escritura en la memoria EEPROM (de datos o de programa) ha nalizado. 0: Operacion incompleta. En curso. 1: Operacion nalizada. BCLIF Colision en el bus I2C (modo maestro). 0: Todo bien. 1: Ocurrio una colision en el bus I2C. CCP2IF El modulo CCP2 completo la operacion (modos captura o comparacion). 0: Operacion en curso o no iniciada. 1: Operacion nalizada.
PCON. Presente en el banco 1. Registro de estado del arranque del microcontrola-

dor. PCON
Bit 7 6 5 4 3 2 1 Bit 0

/POR

/BOR

/POR Estado del reset de arranque. 0: Ocurrio un arranque del sistema (POR: Power-on reset). Se debe poner a uno por software para detectarlo. 1: No ocurrio nada. /BOR Senaliza un rearranque del micro por cada de la tension de alimentacion (BOR: Brown-Out Reset). 0: Ocurrio el reset. 1: No ocurrio.

1.5.4. Contador de programa


El contador de programa PC es de 13 bits y no es accesible directamente. Est coma puesto de:
Registro PCL: parte baja de PC.
Registro PCH: parte alta de PC. No es accesible directamente, si no que se puede modicar a trav s del registro PCLATH que se copia en PCH al escribir en PCL e o cuando se ejecuta una instruccion GOTO o CALL. Esquema
PCH 12 PC 5 PCLATH<4:0> 8 8 7 PCL 0 Instruction with PCL as Destination ALU

PCLATH PCH 12 PC 2 PCLATH<4:3> 11 Opcode <10:0> PCLATH 11 10 8 7 PCL 0 GOTO,CALL

Ejemplo
1
2
3
4
5
6
7
8
9
10
11
12
13
14

ORG BCF BSF CALL

0x500 PCLATH,4 PCLATH,3 SUB1_P1

; Selecciona la pagina 1 de FLASH (800h-FFFh) ; Llama a la subrutina


; pagina 1 (800h-FFFh)
; pagina 1 (800h-FFFh)
; subrutina llamada ; pagina 1 (800h-FFFh)
; retorno de la subrutina ; hacia la pagina 0 (000h-7FFh)

: : ORG 0x900 SUB1_P1 : : : RETURN

1.5.5. Direccionamiento directo/ indirecto


El registro FSR contiene la direccion a la que se accede a trav s del registro INDF. e Esto es INDF=[FSR].

Esquema El funcionamiento es diferente cuando el direccionamiento es directo de cuando el direccionamiento es indirecto:


Direct Addressing RP1:RP0 6 from opcode 0 IRP Indirect Addressing 7 FSR register 0

bank select

location select 00 00h 01 80h 10 100h 11 180h

bank select

location select

Data Memory(1)

7Fh Bank 0

FFh Bank 1

17Fh Bank 2

1FFh Bank 3

Ejemplo El ejemplo muestra como poner a cero un bloque de datos en RAM desde la posi cion 32 hasta la 40:
1
2
3
4
5
6
7
8
9

NEXT

movlw movwf clrf incf movlw subwf btfss goto

32 FSR INDF FSR,F 40 FSR,W FSR,Z NEXT

; ; inicializa el puntero FSR = 32 ; [FSR] = INDF = 0 ; incrementa FSR


; W = FSR-40 ; fin? ; si no continua borrando ;

FIN

Vous aimerez peut-être aussi