SlideShare a Scribd company logo
2
Most read
5
Most read
12
Most read
Interrupts for PIC18
DEPARTMENT OF ELECTRICAL ENGINEERING
IIT JODHPUR
PRESENTED BY
•DEEPAK KUMAR KALAWANIA
PIC18 INTERRUPTS
INTRODUCTION:-
Interrupts are mechanisms which enable instant
response to events such as counter overflow, pin
change, data received, etc.
• In normal mode, microcontroller executes the
main program as long as there are no occurrences
that would cause an interrupt.
• Upon interrupt, microcontroller stops the
execution of main program and commences the
special part of the program(ISR) which will
analyze and handle the interrupt.
PIC can serve multiple devices
using mechanisms of
– Polling
• PIC continuously monitors the status of each device
• Each device get the attention of the CPU as the
same level of priority
• Wastes u-Controllers time by polling devices that
do not need service.
– Interrupt
• Devices get the attention of the CPU only when it
needs a service
• Can service many devices with different level of
priorities
Interrupt service routine (ISR)
• When an interrupt is
invoked the uC runs the
Interrupt Service
Routine(ISR)
• Interrupt vector table
holds the address of ISRs
– Power-on Reset 0000h
– High priority interrupt
0008h
– Low priority interrupt
0018h
Steps in executing an interrupt
• Upon activation of interrupt the microcontroller
– Finishes executing the current instruction
– Pushes the PC of next instruction in the stack
– Jumps to the interrupt vector table to get the
address of ISR and jumps to it
– Begin executing the ISR instructions to the last
instruction of ISR (RETFIE)
– Executes RETFIE
• Pops the PC from the stack
• Starts to execute from the address of that PC
Program organization in MPLAB
Sources of interrupts in PIC18
• External hardware interrupts
– Pins RB0(INT0),RB1(INT1),RB2(INT2)
• Timers
– Timer0 , Timer1 ,Timer2
Enabling and disabling an interrupt
• When the PIC is powered on (or resets)
– All interrupts are masked (disabled)
– The default ISR address is 0008h
• No interrupt priorities for interrupts
Enabling and disabling an interrupt
In general, interrupt sources have three bits to control
their operation. They are:
• Flag bit
– to indicate that an interrupt event occurred
• Enable bit
– that allows program execution to branch to the
interrupt vector address when the flag bit is set
• Priority bit
– to select high priority or low priority
Steps in enabling an interrupt
• Set the GIE bit from
INTCON REG
• Set the IE bit for that
interrupt
• If the interrupt is one of
the peripheral (timers
1,2 , serial,etc ) set PEIE
bit(6) from INTCON
reg
Example
a)
BSF INTCON,TMR0IE
BSF INTCON,INT0IE
BSF INTCON,GIE
Or
MOVLW B’10110000’
MOVWF INTCON
b)
BCF INTCON,TMR0IE
c) BCF INTCON,GIE
Program - External hardware
interrupt
ORG 0000H
GOTO MAIN
ORG 0008H
BTFSS INTCON,INT0IF
RETFIE
GOTO INT0_ISR
ORG 00100H
MAIN
BCF TRISB,7
BSF TRISB,INT0
CLRF TRISD
SETF TRISC
BSF INTCON,INT0IE
BSF INTCON,GIE
OVER MOVFF PORTC,PORTD
BRA OVER
INT0_ISR
ORG 200H
BTG PORTB,7
BCF INTCON,INT0IF
RETFIE
END
Program - Edge-triggered
interrupts
ORG 0000H
GOTO MAIN
ORG 0008H
BTFSS INTCON,INT0IF
RETFIE
GOTO INT1_ISR
ORG 00100H
MAIN
BCF TRISB,7
BSF TRISB,INT1
BSF INTCON3,INT1IE
BCF INTCON2,INTEDGE1
BSF INTCON,GIE
OVER BRA OVER
BRA OVER
INT1_ISR
ORG 200H
BTG PORTB,7
BCF INTCON3,INT1IF
RETFIE
END
Sampling the Edge triggered
interrupt
• The external source
must be held high for at
least two instruction
cycles
• For XTAL 10Mhz
• Instruction cycle time is
400ns,0.4us
• So minimum pulse
duration to detect edge
triggered interrupts =
2 instruction cycle
=0.8us
At what address does the
CPU wake up when power
applied?
• The uC wakes up at memory
address 0000
• The PC has the value 0000
• ORG directive put the
address of the first op code at
the memory location 0000
Powering UP
INTCON
global
interupt
enable
• INT pin interrupt
• TMR0 overflow interrupt
• GP port
change
interrupt
• GP port
change
interrupt
• INT pin interrupt
• TMR0 overflow interrupt
FLAGSENABLES
Timer Interrupts
Interrupt Flag Bit Register Enable Bit Register
Timer0 TMR0IF INTCON TMR0IE INTCON
Timer1 TMR1IF PIR1 TMR1IE PIE1
Timer2 TMR2IF PIR1 TMR3IE PIE1
Timer3 TMR3IF PIR3 TMR3IE PIE2
Timer Interrupt Flag Bits and Associated Registers
INTCON Register with Timer0 Interrupt Enable and Interrupt Flag
Timer Interrupts
Program -
ORG 0000H
GOTO MAIN
ORG 0008H
BTFSS INTCON,TMR0IF
RETFIE
GOTO T0_ISR
ORG 00100H
MAIN BCF TRISB,5
CLRF TRISD
SETF TRISC
MOVLW 0x08
MOVWF T0CON
MOVLW 0xFF
MOVWF TMR0H
MOVLW 0xF2
MOVWF TMR0L
BCF INTCON,TMR0IF
BSF T0CON,TMR0ON
BSF INTCON,TMR0IE
BSF INTCON,GIE
OVER MOVFF PORTC,PORTD
BRA OVER
Timer0 Interrupt
T0_ISR
ORG 200H
MOVLW 0xFF
MOVWF TMR0H MOVLW 0xF2
MOVWF TMR0L
BTG PORTB,5
BCF INTCON,TMR0IF
RETFIE
END
Revisit
Serial Communication Interrupts
Interrupt Flag Bit Register Enable Bit Register
TXIF
(Transmit)
TXIF PIR1 TXIE PIE1
RCIF
(Receive)
RCIF PIR1 RCIE PIE1
Serial Port Interrupt Flag Bits and Associated Registers
PIE1 Register Bits Holding TXIE and RCIE
Program
ORG 0000H
GOTO MAIN
ORG 0008H
BTFSC PIR1,TXIF
BRA TX_ISR
RETFIE
ORG 0040H
TX_ISR
MOVWFF PORTD,TXREG
RETFIE
ORG 00100H
MAIN SETF TRISD
MOVLW 0x20
MOVWF TXSTA
MOVLW D'15'
MOVWF SPBRG
BCF TRISC, TX
BSF RCSTA, SPEN
BSF PIE1 ,TXIE
BSF INTCON,PEIE
BSF INTCON,GIE
OVER BRA OVER
END
Serial Port Interrupt
Enable peripheral Interrupt
11-22
8 bit switch is connected to port.D. the PIC18 reads data from PORTD and
writes it to TXREG.
Interrupts for PIC18

