为什么asm(MPLAB x)中的代码不起作用(开/关led)

时间:2016-03-25 18:06:43

标签: assembly pic mplab

    #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

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

led

最好的问候。

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

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

在proteus中它是正常的还是我的代码没问题?

1 个答案:

答案 0 :(得分:0)

在开关输入端添加一个下拉电阻,试试这个:

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