-
Home
- Microcontroller and embedded
- Labs
- Lab 5 - interrupts
- Lab 5: interrupts
Lab 5 will discuss what interrupts are for and how to fire them.
Seven segment counter
Write a function,
void seg_count(int num)
, similar to the LED counting function,
led_num()
, from
Lab 4 . In this case, the function will display a number between 0 and 15 on the seven-segment display in hex.
The pin-outs for the blue
MSP430F16x Lite Development Board are configurable through a programmable PLD. This allows the user to change the pin map in software. You can see the current arrangement of the pins here:
LiteBoardPinout
Using the
seg_count()
function you just wrote. Write a program that does the following:
- Poll for button_1 being pushed. Begin counting up slowly on the seven-segment display. It must be slow enough that it can be human readable. Counting will pause if button_1 is pushed again.
- Poll for button_2 being pushed. If it is pushed, begin counting in the opposite direction. Initially, the counter will go up from 0 to F.
- If the counter is going up and it reaches its maximum value, it will roll over to zero and continue counting. If it is counting down it will roll over to its maximum value.
- Be sure to include all appropriate header files, disable the Watchdog Timer, and initialize the master clock.
Got questions? Get instant answers now!
Firing an interrupt
Interrupts, as the name implies, will interrupt a program whenever it is, and when the interrupt is done being serviced it will jump back to wherever it was in the program. This allows the programmer to have more freedom in their code, automates certain functions, and reduces the number of checks handled by the processor.
In order to fire an interrupt, the following must be done:
- All interrupts on the processor are disabled by default and must be first enabled globally.
- Next, each specific interrupts must be enabled.
- Finally, for each enabled interrupt, an interrupt service routine (ISR), the interrupt handler, must be written. Once an interrupt fires, the program will jump to this section of the program.
A typical program using interrupts will look like the following piece of code:
void main(void){
_EINT(); //Enables interrupts globally
//... more code
}
void SOME_interrupt (void) __interrupt[SOME_vector]{
//...more code that runs once interrupt fires
return;
}
Processors are designed to be able to service interrupts from predefined, specific places. The list of possible interrupts is put into an interrupt vector, and each must be enabled individually. To find the name of the interrupt vector that needs to be enabled, check the
MSP430Fx16x.h header file's
Interrupt Vectors
section.
Write an interrupt that will fire when the buttons are pushed. If you need additional help, there are examples in the
../Crossworks MSP430 1.x/samples/
directory.
Modify the program from
Problem 1 so that it is interrupt based and does not poll for the buttons being pushed. How does your program behavior changes? When would you want to use polling over using an interrupt?
Got questions? Get instant answers now!
Questions & Answers
calculate molarity of NaOH solution when 25.0ml of NaOH titrated with 27.2ml of 0.2m H2SO4
the study of the heat energy which is associated with chemical reactions
Kaddija
How was CH4 and o2 was able to produce (Co2)and (H2o
First twenty elements with their valences
what is the best way to define periodic table for jamb
what is the change of matter from one state to another
what is isolation of organic compounds
Read Chapter 6, section 5
Dr
Read Chapter 6, section 5
Kareem
Atomic radius is the radius of the atom and is also called the orbital radius
Kareem
atomic radius is the distance between the nucleus of an atom and its valence shell
Amos
Read Chapter 6, section 5
paulino
Bohr's model of the theory atom
when a gas is compressed why it becomes hot?
ATOMIC
It has no oxygen then
Goldyei
read the chapter on thermochemistry...the sections on "PV" work and the First Law of Thermodynamics should help..
Dr
Which element react with water
an increase in the pressure of a gas results in the decrease of its
definition of the periodic table
what were atoms composed of?
Got questions? Join the online conversation and get instant answers!
Source:
OpenStax, Microcontroller and embedded systems laboratory. OpenStax CNX. Feb 11, 2006 Download for free at http://cnx.org/content/col10215/1.29
Google Play and the Google Play logo are trademarks of Google Inc.