2017-08-29 75 views
0

以下代碼是blackfin bf537 LED閃爍程序的示例,LED將從右向左閃爍並切換回。 /**/blackfin bf537 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; 

/**/

現在我想修改代碼來實現新的功能,我想它離開的時候我推BUTTOM到正確的時間眨眼,所以有我的代碼如下: /**/

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,我該如何解決呢?

感謝

+1

您正在使用==而不是=,並且您將得到一個警告「聲明無效」(整個事情將被轉換爲布爾)。 ucActive_LED = ucActive_LED >> 1;可以用ucActive_LED >> 1替換; –

+0

我試過了,但還是不行。代碼或我的想法有什麼問題嗎? –

+0

我的錯誤是ucActive_LED >> = 1; –

回答

0

幾天後想,這裏就是我的回答:

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.