1 / 26

PIC18 Interrupt Programming

PIC18 Interrupt Programming. “Explain the interrupts, timer interrupts, external hardware interrupts, serial communication interrupts and the interrupts priority”. Objectives. Contra and compare interrupts versus pooling Explain the purpose of the ISR

trentv
Download Presentation

PIC18 Interrupt Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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) 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 Timer Interrupt Flag Bits and Associated Registers INTCON Register with Timer0 Interrupt Enable and Interrupt Flag

  10. Program 11-1 (pg 430) 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 T0_ISR ORG 200H MOVLW 0xFF MOVWF TMR0H MOVLW 0xF2 MOVWF TMR0L BTG PORTB,5 BCF INTCON,TMR0IF RETFIE END Timer0 Interrupt

  11. Revisit

  12. Please see Program 11-2 (pg 432) and Program 11-3 (pg 433)

  13. External Hardware Interrupts Hardware Interrupt Flag Bits and Associated Registers Positive-edge-triggered interrupt PIC18 External Hardware Interrupt Pins

  14. Program 11-4 (pg 440) ORG 0000H GOTO MAIN ORG 0008H BTFSS INTCON,INT0IF RETFIE GOTO T0_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 T0_ISR ORG 200H BTG PORTB,7 BCF INTCON,INT0IF RETFIE END BCF INTCON2,INTEDG1 Hardware Interrupt Negative-edge-trigerred

  15. Please see Program 11-5 (pg 442)

  16. Serial Communication Interrupts Serial Port Interrupt Flag Bits and Associated Registers PIE1 Register Bits Holding TXIE and RCIE

  17. Program 11-6 (pg 446) ORG 0000H GOTO MAIN ORG 0008H BTFSC PIR1,TXIF BRA TX_ISR 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 ORG 0040H TX_ISR MOVWFF PORTD,TXREG RETFIE Enable peripheral Interrupt

  18. Please see Program 11-7 (pg 446)

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

  20. Differences Between External Hardware and PORTB-Change Interrupt

  21. Please see Program 11-8 (pg 451) and Program 11-9 (pg 452)

  22. Interrupt Priority

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

  24. IPR1 Peripheral Interrupt Priority Register

  25. Please see Program 11-10 (pg 459) and Program 11-11 (pg 460)

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

More Related