ECE 371 – Unit 9 Interrupts (continued). Example Set up Two Interrupt Request Inputs: –Port H[0] Set Interrupt Flag on “0” to “1” transition (rising edge)

Slides:



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

Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
10-1 EE 319K Introduction to Microcontrollers Lecture 10: Interrupts, Output Compare Periodic Interrupts Read Book Sections 9.1, 9.2, 9.4, 9.6.1, 9.6.2,
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
EET 2261 Unit 9 Interrupts  Read Almy, Chapters 17 – 19.  Homework #9 and Lab #9 due next week.  Quiz next week.
Bitwise Operators Pointers Functions Structs Interrupts (in C)
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
C Programming for Embedded Systems. fig_06_00 Computer Layers Low-level hardware to high-level software (4GL: “domain-specific”, report-driven, e.g.)
Dr. Amr Talaat. #include ; /* this makes the header file for the PIC16f877 ready to be used in the C-class */ #define LED PORTC ; /* defines.
Chapter 12 Capturing Input. Di Jasio - Programming 32-bit Microcontrollers in C Button Inputs.
ECE 265 – LECTURE 12 The Hardware Interface 8/22/ ECE265.
UNIT 8 Keypad Interface Contact Closure Counter Exceptions (Interrupts and Reset)
Ch. 9 Interrupt Programming and Real-Time Sysstems From Valvano’s Introduction to Embedded Systems.
ECE 371- Unit 11 Timers and Counters (“Stop Watches and Alarm Clocks”)
Unit 10.2 Timer Examples. Example – Music Generation Channel 6 – Set up as a timer Output to Generate Square Waves Channel 4 – Set up as a timer Output.
Revised: Aug 1, ECE 263 Embedded System Design Lessons 23, 24 - Exceptions - Resets and Interrupts.
Lecture 11: TI MSP430 Timers Compare Modes
Microprocessors 1 MCS-51 Interrupts.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Code The Arduino Environment.
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
6-1 Infineon 167 Interrupts The C167CS provides 56 separate interrupt sources that may be assigned to 16 priority levels. The C167CS uses a vectored interrupt.
ECE 447 Fall 2009 Lecture 7: MSP430 Polling and Interrupts.
Input Interface – Microprocessor
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.
Real Time Interrupts Section Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts.
Chapter 5 - Interrupts.
CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
UNIT 7 - INTRODUCTION TO I/O INTERFACING. TWO MAJOR TYPES OF I/O INTERFACING ISOLATED I/O - DEDICATED I/O INSTRUCTIONS ARE USED TO ACCESS I/O DEVICES.
Lecture 4 General-Purpose Input/Output NCHUEE 720A Lab Prof. Jichiang Tsai.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
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.
Examples Lecture L2.2. // Example 1a: Turn on every other segment on 7-seg display #include /* common defines and macros */ #include /* derivative.
GUIDED BY PROFFESOR NILESH DESAI GROUP NO:-8 CHANDRASHIKHA SINGH( ) KURUP SHUBHAM VALSALAN( ) SAURAV SHUBHAM( )
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
HCS12 Technical Training Module 6 – Port Integration, Slide 1 MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
An Introduction to Embedded Systems, and the PIC Microcontroller Lecture 8: Interrupts The aims of this session are to explore the structure and application.
Lecture 8: TI MSP430 Interrupts, ISRs
Microprocessor and Assembly Language
Lesson Outline Interrupts Admin Assignment #9 due next lesson
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Protection of System Resources
Interrupts In 8085 and 8086.
ECE 3430 – Intro to Microcomputer Systems
The slides must be understood in Lecture 5
Keypad Source: under under
Interrupts in C Programs
Port Integration Module
Transmitter Interrupts
Lecture 9: TI MSP430 Interrupts & Low Power Modes
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Keypad Source: under under
Keypad Source: under under
Fundamental Programming
COMP3221: Microprocessors and Embedded Systems
The Programmable Peripheral Interface (8255A)
Presentation transcript:

ECE 371 – Unit 9 Interrupts (continued)

Example Set up Two Interrupt Request Inputs: –Port H[0] Set Interrupt Flag on “0” to “1” transition (rising edge) Port H[1] Set Interrupt Flag on “1” to “0” transition (trailing edge)

Example (cont) Response to Interrupts: Toggle H[4] on each H[0] Interrupt Toggle H[5] on each H[1] Interrupt

#include ece371.h /* Port H Port Definitions */ #define PTH _P( 0x260) #define PTIH _P( 0x261) #define DDRH _P( 0x262) #define RDRH _P( 0x263) #define PERH _P( 0x264) #define PPSH _P( 0x265) #define PIEH _P( 0x266) #define PIFH _P( 0x267) Example – Port H Interrupt

Interrupt Service Routine Setting up (declaring) “myisr” as in Interrupt Service Routine: void myisr() __attribute__ ((interrupt)); //should be at the //beginning of source file /* 2 underscores before and after attribute */ /* Do not use #pragma, which is used in the text To establish in Interrupt Service Routine*/

