2014-03-31 58 views
2

指令流在該代碼中,如果按鈕被按壓,如果被按壓SW11,我轉發流鍵進行比較的 function.The結構下面我檢查歧義在PIC彙編

aftersw00: 



    movf counter,0 
    call ledtable 
    movwf countertab 
    call led 

    call disp1 

    movf display2,0 
    call displaytable23 
    movwf displaytab2 
    call disp2     //show on display2 


    movf display3,0 
    call displaytable23 
    movwf displaytab3 
    call disp3     //show on display3 
    call assignRandomNumber 
    call delay 

    bsf  PORTB,1    //here I make RB1,to disable sw4,sw5,sw6,sw7 
    btfsc PORTB,7    //here I check if RB7 pressed, if pressed RB7 becomes 0 
     goto $+5   //if not pressed, it must go +5 instructions forward 
     btfss PORTB,4  //check if button is released 
    goto $-1     
     bcf  PORTB,1  //if pressed and released, goto compare function 
     goto compare 
    bcf  PORTB,1 

    btfsc PORTB,4    //check for sw4 press, it RB4 initially 1,when pressed it becomes 5 
     goto $+5    //if not pressed go +5 instructions forward 
     btfss PORTB,4   //to check if released 
    goto $-1 
     decf display2,1  //if pressed and released, decrement display2        
    goto aftersw00   //and go to aftersw00 function again 
    btfsc PORTB,5    
     goto $+5 
     btfss PORTB,5 
    goto $-1 
     incf display2,1 
    goto aftersw00    
    btfsc PORTB,6 
     goto $+5 
     btfss PORTB,6 
    goto $-1 
     decf display3,1 
    goto aftersw00 
    btfsc PORTB,7 
     goto aftersw00 
    btfss PORTB,7 
    goto $-1 
     incf display3,1 
    goto aftersw00 

compare:      basic function to display what is now display 

    movf counter,0 
    call ledtable 
    movwf countertab 
    call led 

    call disp1 

    movf display2,0 
    call displaytable23 
    movwf displaytab2 
    call disp2 



    movf display3,0 
    call displaytable23 
    movwf displaytab3 
    call disp3 
    goto compare 

我通過設置

使RB1禁用
bsf PORTB,1 

,以確保第三行,就是SW11被按下,但現在我遞增顯示2display3變量只能達到2,然後顯示出一些不可預知的

更新:我想理解爲什麼指令流不同,爲什麼顯示2和display3可以增加僅達2

回答

0

在第一次看... 爲什麼不執行incf display3,1的原因是,你必須在第一腳檢查:

btfsc PORTB,7  //here I check if RB7 pressed, if pressed RB7 becomes 0 
goto $+5   //if not pressed, it must go +5 instructions forward 
btfss PORTB,4  //check if button is released 

,而不是...

btfsc PORTB,4  //here I check if RB4 pressed, if pressed RB4 becomes 0 
goto $+5   //if not pressed, it must go +5 instructions forward 
btfss PORTB,4  //check if button is released 

所以,如果是明確的(按下)的代碼的其餘部分不應該執行PORTB,7

順便說一句。 當您按下MCPU中的一個按鈕時,直到該按鈕被關閉。這是糟糕的代碼設計!