INTRODUCTION Microchip is the Embedded Control Solutions Company. The company’s focus is on products that meet the needs of the embedded control market.

Slides:



Advertisements
Similar presentations
م/محمد علي عطية حسين. Pin Diagram DescriptionPin Name Oscillator crystal input/external clock source input. OSC1/CLKIN Oscillator crystal output.OSC2/CLKOUT.
Advertisements

Chapter 2 HARDWARE SUMMARY
8051 Core Specification.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Introduction of Holtek HT-46 series MCU
Eng. Husam Alzaq The Islamic Uni. Of Gaza
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2013 Lecture 26: PIC microcontroller intro.
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 30: PIC data memory.
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 29: Microcontroller intro.
Microcontroller Architecture— PIC18F Family
Microcontroller Architecture PIC18F Family
Programming 8-bit PIC Microcontrollers in C Martin Bates Elsevier 2008.
The domestic refrigerator-An example A car door mechanism.
Micro controllers A self-contained system in which a processor, support, memory, and input/output (I/O) are all contained in a single package.
Special Function Register
16F877A. Timer 0 The Timer0 module timer/counter has the following features: –8-bit timer/counter –Readable and writable –8-bit software programmable.
Directives, Memory, and Stack. Directives Special commands to the assembler May or may not generate machine code Categories by their function Programming.
PIC16F877 ISR Points to note Interrupt Triggers –Individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, PEIE.
Prepared by Eng. Musa Alyaman1 Chapter Seven Chapter Seven PIC16F87x.
Embedded System Spring, 2011 Lecture 4: The PIC Microcontrollers Eng. Wazen M. Shbair.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This course provides an overview of the CPU architecture.
PIC18F Programming Model and Instruction Set
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This training course provides an overview of the CPU architecture.
MICROCONTROLLER SYSTEMS Part 1. Figure 1.1Elements of a digital controller CPU Central Processing Unit Input Peripherals Output Peripherals ROM Read Only.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
Chapter 2 Introducing the PIC Mid-Range Family and the 16F84A The aims of this chapter are to introduce: The PIC mid-range family, in overview The overall.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Chapter 7 Larger Systems and the PIC 16F873A The aims of this chapter are to introduce: The architecture of the 16F873A microcontroller; The 16F873A memory.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
EEE237 Introduction to Microprocessors Week x. SFRs.
Teachers Name : Suman Sarker Telecommunication Technology Subject Name : Microcontroller & Embedded System Subject Code : 6871 Semester : 7th Department.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
INTRODUCTION TO PIC MICROCONTROLLER. Overview and Features The term PIC stands for Peripheral Interface Controller. Microchip Technology, USA. Basically.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Features of the PIC18 microcontroller - 8-bit CPU - 2 MB program memory space (internal 32KB to 128KB) bytes to 1KB of data EEPROM - Up to 4096 bytes.
Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit.
Working with Time: Interrupts, Counters and Timers
Microcontrollers session. What is Microcontroller? Microcontroller is composed of microprocessor,ram, flash memory,EEPROM and some modules like timers,
PIC12F629/675. “Wide variety” 8-84 pin RISC core, 12/14/16bit program word USART/AUSART, I 2 C, ADC, ICSP, ICD OTP/UV EPROM/FLASH/ROM Families: PIC12,
Interrupts ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
Aum Amriteswaryai Namah:. SUB ROUTINES Instead of repeating same program segments at all locations, they are written and stored separately; Each such.
AVR Architecture Prepared By: Avdhesh Soni ( ) Sarthak Patel ( ) Akshay Parekh ( ) Fenil Sachla ( ) Guided.
INTRODUCTION TO PIC MICROCONTROLLERS INTRODUCTION TO PIC MICROCONTROLLERS Dr.Y.Narasimha Murthy Ph.D SRI SAIBABA NATIONAL COLLEGE(AUTONOMOUS)
Lecture – 8 Interrupt 1. Outline Introduction Handling interrupt Interrupt sources Switching interrupt Peripheral interrupts Using two interrupts Conclusions.
I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add.
Special Features. Device Configuration bits Revision Device Configuration bits Revision On-chip Power-on Reset (POR) Revision On-chip Power-on Reset (POR)
Dr. Iyad Jafar Introducing the PIC 16 Series and the 16F84A.
TIMERS.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Memory Organization 1.  3 types of memory are used in PIC18 microcontroller devices: Program Memory - Flash Memory Data RAM - Static RAM Data EEPROM.
An Introduction to Embedded Systems, and the PIC Microcontroller Lecture 8: Interrupts The aims of this session are to explore the structure and application.
Embedded Hardware.
Microprocessor Systems Design I
UNIT – Microcontroller.
Microprocessor Systems Design I
Micro-Controller: PIC16C74 < Architecture >
Microprocessor Systems Design I
PIC 16F877.
Microprocessor Systems Design I
مقدمه با توجه به اهميت و گسترش روزافزون كاربردهاي ميكروكنترلرها و محدوديت هايي كه ميكروكنترلرهاي خانواده ي MCS51 ايجاد مي كرد،شركت Microchipنسل جديدي.
Introduction to Microprocessors and Microcontrollers
Chapter 4 Instruction Set.
INSTRUCTION SET.
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
PIC18 Interrupt Programming
Computer Operation 6/22/2019.
PIC18 Interrupt Programming
Presentation transcript:

