1

MikroC を使用して、PIC16f62 マイクロコントローラをプログラムしようとしています。出力を機能させることはできました (LED を点灯させることができます) が、入力を機能させることができないようです。

これが私の現在のコードです:

void main() {
    TRISB.RB0 = 0; //set Port RB0 as output
    PORTB.RB0 = 1; //set Port RB0 to high (turn on LED)
    TRISA = 1; //Set PORTA as inputs 

    for(;;){  //endless loop
            if(PORTA.RA0 == 1){  //if push button is pressed
                         PORTB.RB0 = !PORTB.RB0;  \\toggle LED
            }
    }
}

PORT を正しく設定していないことが問題なのか、ボタンが正しく押されていないかどうかを確認しているのかどうかはわかりません。

どんな助けでも大歓迎です。ありがとう。

4

2 に答える 2

7

この変更が役立つ場合があります。

for(;;){  //endless loop
        if(PORTA.RA0 == 1){  //if push button is pressed
                     PORTB.RB0 = !PORTB.RB0;  \\toggle LED
          while(PORTA.RA0 == 1);
       /*wait till button released as press of a buttons take time  and processor is too fast */
        }
于 2012-08-21T04:57:08.910 に答える