{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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 first to see whether an intrinsic function is available to do the job without leaving C. Many of these are declared in the header file intrinsics.h to perform functions that are not possible in standard C. For 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 defined 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 file 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 www.newnespress.com
Background image of page 1

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

View Full Document Right 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 superficially like a function but there are a few crucial modifications. 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.

{[ snackBarMessage ]}