External interrupt section

msp430 several groups of IO registers, input register (read only), output register, the directional control, multiplex control, in fact, comparison with the STM32, or a much simpler structure. FIG configuration to not remember. .
Up to 16 external interrupts, P1 and P2 port pins can be used for all external interrupt. Edge can only respond to an event, can not produce a level interrupt, of course, this is very sad to call interrupt level, generally do not have access, edge interrupt is also flexible enough to cope with different scenarios. The register is not much need to pay attention, consistent with the 51: Interrupt Enable, select the type (rising or falling), the interrupt flag register. Finally, there is always interrupt enable control bit to pay attention to open.

Read the official three programs.

① first program without interruption, detection of the key in the key loop, to the corresponding LED lamp blinking.
However failure, when in fact just tried Fortunately, try not effective. . . Check with other programs and found lights and buttons like no problem. . . Then try to add image stabilization, anti-shake functions require a delay, Baidu nod of this document is:
__delay_cycles (100);
delay of 100 clock cycles, or not, 1000 10 000 nor orz. . . Forget it

② The second is to make use of interrupt key LED flashes, interrupted only need to configure and IO in the main function, clearing the flag and flip lights in the interrupt function in on it.
P1REN | = BIT4; // the Enable P1.4 Internal resistance
P1OUT | = BIT4; // AS P1.4 pull the Set-Up resistance
two lines of code configuration appeared, read a bit, have not seen this PxREN, check what is the control configuration of the pull-down resistor.
But here again there is no direction 1.4 configuration, in fact, this is an input port, but the configuration of the output register, may be used in conjunction with the corresponding external interrupt input, remember the first usage.
Most big head to the interrupt service routine of writing a little uncomfortable:
// Port 1 interrupt Service routine
#if defined ( TI_COMPILER_VERSION ) || defined ( IAR_SYSTEMS_ICC )
#pragma the Vector = PORT1_VECTOR
__interrupt void Port_l (void)
#elif defined ( GNUC )
void attribute ((interrupt (PORT1_VECTOR))) Port_l (void)
#else
#error Compiler not Supported!
#endif

Try to read: If there are two things in brackets defined, then the port1 interrupt vector is assigned to vector, or if so. . . . Well anyway, after you copy it

The results were good, press the button, flip the lights on, but occasionally press flips twice, set about anti-shake:
IF (! (P1IN & BIT1))
because it is a negative transition interrupt will trigger, then went into the break and then test to see whether low.
Still found a little shake, it may take a little longer the delay time.
Internet shining delay function, the delay of one millisecond:
#define the CPU_F ((Double) 8000000)
#define delay_us (X) __delay_cycles ((Long) (the CPU_F * (Double) X / 1,000,000.0))
#define Delay_ms (X ) __delay_cycles ((long) (CPU_F * (double) x / 1000.0))
also shining cpu frequency values change it, I certainly will not be changed, directly, although I do not know how long the delay, but there is a delay on it,
Delay_ms (1);
then perfect control
is worth noting that this opens the low-power mode.

③ This is a bit complicated because not familiar with what the low-power mode.
The main function of IO and interrupt configuration and then circulation.
There is a cycle into low power mode, flip LED lights, change the trigger, and potential break
interrupt function in the interrupt flag is cleared, the interrupt enable clear, exit low-power mode

Baidu, is such that:
a low-power process executed: program execution begins at inlet main function program, when it comes into a low power program, such as: _BIS_SR (LPM1_bits + GIE); corresponding to the following procedure in this case stop state is no longer performed, when there came a break, will enter the interrupt handler, automatically exit low-power, low-power if there is no quit in interrupt, the interrupt service routine when completed, will re-enter the low power consumption.

So the whole process:
interrupt and IO configuration, enter the circulation, the first sentence is to enter low-power mode, the following program will not be executed until the interrupt has been interrupted in empty interrupt request, interrupt enable and shut down, and then exit the low power consumption mode, then the program will continue to loop execution, reversing lights, changing the trigger mode, the interrupt allowed to open, and then enter low-power mode.
When the effect is no external signals, the system low-power mode, press button, the lamp will be off, press End key, and bright lights.
The results actually perfect, do not shake shake orz, probably because they interrupt enable opening and closing of this step?

In short break on it, open the interrupt is enabled, the pull-down setting, turn off the overlay.
There format interrupt function.

Then take a look timer, and then sort out the information.

Guess you like

Origin blog.csdn.net/qq_41382643/article/details/94431956