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.
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?