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.

Slides:



Advertisements
Similar presentations
Interrupts How to do 2 things at the same time. Need for interrupts Computers often have to deal with asynchronous events. That is to say events that.
Advertisements

Working with time: interrupts, counters and timers Chapter Six Dr. Gheith Abandah1.
Electronics Design Lab TUTORIAL PIC Microcontrollers Francesco Tenore 2/10/2006.
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.
Starting with serial Chapter Ten 10.1, 10.2,
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.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
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.
CoE3DJ4 Digital Systems Design Chapter 6: Interrupts.
Directives, Memory, and Stack. Directives Special commands to the assembler May or may not generate machine code Categories by their function Programming.
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.
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.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
Dec Hex Bin 14 E ORG ; FOURTEEN Interrupts In x86 PC.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
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.
Features of the PIC18 microcontroller - 8-bit CPU - 2 MB program memory space (internal 32KB to 128KB) bytes to 1KB of data EEPROM - Up to 4096 bytes.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
Working with Time: Interrupts, Counters and Timers
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.
Lecture – 8 Interrupt 1. Outline Introduction Handling interrupt Interrupt sources Switching interrupt Peripheral interrupts Using two interrupts Conclusions.
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
Microprocessor Systems Design I
Chapter 10 PIC18 Serial Port Programming in Assembly
Microprocessor Systems Design I
UNIT – Microcontroller.
Interrupts In 8085 and 8086.
Microprocessor Systems Design I
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
EE Embedded Systems Fall 2015
* * * * * * * 8051 Interrupts Programming.
USART Universal Synchronous Asynchronous Receiver Transmitter
Interrupt Source: under
PIC18 Timer Programming “Explain the assembly language programming for the timer and counter module”
Interrupt.
EECE.3170 Microprocessor Systems Design I
Interrupt Source: under
EECE.3170 Microprocessor Systems Design I
PIC18 Interrupt Programming
PIC Serial Port Interfacing
Figure Simplified View of Interrupts (default for power-on reset)
PIC Serial Port Interfacing
PIC18 Interrupt Programming
Presentation transcript:

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

The PIC uCs Chapter 11: Interrupts programming in Assembly PIC Microcontroller and Embedded Systems Muhammad Ali Mazidi, Rolin McKinlay and Danny Causey, February

The PIC uCs Objective 11-3

The PIC uCs Introduction r Interrupts are mechanisms which enable instant response to events such as counter overflow, pin change, data received, etc. r In normal mode, microcontroller executes the main program as long as there are no occurrences that would cause an interrupt. r 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. 11-4

The PIC uCs 11.1:PIC18 interrupts r PIC can serve multiple devices using mechanisms of m 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. m Interrupt Devices get the attention of the CPU only when it needs a service Can service many devices with different level of priorities 11-5

The PIC uCs Interrupt service routine (ISR) r When an interrupt is invoked the uC runs the Interrupt Service Routine(ISR) r Interrupt vector table holds the address of ISRs m Power-on Reset 0000h m High priority interrupt 0008h m Low priority interrupt 0018h 11-6

The PIC uCs Steps in executing an interrupt r Upon activation of interrupt the microcontroller m Finishes executing the current instruction m Pushes the PC of next instruction in the stack m Jumps to the interrupt vector table to get the address of ISR and jumps to it m Begin executing the ISR instructions to the last instruction of ISR (RETFIE) m Executes RETFIE Pops the PC from the stack Starts to execute from the address of that PC 11-7

The PIC uCs Program organization in MPLAB 11-8

The PIC uCs Sources of interrupts in PIC18 r External hardware interrupts m Pins RB0(INT0),RB1(INT1),RB2(INT2) r PORTB change r Timers m Timer0, Timer1,Timer2 r ADC (analog to digital converter) r CCP (compare capture pulse width modulation, PWM) r... etc 11-9

The PIC uCs Enabling and disabling an interrupt r When the PIC is powered on (or resets) m All interrupts are masked (disabled) m The default ISR address is 0008h No interrupt priorities for interrupts 11-10

The PIC uCs Enabling and disabling an interrupt r In general, interrupt sources have three bits to control their operation. They are: r Flag bit m to indicate that an interrupt event occurred r Enable bit m that allows program execution to branch to the interrupt vector address when the flag bit is set r Priority bit m to select high priority or low priority 11-11