#include void myisr() __attribute__ ((interrupt)); int main() {/* stack is initialized by c */ /* initialize interrupt vector for Port H */ SETVECT(0xFFCC,my_isr); /* init Data Direction Bits for Port H Bits 0 and 1 are Input Bits 4 and 5 are Output Other Bits assigned to other applications /* DDRH = DDRH & 0xFC; // Bit 0 and 1 are Input DDRH = DDRH | 0x30; // Bit 4 and 5 are output Example – Main Program

/* Set Bit 4 and 5 to full drive outputs */ RDRH = RDRH & 0xCF; // /* Enable Bit 0 and 1 Pull Device on Input */ PERH = PERH | 0x03; // Enable Bit 0 and 1 Pull Device PPSH = (PPSH & 0xFC) | 0x01; // Bit 0 Rise, Bit 1 Fall /* Clear Pending Port H Bit 0 and 1 Interrupts */ PIFH = 0x03; /* Enable Bit 0 and 1 to Interrupt */ PIEH = PIEH | 0x03; // Enable Interrupts /* Enable Maskable Interrupt System */ ENABLE(); /* do main program processing */ while(TRUE); // loop }

void my_isr(void) { if ((PIFH&0x2)!=0) {//Bit 1 was source of interrupt PIFH = 0x02; // Clear Interrupt // Do interrupt specific action, complement Bit 5 PTH = PTH ^ 0x20; } if ((PIFH&0x01)!=0) {//Bit 0 was source of interrupt PIFH = 0x01; // Clear Interrupt // Do interrupt specific action, complement Bit 4 PTH = PTH ^ 0x10; } Example Interrupt Handler

Use Each Bit of Port H as an Interrupt Request Input Count the Running Total of Interrupt Request that Occur on Each of the 8 Request Inputs Another Example: 8-Switch Counter Implemented Using Interrupts

#include void myisr() __attribute__ ((interrupt)); /* Port H definitions go here */ int count[8]=0,0,0,0,0,0,0,0; // global int main() {/* stack is initialized by c */ /* initialize interrupt vector for Port H */ SETVECT(0xFFCC,my_isr); /* Init Data Direction Bits for Port H All bits are input /* DDRH = 0x00; Another Example: (cont)

/* Enable Pull Devices on Port H all bits */ PERH = 0xFF; /* Interrupt on “1” to “0” Transitions all bits PPSH = 0x00; /* Clear Pending Port H Interrupts all bits */ PIFH = 0xFF; /* Enable all Port H bits to Interrupt */ PIEH = 0xFF; // Enable Interrupts /* Enable Maskable Interrupt System */ ENABLE(); /* do main program processing */ while(TRUE); // loop }

void my_isr(void) { int i; for(i=0;i<8;i++) {if ((PIFH & (1<<i))!=0) {//Bit i was source of interrupt PIFH = (1<<i); // Clear Interrupt // Do interrupt specific action count[i]++; } Method 1 for Implementing Interrupt Service Routine

void my_isr(void) { int i; unsigned char change; change = PIFH; // change bitsw PIFH = change; // Clear interrupt flag for(i=0, i<8, i++) if(((change>>i)&0x01)!=0) {count[i]++;} } Method 2 for Implementing Interrupt Service Routine

Still Another Example: Interfacing a Keypad (Fig. 5.5) Using Interrupts Use Port H

Keypad with Interrupts Port H[3:0] –Output –Full Drive –Set Bits to “0” (all at once) Port H[7:4] –Input –Interrupt on “1” to “0” (Key Pressed)

Cflag!=0 ? c=cin; cflag=0; Function “ci” to Read Keypad Scan Keypad cin=keypad character cflag=1; Interrupt Main –ISR Communication Shared Variables ==0 !=0 Intr. Service Routine

Passing Parameters Between Main Program and Interrupt Service Routine unsigned char cin, cflag=0; /*global variables declared outside Interrupt Service Routine and all functions/* //function to read keyboard: unsigned char ci(void) { while(cflag == 0); cflag=0; return cin;}

Main Program – Receiving Character from ISR Int main() { unsigned char c; PTH=0; // select all rows ENABLE(); // enable all interrupts ---- c=ci(); // input character from keypad //function ci defined on previous slide ---- }

Tasks for Keypad ISR On a Port H Interrupt: –Clear Interrupt Flag Register with Write –Scan Keypad for Pressed Key –cin=key; cflag=1: –Set Port H outputs to “0

void kbisr() //define ISR {unsigned char mask[4]=0x0E,0x0D,0x0B,0x07;int i,j; //1110, 1101, 1011, 0111 PIFH = PIFH; // clear interrupt request for(i=0;i<4;i++) {PTH = mask[i]; // assert row in keypad for(j=0;j<4;j++) {if((PTH>>4) == mask[j]) {if (((i<<2)+j)<10) {cin = ‘0’+(i<<2)+j;cflag=1;} else cin=‘A’+(i<<2)+j -10;cflag=1;} } PTH = 0x00; // select all rows } Keypad ISR void kbisr() __attribute__ ((interrupt)); //Establish kbisr as ISR