SlideShare a Scribd company logo
SUB ROUTINESSUB ROUTINES
Instead of repeating same program
segments at all locations, they are written
and stored separately;
Each such block of instructions which
carries out a specific and well defined task
is called a ‘Subroutine’.
SUB ROUTINESSUB ROUTINES
Halt the main program
Provide returning to the same point.
Transfer control to the subroutine.
Execute the subroutine.
Revert to the main routine.
MOVWF
CALL bb
aa-2
aa-1
aa
aa+1
aa+2
bb-1
bb
bb+1
cc-1
cc
cc+1
RETURN
MainRoutineSubRoutine
2
3
aa+1
1
4
Program Memory
PC Content
Subrouti
ne
operation
s
Stack contents should remain undisturbed
during the execution of the subroutine.
Registers used in the main pgm and those in
the subroutine are not to be mixed up.
While using Goto statement, ensure that
program control is brought back to the
subroutine (using RETURN)
CALL statement has to specify the
subroutine address;13 bits PC is generated with
11 bits of address and PCLATH<4:3> as MS
SUB ROUTINE NESTINGSUB ROUTINE NESTING
Calling of one subroutine inside another
aa-1
aa
aa+1
bb
dd
dd+1
cc-1
cc
aa+1
dd+1
ee
ff
1 2
4
5
3
7
6
9
7
8
9
CALL bb
CALL ee
RETURN
RETURN
stack
PC content
Program
memory
Mainprogram
segment
Subroutine1
segment
Subroutine2
segment
CALL bb
[Subroutine 1]
aa CALL bb
PC
aa+1
stack
bb aa+1
CALL ee
[Subroutine 2]
Return from
Subroutine 2
Return from
Subroutine 1
dd CALL ee
aa+1
PC
dd+1
ee
stack
dd+1
RETURN
aa+1
PC
dd+1
stack
RETURN
PC
stack
aa+1
Sequence of operation during Subroutine nesting….
Regular operation of the processor is
interrupted
and a priority activity is carried out;
once the same is completed,
the regular operation is resumed
Increment PC
Fetch & execute next instruction
Interrupt
Flag
Save return address in stack
Attend to Interrupt (Carry out ISR)
Retrieve return address from Stack
reset
set
Processor Operation while
interrupted
Call occurs at specific
and predetermined
locations in the main
routine.
Can ask for service
without any prior notice.
Hardware initiated.Software initiated.
Request can come
expectedly.
Request can come
unexpectedly; may have
to carry out some
emergency activities-like
saving the status of
scratch pad registers.
Any of the peripherals associated with PIC can interrupt the
microcontroller.
External Peripherals can also interrupt the processor.
Each interrupt has an associated Interrupt Flag.
Interrupt can be masked by resetting its Interrupt Enable Flag.
Three conditions are to be satisfied for a source to interrupt
The interrupt flag has to be set by the Interrupt
Request(IRQ) going high.
The interrupt has to be enabled by the microcontroller by
setting the concerned Interrupt Enable Flag.
The GIE flag has to be set-again by the controller.
PIC 16F877A has 10 sources of interrupt:
External Interrupt
TMR0 Over Flow Interrupt
PORT B Change Interrupt
Comparator Interrupt
USART Interrupt TX
USART Interrupt RX
CCP Interrupt
TMR1 Over Flow Interrupt
TMR2 Match Interrupt
Data EEPROM Interrupt
INTE RBIE T0IF INTFT0IEGIE PEIE RBIF
B4 B3 B2 B1B5B7 B6 B0
INTCON REGISTER
GIE GLOBAL INTERRUPT ENABLE BIT
PIE PERIPHERAL INTERRUPT ENABLE BIT
T0IE TMER 0 OVERFLOW INT ENABLE BIT
INTE RB0/INT EXT INT ENABLE BIT
RBIE RB PORT CHANGE INT ENABLE BIT
T0IF TMR0 OVERFLOW INT FLAG BIT
INTF RB0/INT EXT INT FLAG BIT
RBIF RB PORT CHANGE INT FLAG BIT
TMR1IE
TMR1IF
TMR2IE
TMR2IF
CCPIE
CCPIF
CMIE
CMIF
TXIE
TXIF
RXIE
RXIF
EEIE
EEIF
TMR0IE
TMR0IF
INTF
INTE
RBIF
RBIE
PEIE
GIE
INT
I n t e r r u p t
T X I F
1
2
3
T M R 2 I F
E E I F
R C I F
1
2
3
I N T F
T X I E
I N T E
1
2
3
1
2
3
1
2
3
R B I FE E I E
R B I E
T M R 1 I E
1
2
3
1
2
3
T M R 1 I F
T M R 2 I E
R C I E
1
2
3
1
2
3
P E I E
1
2
3
1
2
3
1
2
3
C C P I F
T 0 I E
G I E
T 0 I F
C M I E
1
2
3
C C P I E
C M I F
1
2
3
INTERRUPT LOGIC
Interrupt Request and Response – Sequence of Activities
Positioning of ISR in Program Memory
The PIC has the provision to start the
ISR at location 0X004H
The location 0X04H can have a simple
GOTO ISR instruction.
0x04h
Interrupt
from
source A
Service routine
A
Service routine B
yes
no
004h BTFSS PIR,A
GOTO SRB
---------------
--[ISR A]----
----------------
RETFIE
SRB : ---[ISR B]---
-------------
RETFIE
004h BTFSS PIR,A
GOTO SRB
---------------
--[ISR A]----
----------------
RETFIE
SRB : ---[ISR B]---
-------------
RETFIE
Stores the W register
Stores the Status register
Executes the ISR code
Restores the Status
Restores the W register
The common memory area with addresses 70h to 7Fh can be used
to store such data.
It eliminates the need to switch banks back and forth to access data
during interrupt service.
Scratchpad register assignment and status saving for each
service routine have to be done with care to avoid any mix up.
While using Goto statement, ensure that program control is
brought back to the subroutine (using RETFIE)
The return addresses of subroutines as well as those of
interrupt services are saved in the same stack.
The service routine can complete the more prioritized task of
one source, enable GIE(to allow IRQ from source B) and then
take up the second (non priority)task.
If more interrupts which exceeds the 8 level stack, are
involved; assign a different processor.
THANK YOU