INTRODUCTION Microchip is the Embedded Control Solutions Company. The company’s focus is on products that meet the needs of the embedded control market. 8-bit General Purpose Microcontrollers (PICmicro™ MCUs)

PICmicro devices are grouped by the size of their Instruction Word. The three current PICmicro families are: 12-bit 1. Base-Line: 12-bit Instruction Word length 14-bit 2. Mid-Range: 14-bit Instruction Word length 16-bit 3. High-End: 16-bit Instruction Word length

Device Structure C O R E Perepherials Special Features

1.Device Oscillator Revision 2.Reset logic Revision 3. CPU (Central Processing Unit) operation Revision 4. ALU (Arithmetic Logical Unit) operation Revision 5. Device memory map organization Revision 6. Interrupt operation Revision 7. Instruction set COR E

1. General purpose I/O Revision 2. Timer0 Revision 3. Timer1 Revision 4. Timer2 Revision 5. Capture, Compare, and PWM (CCP) Revision 6. Synchronous Serial Port (SSP) Revision Perepherials

7. USART Revision 8. Voltage References Revision 9. Comparators Revision bit Analog to Digital (A/D) Revision 11. Liquid Crystal Display (LCD) Drivers Revision 12. Parallel Slave Port (PSP) Perepherials

1.Device Configuration bits Revision 2.On-chip Power-on Reset (POR) Revision 3. Brown-out Reset (BOR) logic Revision 4. Watchdog Timer Revision 5. Low power mode (Sleep) Revision 6. Internal RC device oscillator Special Features

Development Support 1.Code generation MPASM MPASM MPLAB-C MPLAB-C MP-DriveWay™ MP-DriveWay™ Hi-Tech Pic C compilerHi-Tech Pic C compiler 2. Software debug PICMASTER® In-Circuit Emulator PICMASTER® In-Circuit Emulator ICEPIC In-Circuit Emulator ICEPIC In-Circuit Emulator MPLAB-SIM Software Simulator MPLAB-SIM Software Simulator MPLAB ICD 2MPLAB ICD 2 3. Product evaluation boards EduPicEduPic

ARCHITECTURE The high performance of the PICmicro MCU family can be attributed to the following architectural features: Harvard architecture Harvard architecture Register file concept Register file concept All instructions single- word All instructions single- word LWI (Long Word Instruction) LWI (Long Word Instruction) Instruction pipelining Instruction pipelining Single-cycle instructions Single-cycle instructions Reduced instruction set Reduced instruction set Orthogonal instruction set Orthogonal instruction set

Harvard architecture Two separate memory Spaces for instructions and data. Increases throughputIncreases throughput Different program and data bus widths are possibleDifferent program and data bus widths are possible Fetches instructions and data from one memory. Limits Operating BandwidthLimits Operating Bandwidth

Instruction pipelining Allows overlap of fetch and execution.Allows overlap of fetch and execution. Makes single cycle execution.Makes single cycle execution. Program branches (e.g. GOTO, CALL or Write toProgram branches (e.g. GOTO, CALL or Write to PC) takes two cycles.PC) takes two cycles.

