How To Write C ISRs

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

Info icon This 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
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern