Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.

Similar presentations


Presentation on theme: "Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical."— Presentation transcript:

1 Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department بسم الله الرحمن الرحيم EELE 4315 Fall 2010 Lecture 12

2 An Interrupt Review An Interrupt is an external input to the CPU. The interrupt facility allows the processor to respond rapidly to external changes. When an Interrupt is detected by the CPU, it: - completes the current instruction, - stores the address of the next instruction onto the stack, and possibly other key variables (e.g. contents of Work and Status Register) into (stack or GPR), - jumps to an interrupt service routine (ISR), whose address is determined by an "interrupt vector". Interrupt

3 Many interrupts can be masked, ie disabled, by setting a bit in a control register. In some processors however (but not PIC), some interrupts are non- maskable. If an Interrupt is masked, then there is a possibility that it will not be detected. Therefore there are also Interrupt Flags, bits in SFRs, which are set whenever an associated interrupt occurs. These record the fact that an interrupt has occurred, even if the CPU is unable to respond to it. An Interrupt that has occurred, but has not received CPU response, is called a Pending Interrupt. In the case of several interrupts, one ISR is completed before the next interrupt is responded to. Interrupt

4 The Reset Vector Interrupt Routine always starts here Microcontroller Interaction with Peripherals, via SFR and Interrupt Interfacing with Peripherals Recalling Interrupt-Related Points that have already Come up Interrupt

5 Sources of interrupt: In the PIC16F84A, there are four source of interrupt: 1. External interrupt from RB0/INT pin of microcontroller 2. Interrupt during alteration on RB4, RB5, RB6 and RB7 pins of port B. 3. TMR0 interrupt caused by timer overflow. 4.Termination of writing data to EEPROM. Interrupt

6 Registers used with interrupt: 1.Control interrupt register (INTCON) at 0Bh address. 2. Option register at 81h address. 3. Control EEPROM register (EECON 1) at 88h address. The most important register is (INTCON). Interrupt

7 We can use the bits of INTCON register to make interrupt as follow: 1) First we set GIE bit which must be enabled for any interrupt. 2) Second we enable one of this bits( T0IE,EEIE, RBIE,INTE) as we like to use the interrupt: If we use external interrupt, we set INTE to 1. If we use RB interrupt, we set RBIE to 1. If we use TMR0 interrupt, we set T0IE to 1. If we use EEPROM interrupt, we set EEIE 1. 3) When interrupt occurred, the one of flag bits (INTF, RBIF, TOIF) is set physically so it must be cleared in software. Interrupt

8 The PIC 16F84A INTCON Register Interrupt

9 The PIC 16F84A OPTION Register Interrupt

10

11 The PIC 16F84A Interrupt Structure Global Interrupt Enable External Interrupt EEPROM Write Complete Port B Change Timer Overflow Interrupt Flag External Interrupt input Note that the interrupt flags are set by the interrupt action, but must be cleared in the program, during the ISR. What happens if this isnt done? Interrupt

12 A Generic Interrupt Structure Interrupt

13

14 The PIC 16 Series Interrupt Response Note that this diagram shows what the PIC microcontroller itself does as an interrupt occurs. The programmer need not worry about any of these actions, but needs to know that theyre happening. Interrupt

15

16

17 The step of push and pop is performed because the contents of the most important registers may change during the interrupt. The most important registers we must keep is the work register and status register and this is done by storing the work and the status registers. After writing the main body of the interrupt and we can restore the status register then restore the W register Interrupt

18 Procedure of recording important registers before going to an interrupt routine is called PUSH, while the procedure which brings recorded values back, is called POP. PUSH and POP are instructions with some other microcontrollers (Intel), but are so widely accepted that a whole operation is named after them. PIC16F84 does not have instructions like PUSH and POP, and they have to be programmed. Interrupt

19 The contents of W and STATUS registers are stored in W_TEMP and STATUS_TEMP variables (two registers in GPR). For exchange of data between these registers, SWAPF instruction is used instead of MOVF because it does not affect the status of STATUS register bits. Interrupt

20 Example is a program assembler for following steps: 1.Storing W register in GPR. 2. Storing STATUS register in GPR. 4. Executing interrupt routine for interrupt processing (ISR) 5. Restores STATUS register 6. Restores W register Interrupt

21 Flasher on D1 using delay Toggle on D2 using int0

22 Interrupt

23

24 Return from interrupt routine can be accomplished with instructions RETURN, RETLW and RETFIE. When interrupt was answered, GIE bit was cleared so that any additional interrupts would be disabled, It is recommended that instruction RETFIE be used because that instruction is the only one which automatically sets the GIE bit which allows new interrupts to occur.

25 H.W Deadline (4/11) 1- using external interrupt INT0 to implement a counter to counts from 0000 to 1111 at falling edge input 2- using external interrupt INT0 to implement a counter to counts from 1111 to 0000 at rising edge input 3- using external INT0 to toggle the flash from 4 leds in portA to a 4 leds in portB 4- using interrupt technique with tmr0 to implement 1.5sec delay 5- using interrupt technique with tmr0 to implement 15 u sec delay 6- using interrupt technique with tmr0 to implement 15 m sec delay


Download ppt "Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical."

Similar presentations


Ads by Google