Interrupts in C Programs

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)
Slides created by: Professor Ian G. Harris PIC Development Environment MPLAB IDE integrates all of the tools that we will use 1.Project Manager -Groups.
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
68HC11 Polling and Interrupts
Bitwise Operators Pointers Functions Structs Interrupts (in C)
C and Assembler Subroutines: Using the LCD. Outline Basic structure of CW-created C programs for the HC12 How to incorporate assembly code How to use.
C Language Programming. C has gradually replaced assembly language in many embedded applications. Data types –C has five basic data types: void, char,
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.
Infineon Technologies Corp. June 99 1 HOT167-1 Version 2.0 * C167CS not yet supported by DAvE V1.0 CD ROM. See “Hints regarding DAvE.” Exercise 7ASC_1.
NetBurner 5282 MCF5282 ColdFire MicroController Interrupt System.
Communication Lab - Interrupts 1/13 Sequential Programming  Our C++ programs are sequential ( סדרתיים), they start at the first instruction and end at.
Butterfly I/O Ports CS-212 Dick Steflik. I/O for our labs To get data into and out of our Butterfly its a little trickier than using printf and scanf.
NetBurner 5282 MCF5282 ColdFire MicroController Interrupt System.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
Using PDG with e2studio: Example
1 COSC 3P92 Cosc 3P92 Week 11 Lecture slides Violence is the last refuge of the incompetent. Isaac Asimov, Salvor Hardin in "Foundation"
Embedded ‘C’.  It is a ‘mid-level’, with ‘high-level’ features (such as support for functions and modules), and ‘low-level’ features (such as good access.
ECE 265 – LECTURE 12 The Hardware Interface 8/22/ ECE265.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
Embedded Systems Programming 1 ETEE 3285 Topic HW3: Coding, Compiling, Simulating.
RM2D Let’s write our FIRST basic SPIN program!. The Labs that follow in this Module are designed to teach the following; Turn an LED on – assigning I/O.
MICROPROCESSOR INPUT/OUTPUT
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
The miniDragon+ Board and CodeWarrior Lecture L2.1.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
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)
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
CS1372: HELPING TO PUT THE COMPUTING IN ECE CS1372 Some Basics.
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.
LHO 22 C and the  The Silicon Labs ISE uses the Keil C51 compiler.  The code size is limiter to 2K  C has replaced PL/M (the original Intel high.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Configuring CodeWarrior V5.1 for the HCS12.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
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.
Microprocessors A practical approach..
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Mixing C and ASM Programs
Chapter 3 General-Purpose Processors: Software
Lecture 8: TI MSP430 Interrupts, ISRs
ECE 3430 – Intro to Microcomputer Systems
Example 14 Real-time Interrupts
Lesson Outline Interrupts Admin Assignment #9 due next lesson
68HC11 Interrupts & Resets.
Fri. Sept 29 Announcements
Homework Reading Machine Projects Labs
Microprocessor Systems Design I
UNIT – Microcontroller.
Example 19 Measuring Pulse Widths Using Interrupts
ECET 330 Innovative Education--snaptutorial.com
8051 Programming in C rhussin.
Example 6 Hex Keypad Lecture L3.2.
Example 15 Interrupt-Driven Controller
Transmitter Interrupts
Lecture 9: TI MSP430 Interrupts & Low Power Modes
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Founded in Silicon Valley in 1984
Example 18 Pulse Train Using Interrupts
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 3567 Microcontrollers Lab
Presentation transcript:

Interrupts in C Programs Main Points to Remember: 1. The interrupt vector is set by the linker through the use of the Linker Parameter (.PRM) file. 2. The keyword “interrupt” must precede each of the interrupt routine declarations. 11/27/2018 Interrupts in C Programs

Setting up a new CodeWarrior C project The following example implements a simple system that responds to a falling edge IRQ interrupt that is produced by a bounceless pushbutton connected to the PE1/IRQ input pin (Pin 2) of our CSMB12C128 module. In response to this falling edge, and LED (on PT1) is toggled and a counter (on Port M) is incremented. 11/27/2018 Interrupts in C Programs

Interrupts in C Programs Complete Example of a C program that incorporates an interrupt service routine First open CodeWarrior, and click File – New – HC(S)12 New Project Wizard Enter Project name and desired path Click OK and Next Enter MC9S12C128 and Next Check C and uncheck Assembly and Next Check NO to Processor Expert and Next 11/27/2018 Interrupts in C Programs

Interrupts in C Programs Check NO PC-lint and Next Check ANSI startup code and Next Check None for floating point and Next Check Small for memory model Check both “Full-Chip Simulation” and also “P&E Multilink/Cyclone Pro” and Finish Once the “C” project is created, click on “PRM”. Then select (double left click on) the “P&E Multilink/Cyclone Pro” Linker Parameter file. 11/27/2018 Interrupts in C Programs

Now add the desired interrupt vector initialization to the .PRM file In our case we want the function we shall call IRQISR to be entered when an IRQ interrupt occurs, which is Vector 6. Therefore, add the following line to the end of the .PRM file: VECTOR 6 IRQISR Note: Vector 6 is the IRQ vector, initialize it with address of IRQISR 11/27/2018 Interrupts in C Programs

Copy the following program into the main.c function //Example of using C with interrupts //Bounceless SW connected to Pin 2 (PE1/IRQ input) //LED connected to PT1 //Interrupt count set up on Port A. //Interrupt vector for IRQ is initialized to // point to the IRQISR routine at the end of // the .PRM file. #include <hidef.h> /* common defines and macros */ #include <mc9s12c128.h> /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12c128" void IRQISR(void); unsigned char cnt; /* This is global variable is used for communicating between main program and ISR, so it MUST be defined outside of the main program */ void main(void) { DDRA = 0xFF; cnt = 0; PORTA = 0; DDRT = 0x02; /* configure PT1 pin for output */ PTT = 0x02; /* enable LEDs to light */ INTCR = 0xC0; /* enable IRQ (PE1/IRQ, Pin2) interrupt on falling edge */ asm("cli"); /* enable interrupt globally */ /* Alternately you could invoke “EnableInterrupts;” */ while(1); /* wait for interrupt forever */ } 11/27/2018 Interrupts in C Programs

Interrupts in C Programs interrupt void IRQISR(void) { cnt++; PORTA= cnt; //Increment count on Port A PTT = ~PTT; // Toggle LED on PT1 //Since IRQ input is made edge sensitive, //The IRQ interrupt is automatically //relaxed after the interrupt routine is //entered, so there is no need to "shut the //baby up" as with most other"I-bit related" //interrupts. Upon return from IRQISR, the //interrupt is already inactive. } 11/27/2018 Interrupts in C Programs

Configuring PE1/IRQ pin for interrupt input Note that the INTCR (interrupt control register) must be set to $C0 in order to configure pin PE1 as a “falling edge” sensitive IRQ input pin instead of a PORT E digital I/O pin. 11/27/2018 Interrupts in C Programs

INTCR Register (From 9S12C128DGV1.PDF Design Guide Document) 11/27/2018 Interrupts in C Programs

Denoting Interrupt Routines in C Note how the interrupt routine begins with the keyword “interrupt”. It must also be given a name, so that the interrupt vector can be initialized using the name of the interrupt routine. Use of this keyword ensures that the routine will end with an RTI instead of just an RTS. There should be as many interrupt routines defined in this way as you have interrupt sources. 11/27/2018 Interrupts in C Programs

Interrupts in C Programs This program will be interrupted to increment PORT A and then toggle the LED on PT1 with each falling edge on PE1/IRQ pin! 11/27/2018 Interrupts in C Programs