More Related Content

PPTX
Interrupts of 8085
PPT
introduction to microprocessors
PDF
8085 microprocessor notes
PPTX
Microprocessor Fundamentals
PPTX
RTC Interfacing and Programming
PPTX
Pin diagram 8085 and explanation of 8085 microprocessor.
PPTX
Introduction to 8085 Microprocessor
PPTX
Pic 18 microcontroller
Interrupts of 8085
introduction to microprocessors
8085 microprocessor notes
Microprocessor Fundamentals
RTC Interfacing and Programming
Pin diagram 8085 and explanation of 8085 microprocessor.
Introduction to 8085 Microprocessor
Pic 18 microcontroller

What's hot (20)

PPTX
Traffic Light Controller using 8255
PDF
Keypad Interfacing with 8051 Microcontroller
PPT
8085 interrupts
PPTX
ARM Processors
PDF
Introduction to pic microcontroller
PPTX
Arm cortex-m4 programmer model
PPTX
Pic microcontroller architecture
PPT
Addressing modes of 8051
PPT
Memory organization of 8051
PPTX
PIC-18 Microcontroller
PPTX
8051 timer counter
PPTX
Architecture of 8051
PDF
ARM CORTEX M3 PPT
PPT
PIC Microcontrollers.ppt
PPTX
8051 Microcontroller PPT's By Er. Swapnil Kaware
DOC
8051 Microcontroller Notes
PPTX
Timer counter in arm7(lpc2148)
PPT
8051 Microcontroller
PPTX
8255 PPI
PPTX
Interrupts of microprocessor 8085
Traffic Light Controller using 8255
Keypad Interfacing with 8051 Microcontroller
8085 interrupts
ARM Processors
Introduction to pic microcontroller
Arm cortex-m4 programmer model
Pic microcontroller architecture
Addressing modes of 8051
Memory organization of 8051
PIC-18 Microcontroller
8051 timer counter
Architecture of 8051
ARM CORTEX M3 PPT
PIC Microcontrollers.ppt
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller Notes
Timer counter in arm7(lpc2148)
8051 Microcontroller
8255 PPI
Interrupts of microprocessor 8085
Ad

