Pic装配中指令流的模糊性

时间:2014-03-31 17:08:37

标签: assembly pic

在这段代码中,我正在检查按钮是否被按下,如果按下SW11,我将流程转发到比较功能。键的结构如下:

Picture

 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被按下,但是从现在开始我将 display2 display3 变量最多增加到2,然后显示一些不可预测的内容

更新:我想了解为什么指令流不同,为什么display2和display3最多只能增加2

1 个答案:

答案 0 :(得分: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会循环播放,直到按钮被重新启动。这是糟糕的代码设计!