Block Diagram

Instruction Clock The clock input (from OSC1) is internally divided by four to generate four non-overlapping quadrature clocks, namely Q1, Q2, Q3, and Q4.

Instruction Fetch The four Q cycles that make up an instruction cycle (TCY) can be generalized as: Q1: Instruction Decode Cycle or forced No operation Q2: Instruction Read Data Cycle or No operation Q3: Process the Data Q4: Instruction Write Data Cycle or No operation

General Instruction Format Opcode d f (FILE#) Byte oriented file register operations Opcode f (FILE#) bit# Bit-oriented file register operations Opcode k(literal) Literal and control operations Opcode k(literal) CALL and GOTO instructions only The Mid-Range MCU instructions can be broken formats down into four general formats 3

FlashProgramMemory ProgramCounter 13 1 Level Stack 2 Level Stack 8 Level Stack InstructionRegister 14 InstructionDecod&Cont 8 To Data Mux Literal 7 To Addr Mux Byte & Bit Tcy Q1Q2Q3Q4

Data Process MUX InstructionRegister WRegister StatusRegister RAM FileRegisters 368 x

Memory DATA Memory 4 Banks4 Banks General Purpose RAM Special Function Registers (SFR) Program Memory 4 Pages4 Pages

Program Memory 13-bit program counter 13-bit program counter capable of addressing an 8K x 14 program memory space. This program memory space is divided into four pages of 2K words each Page H-07FFH Page H-0FFFH Page H-17FFH Page H-1FFFH

To jump between the program memory pages, the high bits of the Program Counter (PC) must be modified. This is done by writing the desired value into a SFR called PCLATH (ProgramCounter Latch High) ProgramCounter PCL PCH PCLatch

(14 bits) PCH PCL 8 Level STACK

GOTO Instruction PC PCLatch FromOpcode goto

CALL Instruction PC PCLatch Top os stack 13 FromIR 11 call

PC Relative Addressing (14-bit core) First write high byte to PCLATH.First write high byte to PCLATH. Next write low byte to PCL, this loads theNext write low byte to PCL, this loads the entire 13-bit value to PC. movlw HIGH Delay movwf PCLATH movlw LOW Delay movwf PCL movlw movwf

movf addwf retlw

Stack The stack space is not part of either program or data space and the stack pointer is not readable or writable. PUSH Operation Call instructionCall instruction Interrupt causes a branchInterrupt causes a branch POP Operation RETURN, RETLW or a RETFIE instruction execution. After the stack has been PUSHed eight times, the ninth push overwrites the value that was stored from the first push. The tenth push overwrites the second push (and so on).

Example: Call of a Subroutine in Page1 from Page0 ORG 0x500 BSF PCLATH,8 BSF PCLATH,8 ; Select Page1 (800h-FFFh) CALL SUB1_P1 CALL SUB1_P1 ;Call subroutine in Page1 (800h-FFFh) : ; ORG 0x900 SUB1_P1: SUB1_P1: ; called subroutine Page1 (800h-FFFh) : ; RETURN RETURN ;return to Call subroutine in Page0 (000h-7FFh) ORG BSF pclatch

Data Memory Special Function Registers (SFR) Control the operation of the deviceControl the operation of the device General Purpose Registers (GPR) GPRs are the general area for data storageGPRs are the general area for data storage and scratch pad operations. GPRs are not initialized by a Power-on ResetGPRs are not initialized by a Power-on Reset and are unchanged on all other resets

status

Direct Addressing 7-bit direct address from the instruction 2-bits from STATUS register PR1:PR0 Byte&bit instruction Byte&bit instruction

Indirect Addressing 8-bit indirect address from the 8-bit indirect address from the FSR (File Select Register). FSR (File Select Register). 1-bit from STATUS register. 1-bit from STATUS register.

Example:Indirect Addressing Clear all RAM locations from 0x20 to 0x7F.Clear all RAM locations from 0x20 to 0x7F. Indirect address is loaded into FSR.Indirect address is loaded into FSR. Every time INDF is used as operand, registerEvery time INDF is used as operand, register pointed to by FSR is actually used. bcf STATUS,IRP bcf STATUS,IRP movlw 0x20 movlw 0x20 movwf FSR movwf FSR LOOP clrf INDF incf FSR,F incf FSR,F btfss FSR,7 btfss FSR,7 goto LOOP goto LOOP bcf clrf incf btfss

STATUS REGISTER Arithmetic status of the ALUArithmetic status of the ALU RESET statusRESET status Bank select bits for data memoryBank select bits for data memory Since the selection of the Data Memory banks is controlled by this register, it is required to be present in every bank. Also, this register is in the same relative position (offset) in each bank. RAM memory RAM memory

STATUS REGISTER IRPRP1 R\W IRP: Register Bank Select bit (used for indirect addressing) bit 7 IRP: Register Bank Select bit (used for indirect addressing) 1 = Bank 2, 3 (100h - 1FFh) 0 = Bank 0, 1 (00h - FFh) RP1 R\WR\W bit 6:5 RP1:RP0: Register Bank Select bits (used for direct addressing) 11 = Bank 3 (180h - 1FFh) 10 = Bank 2 (100h - 17Fh) 01 = Bank 1 (80h - FFh) 00 = Bank 0 (00h - 7Fh)

TOPD R bit 4 TO: Time-out bit 1 = After power-up, CLRWDT instruction, or SLEEP instruction 0 = A WDT time-out occurred bit 3 PD: Power-down bit 1 = After power-up or by the CLRWDT instruction 0 = By execution of the SLEEP instruction R

ZDCC R/W bit2 bit2 Z: Zero bit 1 = The result of an arithmetic or logic operation is zero 0 = The result of an arithmetic or logic operation is not zero bit 1 DC: Digit carry/borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions) (for borrow the polarity is reversed) 1 = A carry-out from the 4th low order bit of the result occurred 0 = No carry-out from the 4th low order bit of the result R/WR/W bit 0 C: Carry/borrow bit (ADDWF,ADDLW,SUBLW,SUBWF instructions) 1 = A carry-out from the most significant bit of the result occurred 0 = No carry-out from the most significant bit of the result occurred