The PIC uCs Steps in enabling an interrupt r Set the GIE bit from INTCON REG r Set the IE bit for that interrupt r If the interrupt is one of the peripheral (timers 1,2, serial,etc ) set PEIE bit from INTCON reg 11-12

The PIC uCs Example 11.1 a) BSF INTCON,TMR0IE BSF INTCON,INT0IE BSF INTCON,GIE Or MOVLW B’ ’ MOVWF INTCON b) BCF INTCON,TMR0IE c) BCF INTCON,GIE 11-13

The PIC uCs Program 11-4 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 OVER MOVFF PORTC,PORTD BRA OVER INT0_ISR ORG 200H BTG PORTB,7 BCF INTCON,INT0IF RETFIE END 11-14

The PIC uCs Program 11-5 negative 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 OVER BRA OVER BRA OVER INT1_ISR ORG 200H BTG PORTB,7 BCF INTCON3,INT1IF RETFIE END 11-15

The PIC uCs Sampling the Edge triggered interrupt r The external source must be held high for at least two instruction cycles r For XTAL 10Mhz r Instruction cycle time is 400ns,0.4us r So minimum pulse duration to detect edge triggered interrupts = 2 instruction cycle = r 0.8us 11-16

The PIC uCs11-17

The PIC uCs 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 Figure PIC18 Program ROM Space Powering UP

Intcon global interupt enable INT pin interrupt TMR0 overflow interrupt GP port change interrupt INT pin interrupt TMR0 overflow interrupt FLAGS ENABLES

The PIC uCs Timer Interrupts InterruptFlag BitRegisterEnable Bit Register Timer0TMR0IFINTCONTMR0IEINTCON Timer1TMR1IFPIR1TMR1IEPIE1 Timer2TMR2IFPIR1TMR3IEPIE1 Timer3TMR3IFPIR3TMR3IEPIE2 Timer Interrupt Flag Bits and Associated Registers INTCON Register with Timer0 Interrupt Enable and Interrupt Flag 11-20

The PIC uCs Timer Interrupts 11-21

The PIC uCs Program 11-1 (pg 430) ORG0000H GOTOMAIN ORG0008H BTFSS INTCON,TMR0IF RETFIE GOTO T0_ISR ORG00100H MAINBCF 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 OVERMOVFF PORTC,PORTD BRA OVER T0_ISR ORG 200H MOVLW 0xFF MOVWF TMR0H MOVLW 0xF2 MOVWF TMR0L BTGPORTB,5 BCF INTCON,TMR0IF RETFIE END Timer0 Interrupt 11-22

The PIC uCs Revisit 11-23

The PIC uCs Please see Program 11-2 (pg 432) and Program 11-3 (pg 433) 11-24

The PIC uCs Serial Communication Interrupts InterruptFlag BitRegisterEnable BitRegister TXIF (Transmit) TXIFPIR1TXIEPIE1 RCIF (Receive) RCIFPIR1RCIEPIE1 Serial Port Interrupt Flag Bits and Associated Registers PIE1 Register Bits Holding TXIE and RCIE 11-25

The PIC uCs Figure 11-13: Serial Interrupt Enable Flags 11-26

The PIC uCs Program 11-6 (pg 446) ORG0000H GOTOMAIN ORG0008H BTFSC PIR1,TXIF BRA TX_ISR RETFIE ORG 0040H TX_ISR MOVWFF PORTD,TXREG RETFIE ORG00100H MAINSETF 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 Enable peripheral Interrupt bit switch is connected to port.D. the PIC18 reads data from PORTD and writes it to TXREG.

The PIC uCs Program 11-7 page 447 ORG0000H GOTOMAIN ORG0008H HI_ISR BTFSC PIR1,TXIF BRATX_ISR BTFSC PIR1,RCIF BRA RC_ISR RETFIE TX_ISR MOVFF PORTD,TXREG GOTO HI_ISR RC_ISR MOVFF RCREG,PORTB GOTO HI_ISR ORG00100H MAINCLRF TRISB SETF TRISD MOVLW 0x20 MOVWF TXSTA MOVLW D'15' MOVWF SPBRG BCF TRISC,TX BSF TRISC,RX MOVLW 0x90 MOVWFRCSTA BSF PIE1,TXIE BSF PIE1,RCIE BSF INTCON,PEIE BSF INTCON,GIE OVER BRA OVER 11-28