Similar to Interrupts for PIC18 (20)

PPTX
unit 3 a.pptxppppppppppppppppppppppppppp
PDF
PA UNIT 3 (FR INFORMATION TECHNOLOGY) SPPU
PPTX
Micro controller 8051 Interrupts
PPTX
Interrupt programming
PPTX
Interrupt in 8051
PPTX
Mc module5 ppt_msj
PPTX
Embedded systems, lesson 16
PPTX
Interrupts
PPTX
Interrupts in 8051
PPTX
Interrupts programming in embedded C using 8051
PDF
8051-interrupts-temporary suspension of a program
PPTX
37471656 interrupts
PPT
ES-CH6.ppt
PPTX
Interrupts of 8051 microcontroller.newpp
PPT
8051 Inturrpt
DOCX
Interrupts
PPTX
Interrupts on 8086 microprocessor by vijay kumar.k
PPTX
Timing n interrupt.pptx
PPT
8051 interrupts
PDF
Microcontroller part 2
unit 3 a.pptxppppppppppppppppppppppppppp
PA UNIT 3 (FR INFORMATION TECHNOLOGY) SPPU
Micro controller 8051 Interrupts
Interrupt programming
Interrupt in 8051
Mc module5 ppt_msj
Embedded systems, lesson 16
Interrupts
Interrupts in 8051
Interrupts programming in embedded C using 8051
8051-interrupts-temporary suspension of a program
37471656 interrupts
ES-CH6.ppt
Interrupts of 8051 microcontroller.newpp
8051 Inturrpt
Interrupts
Interrupts on 8086 microprocessor by vijay kumar.k
Timing n interrupt.pptx
8051 interrupts
Microcontroller part 2
Ad

Recently uploaded (20)

PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Well-logging-methods_new................
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPT
Project quality management in manufacturing
PDF
Structs to JSON How Go Powers REST APIs.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
web development for engineering and engineering
PPTX
Geodesy 1.pptx...............................................
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
PPT on Performance Review to get promotions
PPTX
Welding lecture in detail for understanding
DOCX
573137875-Attendance-Management-System-original
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
bas. eng. economics group 4 presentation 1.pptx
Well-logging-methods_new................
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Project quality management in manufacturing
Structs to JSON How Go Powers REST APIs.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
web development for engineering and engineering
Geodesy 1.pptx...............................................
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPT on Performance Review to get promotions
Welding lecture in detail for understanding
573137875-Attendance-Management-System-original