INTERRUPTS The PIC16F87XA family has up to 15 sources of interrupt. These sources generally include one interrupt source for each peripheral module, though some modules may generate multiple interrupts (such as the USART module)

INTCONRegister INTCONRegisterPIE/PIFRegisters

GIE bit is cleared to disable any further interruptGIE bit is cleared to disable any further interrupt The return address is pushed into the stackThe return address is pushed into the stack The PC is loaded with 0004h.The PC is loaded with 0004h. In the interrupt service routine the source(s)In the interrupt service routine the source(s) of the interrupt can be determined by polling the interrupt flag bits. When an interrupt is responded to, next operation will executed:

Note 1: Individual interrupt flag bits are set regardless of the status of their corresponding mask bit or the GIE bit. Note 2: When an instruction that clears the GIE bit is executed, any interrupts that were pending for execution in the next cycle are ignored. The CPU will execute a NOP in the cycle immediately following the instruction which clears the GIE bit.The interrupts which were ignored are still pending to be serviced when the GIE bit is set again.

INTCON Register GIEPEIE R/W R/W bit 7 GIE: Global Interrupt Enable bit 1 = Enables all un-masked interrupts 0 = Disables all interrupts bit 6 PEIE: Peripheral Interrupt Enable bit 1 = Enables all un-masked peripheral interrupts 0 = Disables all peripheral interrupts ADDRESS (0Bh, 8Bh, 10Bh, 18Bh)

TOIETOIF bit 5 T0IE: TMR0 Overflow Interrupt Enable bit 1 = Enables the TMR0 overflow interrupt 0 = Disables the TMR0 overflow interrupt bit 2 T0IF: TMR0 Overflow Interrupt Flag bit 1 = TMR0 register has overflowed (must be cleared in software) 0 = TMR0 register did not overflow R/WR/W

bit 4 bit 4 INTE: INT External Interrupt Enable bit 1 = Enables the INT external interrupt 0 = Disables the INT external interrupt bit 1 bit 1 INTF: INT External Interrupt Flag bit 1 = The INT external interrupt occurred (must be cleared in software) 0 = The INT external interrupt did not occur INTEINTF R/W

