Assembly Pic汇编中指令流的模糊性
在这段代码中,我检查按钮是否按下,如果SW11按下,我将流程转发到比较功能。按键结构如下:Assembly Pic汇编中指令流的模糊性,assembly,pic,Assembly,Pic,在这段代码中,我检查按钮是否按下,如果SW11按下,我将流程转发到比较功能。按键结构如下: aftersw00: movf counter,0 call ledtable movwf countertab call led call disp1 movf display2,0 call displaytable23 movwf displaytab2 call d
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
我通过设置使RB1禁用
bsf PORTB,1
为了确保第三行,即SW11被按下,但从现在起,我只将display2和display3变量增加到2,然后显示一些不可预测的内容
更新:我想了解为什么指令流不同,为什么display2和display3在第一次查看时只能增加到2。。。
incf display3,1
未执行的原因是您在第一次进行pin检查时:
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 wiat将进入环路,直到该按钮松开。这是糟糕的代码设计
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