More Related Content

What's hot

Traffic Light Controller using 8255
Traffic Light Controller using 8255Traffic Light Controller using 8255
Traffic Light Controller using 8255
Amit Kumer Podder
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
Aarav Soni
 
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
Vijay Kumar
 
Important questions
Important questionsImportant questions
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
Mustapha Fatty
 
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSORTRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
Subash Sambath Kumar
 
Memory interfacing of microcontroller 8051
Memory interfacing of microcontroller 8051Memory interfacing of microcontroller 8051
Memory interfacing of microcontroller 8051
Nilesh Bhaskarrao Bahadure
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
Suchismita Paul
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
prasadpawaskar
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction Set
Dr. Pankaj Zope
 
Advanced micro -processor
Advanced micro -processorAdvanced micro -processor
Advanced micro -processor
Hinal Lunagariya
 
Code Conversion in 8085 Microprocessor
Code Conversion in 8085 MicroprocessorCode Conversion in 8085 Microprocessor
Code Conversion in 8085 Microprocessor
MOHIT AGARWAL
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
Prof. Swapnil V. Kaware
 
Subroutine in 8051 microcontroller
Subroutine in 8051 microcontrollerSubroutine in 8051 microcontroller
Subroutine in 8051 microcontroller
bhadresh savani
 
Microcontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory portsMicrocontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory ports
Nilesh Bhaskarrao Bahadure
 
Timing Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 MicroprocessorTiming Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 Microprocessor
Dhrumil Panchal
 
Microprogram Control
Microprogram Control Microprogram Control
Microprogram Control
Anuj Modi
 
8085 instruction set
8085 instruction set8085 instruction set
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
Poojith Chowdhary
 
8051 interrupts
8051 interrupts8051 interrupts
8051 interrupts
Shreyans Pathak
 

What's hot (20)

Traffic Light Controller using 8255
Traffic Light Controller using 8255Traffic Light Controller using 8255
Traffic Light Controller using 8255
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
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
 
Important questions
Important questionsImportant questions
Important questions
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
 
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSORTRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
 
Memory interfacing of microcontroller 8051
Memory interfacing of microcontroller 8051Memory interfacing of microcontroller 8051
Memory interfacing of microcontroller 8051
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction Set
 
Advanced micro -processor
Advanced micro -processorAdvanced micro -processor
Advanced micro -processor
 
Code Conversion in 8085 Microprocessor
Code Conversion in 8085 MicroprocessorCode Conversion in 8085 Microprocessor
Code Conversion in 8085 Microprocessor
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
Subroutine in 8051 microcontroller
Subroutine in 8051 microcontrollerSubroutine in 8051 microcontroller
Subroutine in 8051 microcontroller
 
Microcontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory portsMicrocontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory ports
 
Timing Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 MicroprocessorTiming Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 Microprocessor
 
Microprogram Control
Microprogram Control Microprogram Control
Microprogram Control
 
8085 instruction set
8085 instruction set8085 instruction set
8085 instruction set
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
 
8051 interrupts
8051 interrupts8051 interrupts
8051 interrupts
 

Similar to subroutines and interrupts

ES-CH6.ppt
ES-CH6.pptES-CH6.ppt
ES-CH6.ppt
alaakaraja1
 
