Presentation is loading. Please wait.

Presentation is loading. Please wait.

PIC18 Interrupt Programming

Similar presentations


Presentation on theme: "PIC18 Interrupt Programming"— Presentation transcript:

1 PIC18 Interrupt Programming
“Explain the interrupts, timer interrupts, external hardware interrupts, serial communication interrupts and the interrupts priority”

2 Objectives Contra and compare interrupts versus pooling
Explain the purpose of the ISR List all the major interrupts of the PIC18 Explain the purpose of the IVT Enable and disable PIC18 interrupts Program the PIC18 interrupt using assembly language

3 Interrupt Whenever any device needs the microcontroller’s service the device notifies it by sending an interrupt signal. Upon receiving an interrupt signal, the microcontroller stops whatever it is doing and serve the device. The program associated with the interrupt is called ISR (interrupt service routine) or interrupt handler. Each device can get the attention of the microcontroller based on the priority assign to it. Can ignore a device request for service

4 Polling The microcontroller continuously monitors the status of a given device; when the status condition met, it performs the service. After that, it moves on to monitor the next device until each one is service. Cannot assign priority because it checks all devices in a round-robin fashion. Cannot ignore a devices for service

5 Interrupt Service Routine (ISR)
ROM Location (hex) Power-on-Reset 0000 High Priority Interrupt 0008 (Default upon power-on reset) Low Priority Interrupt 0018 Interrupt Vector Table for the PIC18 Fixed Location in Memory

6 Step in Executing an Interrupt
It finishes the instruction it is executing and saves the address of the next instruction (program counter) on the stack It jumps to a fixed location in memory (interrupt vector table (IVT)). The IVT directs the microcontroller to the address of the ISR The microcontroller gets the address of the ISR from the IVT and jumps to it. It start to execute the interrupt service subroutine until it reaches the last instruction of the subroutine - RETFIE (Return from Interrupt Exit) Upon executing the RETFIE instruction, the microcontroller returns to the place where it was interrupted

7 Sources of Interrupt Each Timers
3 interrupts for external hardware. Pin RB0 (INT0), RB1 (INT1) and RB2 (INT2) 2 interrupts for serial communication (Receive and Transmit) The PORTB-Change interrupt (RB4-RB7) The ADC The CCP

8 Enable and Disable an Interrupt
BSF INTCON,GIE BCF INTCON,GIE

9 Timer Interrupts Interrupt Flag Bit Register Enable Bit Timer0 TMR0IF
INTCON TMR0IE Timer1 TMR1IF PIR1 TMR1IE PIE1 Timer2 TMR2IF TMR3IE Timer3 TMR3IF PIR3 PIE2 Timer Interrupt Flag Bits and Associated Registers INTCON Register with Timer0 Interrupt Enable and Interrupt Flag

10 Page 435

11 External Hardware Interrupts
Flag Bit Register Enable Bit INT0(RB0) INT0IF INTCON INT0IE INT1 (RB1) INT1IF INTCON3 INT1IE INT2 (RB2) INT2IF INT2IE Hardware Interrupt Flag Bits and Associated Registers Positive-edge-triggered interrupt PIC18 External Hardware Interrupt Pins

12 Please see Program (pg 441)

13 Serial Communication Interrupts
Flag Bit Register Enable Bit TXIF (Trasmit) TXIF PIR1 TXIE PIE1 RCIF (Receive) RCIF RCIE Serial Port Interrupt Flag Bits and Associated Registers PIE1 Register Bits Holding TXIE and RCIE

14 Please see Program 11-7 (pg 447)

15 PORTB-Change Interrupt
INTCON Register * Use in Keypad Interfacing * Status: H-L or L-H

16 Differences Between External Hardware and PORTB-Change Interrupt
This (RB0-RB2) interrupts has its own pin and is independent each other Use s all four (RB4-RB7) and considered to be a single interrupt even though it can use up to four pins Has it own flag (INTxIF) and independent each other Single flag only (RBIF) Can be programmed to trigger on the negative or positive edge Cause an interrupt either pin changes status from HIGH-LOW or LOW-HIGH

17 Please see Program (pg 453)

18 Interrupt Priority Interrupt ROM Location (hex) Power-on-Reset 0000
High Priority Interrupt 0008 (Default upon power-on reset) Low Priority Interrupt 0018

19 Interrupt Priority (Cont’d)
Upon Power-on Reset

20 IPR1 Peripheral Interrupt Priority Register

21 “Never interrupt your enemy when he/she is making a mistake“
End Of Chapter “Never interrupt your enemy when he/she is making a mistake“


Download ppt "PIC18 Interrupt Programming"

Similar presentations


Ads by Google