MSP430_Microcontroller_Basics_Chapter 6.6-9

MSP430_Microcontroller_Basics_Chapter 6.6-9 - 186 Chapter 6...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
186 Chapter 6 Check frst to see whether an intrinsic Function is available to do the job without leaving C. Many oF these are declared in the header fle intrinsics.h to perForm Functions that are not possible in standard C. ±or example, the _ _swap_bytes() intrinsic Function calls the swpb instruction. Another possibility, when only a line or two oF assembly language is needed, is to use inline assembly. This looks like a Function asm() whose argument is the line(s) oF assembly code, such as asm("mov.b &P1IN,&dest") . There are some dangers with this approach, set out in the compiler reFerence guide. The third method is to write a complete subroutine in assembly language and call it From C. Obviously it is essential to get the calling convention correct. This is defned in the reFerence guides but there is an easier way. Write as much oF the subroutine as possible in C and compile it. Copy the resulting assembly code and use it as the shell oF your subroutine. This can be done From the disassembly window in the Kickstart version oF EW430; you have to pay to get a real output fle with the assembly code. Do not change the level oF optimization aFterward because this may change the code that calls the subroutine. An example will be given in “Conversion From Binary to BCD in Assembly Language” on page 272. 6.6 Interrupts Interrupts were introduced in the section “Exceptions: Interrupts and Resets” on page 36. They are like Functions but with the critical distinction that they are requested by hardware at unpredictable times rather than called by soFtware in an orderly manner. (Well, a periodic interrupt should be highly predictable in real time, but this is not apparent to the CPU.) Interrupts are commonly used For a range oF applications: Urgent tasks that must be executed promptly at higher priority than the main code. However, it is even Faster to execute a task directly by hardware iF this is possible. InFrequent tasks, such as handling slow input From humans. This saves the overhead oF regular polling. Waking the CPU From sleep. This is particularly important in the MSP430, which typically spends much oF its time in a low-power mode and can be awakened only by an interrupt. Calls to an operating system. These are oFten processed through a trap or soFtware interrupt instruction but the MSP430 does not have one. A substitute is For
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Functions, Interrupts, and Low-Power Modes 187 software to set an unused interrupt flag for one of the peripherals, such as port P1 or P2. The code to handle an interrupt is called an interrupt handler or interrupt service routine (ISR). It looks superFcially like a function but there are a few crucial modiFcations. The feature that interrupts arise at unpredictable times means that an ISR must carry out its action and clean up thoroughly so that the main code can be resumed without error—it should not be able to tell that an interrupt occurred.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/06/2012.

Page1 / 13

MSP430_Microcontroller_Basics_Chapter 6.6-9 - 186 Chapter 6...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online