80 c51 family programmer’s guide
80 c51 family programmer’s guide80 c51 family programmer’s guide
80 c51 family programmer’s guide
Pratheesh Pala
 
89 c2051
89 c205189 c2051
89 c2051
Nitin Joshi
 
At89 c2051 (3)
At89 c2051 (3)At89 c2051 (3)
At89 c2051 (3)
angiey y
 
At89c4051
At89c4051At89c4051
Pic full note
Pic full notePic full note
Registers
RegistersRegisters
Registers
Jamia Hamdard
 
Basic computer organisation design
Basic computer organisation designBasic computer organisation design
Basic computer organisation design
Sanjeev Patel
 
pic_1.pdf
pic_1.pdfpic_1.pdf
pic_1.pdf
ZatinGupta2
 
Lecture on PIC-1.pptx
Lecture on PIC-1.pptxLecture on PIC-1.pptx
Lecture on PIC-1.pptx
godfrey35
 
Microprocessor Part 4
Microprocessor    Part 4Microprocessor    Part 4
Microprocessor Part 4
Sajan Agrawal
 
Pic16f84
Pic16f84Pic16f84
Chp4 introduction to the pic microcontroller copy
Chp4 introduction to the pic microcontroller   copyChp4 introduction to the pic microcontroller   copy
Chp4 introduction to the pic microcontroller copy
mkazree
 
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIWLec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Hsien-Hsin Sean Lee, Ph.D.
 
At 89s51
At 89s51At 89s51
At 89s51
Mr Giap
 
Overview of LPC213x MCUs
Overview of LPC213x MCUsOverview of LPC213x MCUs
Overview of LPC213x MCUs
Premier Farnell
 
My seminar new 28
My seminar new 28My seminar new 28
My seminar new 28
rajeshkvdn
 
At89s51
At89s51At89s51
At89c2051 Data sheet
At89c2051 Data sheetAt89c2051 Data sheet
At89c2051 Data sheet
Microtech Solutions
 
Dv3
Dv3Dv3
Dv3
EXT21
 

Similar to subroutines and interrupts (20)

ES-CH6.ppt
ES-CH6.pptES-CH6.ppt
ES-CH6.ppt
 
80 c51 family programmer’s guide
80 c51 family programmer’s guide80 c51 family programmer’s guide
80 c51 family programmer’s guide
 
89 c2051
89 c205189 c2051
89 c2051
 
At89 c2051 (3)
At89 c2051 (3)At89 c2051 (3)
At89 c2051 (3)
 
At89c4051
At89c4051At89c4051
At89c4051
 
Pic full note
Pic full notePic full note
Pic full note
 
Registers
RegistersRegisters
Registers
 
Basic computer organisation design
Basic computer organisation designBasic computer organisation design
Basic computer organisation design
 
pic_1.pdf
pic_1.pdfpic_1.pdf
pic_1.pdf
 
Lecture on PIC-1.pptx
Lecture on PIC-1.pptxLecture on PIC-1.pptx
Lecture on PIC-1.pptx
 
Microprocessor Part 4
Microprocessor    Part 4Microprocessor    Part 4
Microprocessor Part 4
 
Pic16f84
Pic16f84Pic16f84
Pic16f84
 
Chp4 introduction to the pic microcontroller copy
Chp4 introduction to the pic microcontroller   copyChp4 introduction to the pic microcontroller   copy
Chp4 introduction to the pic microcontroller copy
 
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIWLec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
 
At 89s51
At 89s51At 89s51
At 89s51
 
Overview of LPC213x MCUs
Overview of LPC213x MCUsOverview of LPC213x MCUs
Overview of LPC213x MCUs
 
My seminar new 28
My seminar new 28My seminar new 28
My seminar new 28
 
At89s51
At89s51At89s51
At89s51
 
At89c2051 Data sheet
At89c2051 Data sheetAt89c2051 Data sheet
At89c2051 Data sheet
 
Dv3
Dv3Dv3
Dv3
 

Recently uploaded

digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 

Recently uploaded (20)

digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 

