入门MSP430FR6989之按键

这篇文章基于上个工程,打开上个工程,将程序改成如下

#include <msp430.h>

#define uint8 unsigned char
#define uint16 unsigned int

uint8 key_data(void)
{
    uint8 key_value=0;
    if((P1IN&BIT1) == 0)
    {
        __delay_cycles(10000);
        if((P1IN&BIT1) == 0)
        {
            key_value=1;
            while((P1IN&BIT1) == 0);
        }
    }
    return key_value;
}

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;               // Stop WDT

    // Configure GPIO
    P9DIR |= BIT7;                          // Clear P1.0 output latch for a defined power-on state
    P1DIR |= BIT1;

    PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode
                                            // to activate previously configured port settings

    while(1)
    {
        uint8 key_value=0;
        key_value=key_data();
        if(key_value==1)
        {
            key_value=0;
            P9OUT ^= BIT7;
        }
    }
}

编译,运行,即可通过S1(P1.1)控制LED2(P9.7)了

 

上一篇:分别使用Opencv、FFmepg、LibYUV将YUV数据转换为RGB


下一篇:标志位和中断位的区别:USART_ClearFlag和USART_ClearITPendingBit