This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/MSP430-3P-GCC-MSPGCC-TPDE:MSP430G2553 RGB LED 出现问题

Guru**** 2555630 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/597416/ccs-msp430-3p-gcc-mspgcc-tpde-msp430g2553-trouble-with-rgb-leds

器件型号:MSP430-3P-GCC-MSPGCC-TPDE

工具/软件:Code Composer Studio

我使用连接到外部按钮的 MSP430G22553。 在我的项目的这个阶段、我尝试将其设置为按下按钮之前的默认状态不会开启 RGB LED、但当您按下按钮时、RGB LED 将会亮起一段时间并显示相应的颜色。 我用两个按钮(绿色和蓝色)可以正常工作、但当我再添加两个按钮时、由于某种原因、RGB LED 现在闪烁不同的颜色、 如休眠状态中的粉色和紫色、按下按钮可将颜色更改为不需要的颜色。 这是我的代码;大多数注释不正确。

#include

#define LED0 BIT0
#define LED1 BIT6
#define RGB_LED_ALL BIT1|BIT2|BIT3|BIT4|BIT5
#define 按钮 BIT2 //Bit3 = 0x08 =P1.3
#define Button2 BIT3 //Bit2= 0x04 =P1.2
#define button3 BIT4 //Bit2= 0x04 =P1.2
#define button4 BIT5 //Bit2= 0x04 =P1.2


int main (空)

WDTCTL = WDTPW + WDTHOLD;//停止看门狗计时器
P2DIR |= RGB_LED_ALL;
P2SEL &=~RGB_LED_ALL;
P2SEL2 &=~RGB_LED_ALL;
//P1DIR |= BIT3 + BIT2;
//P1OUT |= 0x00;
P1REN |= 0x08;

P2OUT &=~RGB_LED_ALL;//~(0x10 + 0x04 + 0x02);
P1IE |=(按钮);// P1.3中断被启用
P1IE |=(Button2);
P1IE |=(button3);
P1IE |=(button4);

P1IFG &=~Ω(按钮);// P1.3 IFG 被清除
P1IFG &=~(Button2);
P1IFG &=~(button3);
P1IFG &=~(button4);


_ENABLE_INTERRUPT ();//启用所有中断
for (;;)
{}


//端口1中断服务例程
#pragma vector=Port1_vector
_interrupt void Port_1 (void)

if (!(P1IN & 0x08)){
//P2OUT &=~0x10;
P2OUT =(0x10);// P1.0 =切换

//P1IES ^=按钮;//切换中断边沿,
//P1IES ^= Button2;

if (!(P1IN & 0x04)){
//P2OUT &=~0x04;
P2OUT =(0x04);// P1.0 =切换

// P1IES ^= Button2;//切换中断边沿,
//P1IES ^=按钮;//切换中断边沿,

if (!(P1IN & 0x10)){
//P2OUT &=~0x06;
P2OUT =(0x06);// P1.0 =切换

// P1IES ^= Button2;//切换中断边沿,
//P1IES ^=按钮;//切换中断边沿,

if (!(P1IN & 0x20)){
//P2OUT &=~0x12;
P2OUT =(0x12);// P1.0 =切换

// P1IES ^= Button2;//切换中断边沿,
//P1IES ^=按钮;//切换中断边沿,

否则、if (P1IN & 0xCC){
P2OUT &=~RGB_LED_ALL;
P1IFG &=~按钮;// P1.3 IFG 被清除
P1IFG &=~BUTTON2;
P1IFG &=~按钮3;
P1IFG &=~按钮4;

/*否则(P1IN & button3){
P2OUT ^=(0x02);// P1.0 =切换
P1IFG &=~μ s button3;// P1.3 IFG 清零
P1IES ^= button3;//切换中断边沿、

否则、如果(P1IN & button4){
P2OUT ^=(0x12);// P1.0 =切换
P1IFG &=~按钮;// P1.3 IFG 被清除
P1IES ^=按钮;//切换中断边沿、

//将调用中断矢量
//当 P1.3也从 HitoLow 进入时
// LowtoHigh
*

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    >#define RGB_LED_ALL BIT1 |BIT2 |BIT3 |BIT4 |BIT4

    在该表达式周围放置圆括号。 当与"~"结合使用时、它不会执行您认为的操作。

    >P2OUT =(0x06);// P1.0 =切换

    确保这符合您的想法。 它本身不会切换任何内容。

    更普遍的做法是:我没有尝试对您的状态机进行解码(注释代码过多)、但我看不到任何可以去抖的东西。