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/MSP430G2553:LED 的输出二进制4位?

Guru**** 2577385 points


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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/610653/ccs-msp430g2553-output-binary-4bits-for-leds

器件型号:MSP430G2553

工具/软件:Code Composer Studio

大家好、我是新手、我使用两个变量执行乘法。结果我可以看到它存储在分配给它的变量中、但我希望它作为二进制输出、方法是使用端口2的4位打开 LED、 我将变量 a = 2和 b = 6存储在 c = a + b、然后 c = 8中、我想使用具有4位的端口2输出"1000"、以便连接到端口的 LED 在此亮起、 只有一个 LED 和3个 LED 将保持关闭状态、只需尝试在端口上加载注册表、但它不起作用(如果我将其作为输出、则为 P2DIR)

  
P2OUT |= c;

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    尝试将端口2的引脚0-3设置为输出。
    P2DIR |= BIT0 + BIT1 + BIT2 + BIT3;

    然后只需使用:
    P2OUT &=~(BIT0 + BIT1 + BIT2 + BIT3);//清除 LED

    然后、
    P2OUT |=(BIT0 + BIT1 + BIT2 + BIT3)和 c;//根据变量 C 设置相应的 LED