PIC18 Interrupt Programming

Slides:



Advertisements
Similar presentations
Working with time: interrupts, counters and timers Chapter Six Dr. Gheith Abandah1.
Advertisements

ECT 357 Ch 18 UART. Today’s Quote: Be careful that your marriage doesn’t become a duel instead of a duet. Be careful that your marriage doesn’t become.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
The PIC uCs PIC Microcontroller and Embedded Systems Muhammad Ali Mazidi, Rolin McKinlay and Danny Causey Eng. Husam Alzaq The Islamic Uni. Of Gaza 9-1.
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
Microcontroller Programming How to make something almost do something else Raffi Krikorian MAS November 2003.
Today’s Lecture List the Timers of PIC18 and their associated registers Describe the various modes of the PIC18 timers Program the PIC18 timers in Assembly.
V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,
CoE3DJ4 Digital Systems Design Chapter 6: Interrupts.
PIC16F877 ISR Points to note Interrupt Triggers –Individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, PEIE.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
Microprocessors 1 MCS-51 Interrupts.
Chapter 7 Larger Systems and the PIC 16F873A The aims of this chapter are to introduce: The architecture of the 16F873A microcontroller; The 16F873A memory.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
EEE237 Introduction to Microprocessors Week x. SFRs.
Teachers Name : Suman Sarker Telecommunication Technology Subject Name : Microcontroller & Embedded System Subject Code : 6871 Semester : 7th Department.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
Working with Time: Interrupts, Counters and Timers
Lecture 3 CSE 341 – Microprocessors Lecture 3 Md. Omar Faruqe UB 1228
Polled IO versus Interrupt Driven IO
Microcontrollers session. What is Microcontroller? Microcontroller is composed of microprocessor,ram, flash memory,EEPROM and some modules like timers,
kashanu.ac.ir Microprocessors Interrupts Lec note 8.
Interrupts ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Interrupts ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
The 8051 Microcontroller Chapter 6 INTERRUPTS. 2/29 Interrupt is the occurrence of a condition an event that causes a temporary suspension of a program.
Aum Amriteswaryai Namah:. SUB ROUTINES Instead of repeating same program segments at all locations, they are written and stored separately; Each such.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
Lecture – 8 Interrupt 1. Outline Introduction Handling interrupt Interrupt sources Switching interrupt Peripheral interrupts Using two interrupts Conclusions.
I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
TIMERS.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Timer modules in PIC 16F877.  The PIC 16F877 basically has three independent timer modules,  denoted by the symbols, TIMER-0, TIMER1,andTIMER2. . These.
An Introduction to Embedded Systems, and the PIC Microcontroller Lecture 8: Interrupts The aims of this session are to explore the structure and application.
Chapter 9 PIC18 Timer Programming in Assembly
Chapter 11 INTERRUPTS PROGRAMMING
Microprocessor Systems Design I
Chapter 10 PIC18 Serial Port Programming in Assembly
Microprocessor Systems Design I
Interrupts In 8085 and 8086.
Microprocessor Systems Design I
Interrupts, Counter and Timers
Microprocessor Systems Design I
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
Interrupt Source: under
Microprocessors Timers
Microprocessor Systems Design I
Introduction to Micro Controllers & Embedded System Design Interrupt
Interrupt.
The PIC uCs PIC Microcontroller and Embedded Systems Muhammad Ali Mazidi, Rolin McKinlay and Danny Causey Eng. Husam Alzaq The Islamic Uni. Of Gaza 11-1.
* * * * * * * 8051 Interrupts Programming.
USART Universal Synchronous Asynchronous Receiver Transmitter
Interrupt.
Serial Communication Interface
Interrupt Source: under
PIC18 Timer Programming “Explain the assembly language programming for the timer and counter module”
Interrupt.
ADC and DAC Data Converter
EECE.3170 Microprocessor Systems Design I
Interrupt Source: under
EECE.3170 Microprocessor Systems Design I
PIC18 Interrupt Programming
PIC Serial Port Interfacing
ADC and DAC Data Converter
Figure Simplified View of Interrupts (default for power-on reset)
PIC Serial Port Interfacing
Timers Chapter 2.
Presentation transcript:

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 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

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

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

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

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

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

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

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

Program 11-1 (pg 430) Timer0 Interrupt 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

Revisit

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

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

Program 11-4 (pg 440) Hardware Interrupt 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

Please see Program 11-5 (pg 442)

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

Program 11-6 (pg 446) Serial Port Interrupt 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

Please see Program 11-7 (pg 446)

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

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

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

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

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

IPR1 Peripheral Interrupt Priority Register

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

“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“

*****Assignment 1) Compare and differentiate the features of the Timer 0, Timer1, and Timer2. 2) Write a program using Timer0 to generate a 1 kHz square wave frequency on PORTB RA5. Assuming XTAL=10kHz 3) Write a program using Timer0 to generate a 1 kHz and a 2 kHz square wave frequency on PORTB RB0 and PORTB RB4 respectively. PORTB RB7 will be used as a switch to select the frequencies. If RB7 = 0, a 1 kHz square wave will be generated and if RB7 = 1, a 2 kHz square wave will be generated.