How To Write C ISRs

How To Write C ISRs - P2IFG&= ~0x0f P2.0-3 IFG cleared...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
How To Write C ISRs. .. A C Interrupt Service Routine (ISR) is created using a pre-processor #pragma vector= directive. (See msp430x22x4.h for specific vector names.) Before a device will interrupt, it has to be enabled plus the GIE status register bit must be set. Here is an example of how the switches on the eZ430X development board can be configured to interrupt on Port 2: void port2_init(void) { // configure P2 switches for interrupt P2SEL = 0; // select GPIO P2DIR = 0xd0; // Configure P2.0-3 as Inputs P2OUT = 0x0f; // use pull-ups P2IES = 0x0f; // high to low transition P2REN = 0x0f; // Enable pull-ups P2IE |= 0x0f; // P2.0-3 interrupt enabled
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: P2IFG &= ~0x0f; // P2.0-3 IFG cleared return; } Here is an example of a Port 2 interrupt routine that returns an event signal ( sys_event ) when a switch is pressed. The ISR will also exit low-power 0 when it returns. (Note: P2IE must be again enabled before the pressed switch can interrupt again.) //------------------------------------------------------------------------------ // Port 2 interrupt service routine #pragma vector=PORT2_VECTOR __interrupt void Port_2(void) { sys_event |= (P2IN ^ 0x0f) & 0x0f; P2IE &= ~(sys_event & 0x0f); __bic_SR_register_on_exit(LPM0_bits); // Clear CPUOFF bit from 0(SR) }...
View Full Document

This document was uploaded on 02/08/2012.

Ask a homework question - tutors are online