bit 3 RBIE (1): RB Port Change Interrupt Enable bit 1 = Enables the RB port change interrupt 0 = Disables the RB port change interrupt bit 0 RBIF (1): RB Port Change Interrupt Flag bit 1 = At least one of the RB7:RB4 pins changed state (must be cleared in software) 0 = None of the RB7:RB4 pins have changed state RBIERBIF R/W

PSPIE PIE1 Register PSPIE: Parallel Slave Port Read/Write Interrupt Enable bit(1) bit 7 PSPIE: Parallel Slave Port Read/Write Interrupt Enable bit(1) 1 = Enables the PSP read/write interrupt 0 = Disables the PSP read/write interrupt PSPIF: Parallel Slave Port Read/Write bit 7 PSPIF: Parallel Slave Port Read/Write Interrupt Flag bit 1 = A read or a write operation has taken place (must be cleared in software) 0 = No read or write has occurred PIR1 Register PSPIF

bit 6 ADIF: A/D Converter Interrupt Flag bit 1 = An A/D conversion completed 0 = The A/D conversion is not complete ADIE PIE1 Register ADIF PIR1 Register bit 6 bit 6 ADIE: A/D Converter Interrupt Enable bit 1 = Enables the A/D converter interrupt 0 = Disables the A/D converter interrupt

bit 5 RCIF: USART Receive Interrupt Flag bit 1 = The USART receive buffer is full 0 = The USART receive buffer is empty RCIE PIE1 Register RCIF PIR1 Register bit 5 RCIE: USART Receive Interrupt Enable bit 1 = Enables the USART receive interrupt 0 = Disables the USART receive interrupt

bit 4 TXIF: USART Transmit Interrupt Flag bit 1 = The USART transmit buffer is empty 0 = The USART transmit buffer is full TXIE PIE1 Register TXIF PIR1 Register bit 4 TXIE: USART Transmit Interrupt Enable bit 1 = Enables the USART transmit interrupt 0 = Disables the USART transmit interrupt

CCP1IE PIE1 Register bit 2 CCP1IE: CCP1 Interrupt Enable bit 1 = Enables the CCP1 interrupt 0 = Disables the CCP1 interrupt SSPIE bit 3 SSPIE: Synchronous Serial Port Interrupt Enable bit 1 = Enables the SSP interrupt 0 = Disables the SSP interrupt

CCP1IF PIR1 Register bit 2 CCP1IF: CCP1 Interrupt Flag bit Capture mode: 1 = A TMR1 register capture occurred (must be cleared in software) 0 = No TMR1 register capture occurred Compare mode: 1 = A TMR1 register compare match occurred (must be cleared in software) 0 = No TMR1 register compare match occurred PWM mode: Unused in this mode.

SSPIF PIR1 Register bit 3 SSPIF: Synchronous Serial Port (SSP) Interrupt Flag bit 1 = The SSP interrupt condition has occurred and must be cleared in software before returning must be cleared in software before returning from the Interrupt Service Routine. from the Interrupt Service Routine.

The conditions that will set this bit are: SPI – A transmission/reception has taken place. SPI – A transmission/reception has taken place. I2C Slave – A transmission/reception has taken place. I2C Slave – A transmission/reception has taken place. I2C Master I2C Master - A transmission/reception has taken place. - The initiated Start condition was completed by the SSP module. - The initiated Stop condition was completed by the SSP module. - The initiated Restart condition was completed by the SSP module. - The initiated Acknowledge condition was completed by the SSP module. - A Start condition occurred while the SSP module was Idle (multi-master system). - A Stop condition occurred while the SSP module was Idle (multi-master system).

PIE1 Register TMR2IF PIR1 Register bit 1 TMR2IE: TMR2 to PR2 Match Interrupt Enable bit 1 = Enables the TMR2 to PR2 match interrupt 0 = Disables the TMR2 to PR2 match interrupt bit 1 TMR2IF: TMR2 to PR2 Match Interrupt Flag bit 1 = TMR2 to PR2 match occurred (must be cleared in software) 0 = No TMR2 to PR2 match occurred TMR2IE