Interrupts for PIC18

  • 1. Interrupts for PIC18 DEPARTMENT OF ELECTRICAL ENGINEERING IIT JODHPUR PRESENTED BY •DEEPAK KUMAR KALAWANIA
  • 2. PIC18 INTERRUPTS INTRODUCTION:- Interrupts are mechanisms which enable instant response to events such as counter overflow, pin change, data received, etc. • In normal mode, microcontroller executes the main program as long as there are no occurrences that would cause an interrupt. • Upon interrupt, microcontroller stops the execution of main program and commences the special part of the program(ISR) which will analyze and handle the interrupt.
  • 3. PIC can serve multiple devices using mechanisms of – Polling • PIC continuously monitors the status of each device • Each device get the attention of the CPU as the same level of priority • Wastes u-Controllers time by polling devices that do not need service. – Interrupt • Devices get the attention of the CPU only when it needs a service • Can service many devices with different level of priorities
  • 4. Interrupt service routine (ISR) • When an interrupt is invoked the uC runs the Interrupt Service Routine(ISR) • Interrupt vector table holds the address of ISRs – Power-on Reset 0000h – High priority interrupt 0008h – Low priority interrupt 0018h
  • 5. Steps in executing an interrupt • Upon activation of interrupt the microcontroller – Finishes executing the current instruction – Pushes the PC of next instruction in the stack – Jumps to the interrupt vector table to get the address of ISR and jumps to it – Begin executing the ISR instructions to the last instruction of ISR (RETFIE) – Executes RETFIE • Pops the PC from the stack • Starts to execute from the address of that PC
  • 7. Sources of interrupts in PIC18 • External hardware interrupts – Pins RB0(INT0),RB1(INT1),RB2(INT2) • Timers – Timer0 , Timer1 ,Timer2
  • 8. Enabling and disabling an interrupt • When the PIC is powered on (or resets) – All interrupts are masked (disabled) – The default ISR address is 0008h • No interrupt priorities for interrupts
  • 9. Enabling and disabling an interrupt In general, interrupt sources have three bits to control their operation. They are: • Flag bit – to indicate that an interrupt event occurred • Enable bit – that allows program execution to branch to the interrupt vector address when the flag bit is set • Priority bit – to select high priority or low priority
  • 10. Steps in enabling an interrupt • Set the GIE bit from INTCON REG • Set the IE bit for that interrupt • If the interrupt is one of the peripheral (timers 1,2 , serial,etc ) set PEIE bit(6) from INTCON reg
  • 11. Example a) BSF INTCON,TMR0IE BSF INTCON,INT0IE BSF INTCON,GIE Or MOVLW B’10110000’ MOVWF INTCON b) BCF INTCON,TMR0IE c) BCF INTCON,GIE
  • 12. Program - External hardware interrupt ORG 0000H GOTO MAIN ORG 0008H BTFSS INTCON,INT0IF RETFIE GOTO INT0_ISR ORG 00100H MAIN BCF TRISB,7 BSF TRISB,INT0 CLRF TRISD SETF TRISC BSF INTCON,INT0IE BSF INTCON,GIE OVER MOVFF PORTC,PORTD BRA OVER INT0_ISR ORG 200H BTG PORTB,7 BCF INTCON,INT0IF RETFIE END
  • 13. Program - Edge-triggered interrupts ORG 0000H GOTO MAIN ORG 0008H BTFSS INTCON,INT0IF RETFIE GOTO INT1_ISR ORG 00100H MAIN BCF TRISB,7 BSF TRISB,INT1 BSF INTCON3,INT1IE BCF INTCON2,INTEDGE1 BSF INTCON,GIE OVER BRA OVER BRA OVER INT1_ISR ORG 200H BTG PORTB,7 BCF INTCON3,INT1IF RETFIE END
  • 14. Sampling the Edge triggered interrupt • The external source must be held high for at least two instruction cycles • For XTAL 10Mhz • Instruction cycle time is 400ns,0.4us • So minimum pulse duration to detect edge triggered interrupts = 2 instruction cycle =0.8us
  • 15. At what address does the CPU wake up when power applied? • The uC wakes up at memory address 0000 • The PC has the value 0000 • ORG directive put the address of the first op code at the memory location 0000 Powering UP
  • 16. INTCON global interupt enable • INT pin interrupt • TMR0 overflow interrupt • GP port change interrupt • GP port change interrupt • INT pin interrupt • TMR0 overflow interrupt FLAGSENABLES
  • 17. Timer Interrupts Interrupt Flag Bit Register Enable Bit Register Timer0 TMR0IF INTCON TMR0IE INTCON Timer1 TMR1IF PIR1 TMR1IE PIE1 Timer2 TMR2IF PIR1 TMR3IE PIE1 Timer3 TMR3IF PIR3 TMR3IE PIE2 Timer Interrupt Flag Bits and Associated Registers INTCON Register with Timer0 Interrupt Enable and Interrupt Flag
  • 19. Program - ORG 0000H GOTO MAIN ORG 0008H BTFSS INTCON,TMR0IF RETFIE GOTO T0_ISR ORG 00100H MAIN BCF TRISB,5 CLRF TRISD SETF TRISC MOVLW 0x08 MOVWF T0CON MOVLW 0xFF MOVWF TMR0H MOVLW 0xF2 MOVWF TMR0L BCF INTCON,TMR0IF BSF T0CON,TMR0ON BSF INTCON,TMR0IE BSF INTCON,GIE OVER MOVFF PORTC,PORTD BRA OVER Timer0 Interrupt T0_ISR ORG 200H MOVLW 0xFF MOVWF TMR0H MOVLW 0xF2 MOVWF TMR0L BTG PORTB,5 BCF INTCON,TMR0IF RETFIE END
  • 21. Serial Communication Interrupts Interrupt Flag Bit Register Enable Bit Register TXIF (Transmit) TXIF PIR1 TXIE PIE1 RCIF (Receive) RCIF PIR1 RCIE PIE1 Serial Port Interrupt Flag Bits and Associated Registers PIE1 Register Bits Holding TXIE and RCIE
  • 22. Program ORG 0000H GOTO MAIN ORG 0008H BTFSC PIR1,TXIF BRA TX_ISR RETFIE ORG 0040H TX_ISR MOVWFF PORTD,TXREG RETFIE ORG 00100H MAIN SETF TRISD MOVLW 0x20 MOVWF TXSTA MOVLW D'15' MOVWF SPBRG BCF TRISC, TX BSF RCSTA, SPEN BSF PIE1 ,TXIE BSF INTCON,PEIE BSF INTCON,GIE OVER BRA OVER END Serial Port Interrupt Enable peripheral Interrupt 11-22 8 bit switch is connected to port.D. the PIC18 reads data from PORTD and writes it to TXREG.