SlideShare a Scribd company logo
1 of 22
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
MOVFF PORTC,PORTD
BRA OVER
INT0_ISR
ORG 200H
BTG PORTB,7
BCF INTCON,INT0IF
RETFIE
END
OVER
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
BRA OVER
BRA OVER
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
• GP port
change
interrupt
• INT pin interrupt
• TMR0 overflow interrupt
• GP port
change
interrupt
• INT pin interrupt
• TMR0 overflow interrupt
FLAGS
ENABLES
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
BTFSC PIR1,TXIF
BRA TX_ISR
RETFIE
ORG 0000H ORG 00100H
GOTO MAIN MAIN SETF TRISD
MOVLW 0x20
ORG 0008H MOVWF TXSTA
ORG 0040H
TX_ISR
MOVWFF PORTD,TXREG
RETFIE OVER
Serial Port Interrupt
MOVLW D'15'
MOVWF SPBRG
BCF TRISC, TX
BSF RCSTA, SPEN
BSF PIE1 ,TXIE
BSF INTCON,PEIE
BSF INTCON,GIE
BRA OVER
END
Enable peripheral Interrupt
11-22
8 bit switch is connected to port.D. the PIC18 reads data from PORTD and
writes it to TXREG.
unit 3 a.pptxppppppppppppppppppppppppppp

More Related Content

Similar to unit 3 a.pptxppppppppppppppppppppppppppp

8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti 8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti VenkatraoRamisetti
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxnaveen088888
 
Microprocessor 8051
Microprocessor 8051Microprocessor 8051
Microprocessor 8051Anil Maurya
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kVijay Kumar
 
Lecture on PIC-1.pptx
Lecture on PIC-1.pptxLecture on PIC-1.pptx
Lecture on PIC-1.pptxgodfrey35
 
8051 microcontroller and it’s interface
8051 microcontroller and it’s interface8051 microcontroller and it’s interface
8051 microcontroller and it’s interfaceAbhishek Choksi
 
Atmel and pic microcontroller
Atmel and pic microcontrollerAtmel and pic microcontroller
Atmel and pic microcontrollerTearsome Llantada
 
37471656 interrupts
37471656 interrupts37471656 interrupts
37471656 interruptstt_aljobory
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxRAJEEVKUMARYADAV11
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Vikas Dongre
 
With suitable diagram explain the working of 8255 a and inerrupts
With suitable diagram explain the working of 8255 a and inerruptsWith suitable diagram explain the working of 8255 a and inerrupts
With suitable diagram explain the working of 8255 a and inerruptsransherraj
 
8085 interrupts
8085 interrupts8085 interrupts
8085 interruptsIsha Negi
 
8085 interrupts
8085 interrupts8085 interrupts
8085 interruptsIsha Negi
 

Similar to unit 3 a.pptxppppppppppppppppppppppppppp (20)

DPA
DPADPA
DPA
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti 8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptx
 
8051 interrupts
8051 interrupts8051 interrupts
8051 interrupts
 
Mc module5 ppt_msj
Mc module5 ppt_msjMc module5 ppt_msj
Mc module5 ppt_msj
 
Microprocessor 8051
Microprocessor 8051Microprocessor 8051
Microprocessor 8051
 
ES-CH6.ppt
ES-CH6.pptES-CH6.ppt
ES-CH6.ppt
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.k
 
Lecture on PIC-1.pptx
Lecture on PIC-1.pptxLecture on PIC-1.pptx
Lecture on PIC-1.pptx
 
8051
80518051
8051
 
8051 microcontroller and it’s interface
8051 microcontroller and it’s interface8051 microcontroller and it’s interface
8051 microcontroller and it’s interface
 
Atmel and pic microcontroller
Atmel and pic microcontrollerAtmel and pic microcontroller
Atmel and pic microcontroller
 
37471656 interrupts
37471656 interrupts37471656 interrupts
37471656 interrupts
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051
 
With suitable diagram explain the working of 8255 a and inerrupts
With suitable diagram explain the working of 8255 a and inerruptsWith suitable diagram explain the working of 8255 a and inerrupts
With suitable diagram explain the working of 8255 a and inerrupts
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
8085 interrupts
8085 interrupts8085 interrupts
8085 interrupts
 
8085 interrupts
8085 interrupts8085 interrupts
8085 interrupts
 

Recently uploaded

Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 

Recently uploaded (20)

(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 

unit 3 a.pptxppppppppppppppppppppppppppp

  • 1. 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.
  • 2. 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
  • 3. 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 •
  • 4. 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
  • 6. Sources of interrupts in PIC18 • External hardware interrupts – Pins RB0(INT0),RB1(INT1),RB2(INT2) • Timers – Timer0 , Timer1 ,Timer2
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. 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 MOVFF PORTC,PORTD BRA OVER INT0_ISR ORG 200H BTG PORTB,7 BCF INTCON,INT0IF RETFIE END OVER
  • 12. 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 BRA OVER BRA OVER OVER INT1_ISR ORG 200H BTG PORTB,7 BCF INTCON3,INT1IF RETFIE END
  • 13. 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
  • 14. 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
  • 15. INTCON global interupt enable • GP port change interrupt • INT pin interrupt • TMR0 overflow interrupt • GP port change interrupt • INT pin interrupt • TMR0 overflow interrupt FLAGS ENABLES
  • 16. 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
  • 18. 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
  • 20. 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
  • 21. Program BTFSC PIR1,TXIF BRA TX_ISR RETFIE ORG 0000H ORG 00100H GOTO MAIN MAIN SETF TRISD MOVLW 0x20 ORG 0008H MOVWF TXSTA ORG 0040H TX_ISR MOVWFF PORTD,TXREG RETFIE OVER Serial Port Interrupt MOVLW D'15' MOVWF SPBRG BCF TRISC, TX BSF RCSTA, SPEN BSF PIE1 ,TXIE BSF INTCON,PEIE BSF INTCON,GIE BRA OVER END Enable peripheral Interrupt 11-22 8 bit switch is connected to port.D. the PIC18 reads data from PORTD and writes it to TXREG.