PIE1 Register TMR1IF PIR1 Register bit 0 TMR1IE: TMR1 Overflow Interrupt Enable bit 1 = Enables the TMR1 overflow interrupt 0 = Disables the TMR1 overflow interrupt bit 0 TMR1IF: TMR1 Overflow Interrupt Flag bit 1 = TMR1 register overflowed (must be cleared in software) 0 = TMR1 register did not overflow TMR1IE

PIE2 Register PIR2 Register bit 6 CMIE: Comparator Interrupt Enable bit 1 = Enables the comparator interrupt 0 = Disable the comparator interrupt CMIE CMIF CMIF: Comparator Interrupt Flag bit bit 6 CMIF: Comparator Interrupt Flag bit 1 = The comparator input has changed (must be cleared in software) 0 = The comparator input has not changed

PIE2 Register PIR2 Register EEIE bit 4 bit 4 EEIF: EEPROM Write Operation Interrupt Flag bit 1 = The write operation completed (must be cleared in software) 0 = The write operation is not complete or has not been started bit 4 EEIE:EEPROM Write Operation Interrupt Enable bit 1 = Enable EEPROM write interrupt 0 = Disable EEPROM write interrupt EEIF

PIE2 Register PIR2 Register BCLIE BCLIE: Bus Collision Interrupt Enable bit bit 3 BCLIE: Bus Collision Interrupt Enable bit 1 = Enable bus collision interrupt 0 = Disable bus collision interrupt BCLIF bit 3 BCLIF: Bus Collision Interrupt Flag bit 1 = A bus collision has occurred in the SSP when configured for I2C Master mode 0 = No bus collision has occurred

PIE2 Register CCP2IE CCP2IE: CCP2 Interrupt Enable bit bit 0 CCP2IE: CCP2 Interrupt Enable bit 1 = Enables the CCP2 interrupt 0 = Disables the CCP2 interrupt

PIR2 Register CCP2IF bit 0 CCP2IF: CCP2 Interrupt Flag bit Capture mode: 1 = A TMR1 register capture occurred (must be cleared in software) 0 = No TMR1 register capture occurred Compare mode: 1 = A TMR1 register compare match occurred (must be cleared in software) 0 = No TMR1 register compare match occurred PWM mode: Unused.

Context Saving During Interrupts 1. Stores the W register regardless of current bank. 2. Stores the STATUS register in Bank0. 3. Executes the Interrupt Service Routine (ISR) code. 4. Restores the STATUS (and bank select bit register). 5. Restores the W register. If additional locations need to be saved before executing the Interrupt Service Routine (ISR) code, they should be saved after the STATUS register is saved (step 2), and restored before the STATUS register is restored (step 4).

Saving the STATUS and W Registers in RAM MOVWF W_TEMP ; Copy W to a Temporary Register regardless of ;current bank SWAPF STATUS,W SWAPF STATUS,W ; Swap STATUS nibbles and place into W register MOVWF STATUS_TEMP MOVWF STATUS_TEMP ; Save STATUS to a Temporary register ; in Bank0 : : (Interrupt Service Routine (ISR) ) : SWAPF STATUS_TEMP,W SWAPF STATUS_TEMP,W ; Swap original STATUS register value ; into W (restores original bank) MOVWF STATUS MOVWF STATUS ; Restore STATUS register fromW register SWAPF W_TEMP,F SWAPF W_TEMP,F ; Swap W_Temp nibbles and return ; value to W_Temp SWAPF W_TEMP,W ; Swap W_Temp to W to restore original ; W value without affecting STATUS SWAPF

Initialization and Enabling of Interrupts ; This is the Interrupt Enable PIE1_MASK1 EQU B‘ ’ ; This is the Interrupt Enable ; Register mask value : : : ; Bank0 CLRF STATUS ; Bank0 CLRF INTCON ; Disable interrupts and clear some flags CLRF PIR1 ; Clear all flag bits BSF STATUS, RP0 ; Bank1 MOVLW PIE1_MASK1 ; This is the initial masking for PIE1 MOVWF PIE1 BCF STATUS, RP0 BCF STATUS, RP0 ; Bank0 BSF INTCON, GIE BSF INTCON, GIE ; Enable Interrupts EQU REGISTERS