2017-04-03 7 views
0

ATMEL ATmega16のアセンブリコードをAtmelStudio 7を使用して記述しています。 ボタンを押している間にLEDをオンにしたいのですが、もう一度。まるで部屋の照明のようです。なんらかの理由で、このコードはライトをオンにし、ボタンを押すことで決して消えません(ボタンはプロテウスでシミュレートされます)。誰もこの簡単なコードで私を助けることができますか?ボタンを使用したアセンブリでのAVR LEDのオン/オフプログラム

start: 
    /* set the PIND2 data direction to 0 for input */ 
    /* This one simulates the key */ 
    ldi R16, (0 << PD2) ; Make PD2 as input 
    out DDRB,R16 ; Configure the PIND2 as input 

    /* set the PORTB7 data direction to 1 for output */ 
    /* this one causes the LED to be ON/OFF */ 
    ldi R17, (1 << PB7) ; Make PB7 as output 
    out DDRB,R17 ; Configure the PORTB7 as output 

OFF_MODE: 
    /* Put the PORTB7 to 0 */ 
    ldi R18,(0 << PB7) 
    out PORTB,R18 
    call delay 
    /* Skip if PIN 2 in PORT D is set */ 
    sbis PIND,2 
    jmp OFF_MODE ; Branch to the OFF_MODE if the key isn't pressed yet 

ON_MODE: 
    /* Put the PORTB to 1 */ 
    ldi R18,(1 << PB7) 
    out PORTB,R18 
    call delay 
    /* Skip if PIN 2 in PORT D is set */ 
    sbis PIND,2 
    jmp ON_MODE ; Branch to the ON_MODE if the key isn't unpressed yet 
rjmp start 
delay: 
    ldi r16, 0xFF 
delay_loop_1: 
    dec r16 
    cpi r16, 0x00 
    jmp delay_loop_1 
ret 

答えて

1

delay機能に無限ループがあります。を使用して心:

delay: 
    ldi r16, 0xFF 
delay_loop_1: 
    dec r16 
    brne delay_loop_1 
    ret 
+0

ありがとう。解決済み! – aligholamee

関連する問題