为什么 ASM (MPLAB X) 中的这段代码不起作用(开/关 LED)


    #include p16f88.inc

;----------memory data--------
program org 0x00
    goto    preparation
Preparation
    bsf status,RP0
    bsf trisb,trisb0    ; load port rb0 as input
    bcf trisb,TRISB4    ; load port rb4 as output   
    bcf status,RP0
    goto    begin
;---------------begin---------------
begin
    btfss   portb,rb0
    goto    begin   
    goto    on
on
    bsf portb,rb4
    goto    begin
    end

我的意思是我可以做领导,但我不能做。当我离开按下按钮时,我必须添加什么才能做?

发光二极管

此致敬意。

编辑:现在我将其添加到代码中,但是当我按下开关 3 或 4 次时 LED 关闭?

program org 0x00
    goto    preparation
Preparation
    bsf status,RP0
    bsf trisb,trisb0    ; load port rb0 as input
    bcf trisb,TRISB4    ; load port rb4 as output   
    bcf status,RP0
    goto    begin
;---------------begin---------------
begin
    btfss   portb,rb0
    goto    begin   
    goto    on
on
    bsf portb,rb4
    btfsc   portb,rb0   /* <----------  I add this part*/
    goto    begin       /* <----------  for off the led*/
    bcf portb, rb4  /* <----------  again*/
    goto    begin
    end

变形杆菌正常还是我的代码可以?

开关输入端添加一个下拉电阻,然后尝试:

program org 0x00
goto    preparation
Preparation
bsf status,RP0
bsf trisb,trisb0    ; load port rb0 as input
bcf trisb,TRISB4    ; load port rb4 as output   
bcf status,RP0
goto    begin
;---------------begin---------------
begin
btfss   portb,rb0
goto    begin   
goto    on
on
bsf     portb,rb4
btfsc   portb,rb0   
goto    on          ;don't go to begin but keep testing for the switch to be released
bcf     portb, rb4  
goto    begin
end

最新更新