【问题标题】:blackfin bf537 LED blinkingblackfin bf537 LED 闪烁
【发布时间】:2017-08-29 08:17:31
【问题描述】:

下面这些代码是blackfin bf537的LED闪烁程序示例 LED 将从右向左闪烁并返回。 /**/

EX_INTERRUPT_HANDLER(Timer0_ISR)
{
// confirm interrupt handling
*pTIMER_STATUS = 0x0001;

// shift old LED pattern by one, left to right
if(sLight_Move_Direction)
{
    if((ucActive_LED = ucActive_LED >> 1) <= 0x0020) ucActive_LED = 0x1000;
}
else
{
    if((ucActive_LED = ucActive_LED << 1) == 0x0020) ucActive_LED = 0x0020;
}

// write new LED pattern to PORTF LEDs
*pPORTFIO_TOGGLE = ucActive_LED;  

/**/

现在我正在尝试修改代码以完成新功能,我希望它在我按下按钮时从左到右闪烁一次,所以我的代码如下: /**/

EX_INTERRUPT_HANDLER(Timer0_ISR)
{
// confirm interrupt handling
*pTIMER_STATUS = 0x0001;

// shift old LED pattern by one, left to right
if(sLight_Move_Direction){

    ucActive_LED == 0x0800;

    ucActive_LED = ucActive_LED >> 1;

    ucActive_LED == 0x0040; 
}

// write new LED pattern to PORTF LEDs  
*pPORTFIO_TOGGLE = ucActive_LED; 

/**/

现在无法工作或只是闪烁 LED3,我该如何解决?

谢谢

【问题讨论】:

  • 您正在使用 == 而不是 =,您将收到警告“声明无效”。(整个内容将转换为 bool)。 ucActive_LED = ucActive_LED >> 1;可以换成ucActive_LED>>1;
  • 我试过了,但还是不行。代码或我的想法有什么问题吗?
  • 我的错,是ucActive_LED>>=1;
  • 它仍然无法工作..还是谢谢!

标签: c signal-processing blackfin


【解决方案1】:

经过几天的思考,这是我的答案:

int Mode;

EX_INTERRUPT_HANDLER(Timer0_ISR)
{
    // confirm interrupt handling
    *pTIMER_STATUS = 0x0001;

    if(Mode == 1)
    {
    if((ucActive_LED = ucActive_LED >> 1) <= 0x0020) 
        ucActive_LED = 0x1000;
    }
    else if(Mode == 2)
    {
     if((ucActive_LED = ucActive_LED << 1) >= 0x1000) 
     ucActive_LED = 0x0020;             
    }
    else if(Mode == 3)
    {
    if((ucActive_LED = ucActive_LED >> 2) <= 0x0020) 
        ucActive_LED = 0x1000;  
    }


    // write new LED pattern to PORTF LEDs  
    *pPORTFIO = ucActive_LED;  
    }

然后将 PORTFIO 设置为按钮从 PF2 到 PF5(SW13~SW10) 每个按钮对应每个模式,因此我们可以看到模式 1 是 LED 从左到右闪烁。模式 2 从右向左闪烁。模式 3 正在闪烁 LED 2、4 和 6。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多