subroutines and interrupts

  • 1.
  • 2. SUB ROUTINESSUB ROUTINES Instead of repeating same program segments at all locations, they are written and stored separately; Each such block of instructions which carries out a specific and well defined task is called a ‘Subroutine’.
  • 3. SUB ROUTINESSUB ROUTINES Halt the main program Provide returning to the same point. Transfer control to the subroutine. Execute the subroutine. Revert to the main routine.
  • 5. Stack contents should remain undisturbed during the execution of the subroutine. Registers used in the main pgm and those in the subroutine are not to be mixed up. While using Goto statement, ensure that program control is brought back to the subroutine (using RETURN) CALL statement has to specify the subroutine address;13 bits PC is generated with 11 bits of address and PCLATH<4:3> as MS
  • 6. SUB ROUTINE NESTINGSUB ROUTINE NESTING Calling of one subroutine inside another aa-1 aa aa+1 bb dd dd+1 cc-1 cc aa+1 dd+1 ee ff 1 2 4 5 3 7 6 9 7 8 9 CALL bb CALL ee RETURN RETURN stack PC content Program memory Mainprogram segment Subroutine1 segment Subroutine2 segment
  • 7. CALL bb [Subroutine 1] aa CALL bb PC aa+1 stack bb aa+1 CALL ee [Subroutine 2] Return from Subroutine 2 Return from Subroutine 1 dd CALL ee aa+1 PC dd+1 ee stack dd+1 RETURN aa+1 PC dd+1 stack RETURN PC stack aa+1 Sequence of operation during Subroutine nesting….
  • 8. Regular operation of the processor is interrupted and a priority activity is carried out; once the same is completed, the regular operation is resumed
  • 9. Increment PC Fetch & execute next instruction Interrupt Flag Save return address in stack Attend to Interrupt (Carry out ISR) Retrieve return address from Stack reset set Processor Operation while interrupted
  • 10. Call occurs at specific and predetermined locations in the main routine. Can ask for service without any prior notice. Hardware initiated.Software initiated. Request can come expectedly. Request can come unexpectedly; may have to carry out some emergency activities-like saving the status of scratch pad registers.
  • 11. Any of the peripherals associated with PIC can interrupt the microcontroller. External Peripherals can also interrupt the processor. Each interrupt has an associated Interrupt Flag. Interrupt can be masked by resetting its Interrupt Enable Flag. Three conditions are to be satisfied for a source to interrupt The interrupt flag has to be set by the Interrupt Request(IRQ) going high. The interrupt has to be enabled by the microcontroller by setting the concerned Interrupt Enable Flag. The GIE flag has to be set-again by the controller.
  • 12. PIC 16F877A has 10 sources of interrupt: External Interrupt TMR0 Over Flow Interrupt PORT B Change Interrupt Comparator Interrupt USART Interrupt TX USART Interrupt RX CCP Interrupt TMR1 Over Flow Interrupt TMR2 Match Interrupt Data EEPROM Interrupt
  • 13. INTE RBIE T0IF INTFT0IEGIE PEIE RBIF B4 B3 B2 B1B5B7 B6 B0 INTCON REGISTER GIE GLOBAL INTERRUPT ENABLE BIT PIE PERIPHERAL INTERRUPT ENABLE BIT T0IE TMER 0 OVERFLOW INT ENABLE BIT INTE RB0/INT EXT INT ENABLE BIT RBIE RB PORT CHANGE INT ENABLE BIT T0IF TMR0 OVERFLOW INT FLAG BIT INTF RB0/INT EXT INT FLAG BIT RBIF RB PORT CHANGE INT FLAG BIT
  • 15. I n t e r r u p t T X I F 1 2 3 T M R 2 I F E E I F R C I F 1 2 3 I N T F T X I E I N T E 1 2 3 1 2 3 1 2 3 R B I FE E I E R B I E T M R 1 I E 1 2 3 1 2 3 T M R 1 I F T M R 2 I E R C I E 1 2 3 1 2 3 P E I E 1 2 3 1 2 3 1 2 3 C C P I F T 0 I E G I E T 0 I F C M I E 1 2 3 C C P I E C M I F 1 2 3 INTERRUPT LOGIC
  • 16. Interrupt Request and Response – Sequence of Activities
  • 17. Positioning of ISR in Program Memory The PIC has the provision to start the ISR at location 0X004H The location 0X04H can have a simple GOTO ISR instruction.
  • 18. 0x04h Interrupt from source A Service routine A Service routine B yes no 004h BTFSS PIR,A GOTO SRB --------------- --[ISR A]---- ---------------- RETFIE SRB : ---[ISR B]--- ------------- RETFIE 004h BTFSS PIR,A GOTO SRB --------------- --[ISR A]---- ---------------- RETFIE SRB : ---[ISR B]--- ------------- RETFIE
  • 19. Stores the W register Stores the Status register Executes the ISR code Restores the Status Restores the W register The common memory area with addresses 70h to 7Fh can be used to store such data. It eliminates the need to switch banks back and forth to access data during interrupt service.
  • 20. Scratchpad register assignment and status saving for each service routine have to be done with care to avoid any mix up. While using Goto statement, ensure that program control is brought back to the subroutine (using RETFIE) The return addresses of subroutines as well as those of interrupt services are saved in the same stack. The service routine can complete the more prioritized task of one source, enable GIE(to allow IRQ from source B) and then take up the second (non priority)task. If more interrupts which exceeds the 8 level stack, are involved; assign a different processor.