4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

arduinoのasm命令でanalog readをする

Last updated at Posted at 2018-07-03

#参考文献
これを参考にアセンブラで書きました
命令セット一覧
命令セット一覧

参考文献
参考文献
参考文献

global変数
//global変数にする
volatile byte c = 0;
volatile byte d = 0;
main()
//main関数とかに入れる。
asm(
    "ldi  r16, 0x60     \n"
    "sts  0x007C, r16   \n"
    "ldi  r16, 0xC0     \n"
    "sts  0x007A, r16   \n"

    "wait_adc:          \n"
    "lds  r17, 0x007A   \n"
    "sbrc r17, 6        \n"
    "rjmp wait_adc      \n"
    
    "lds r17,0x0078     \n"
    "sts  (c), r17      \n"

    "lds r17,0x0079     \n"
    "sts  (d), r17      \n"
);

全文

//変数はグローバルかどうかで挙動がちがう。
volatile byte c = 0;
volatile byte d = 0;


void setup() {
  Serial.begin(115200);


  //アセンブラ
  //ADMUX(address:0x7C)に0を代入
  //ADCSRA(address:0x7A)に0を代入
  //ADCL(address:0x78)とADCH(address:0x79)にvalueが入っている。
  while (1) {
    asm(
      "ldi  r16, 0x60     \n"
      "sts  0x007C, r16   \n"
      "ldi  r16, 0xC0     \n"
      "sts  0x007A, r16   \n"

      "wait_adc:          \n"
      "lds  r17, 0x007A   \n"
      "sbrc r17, 6        \n"
      "rjmp wait_adc      \n"


      "lds r17,0x0078     \n"
      "sts  (c), r17      \n"

      "lds r17,0x0079     \n"
      "sts  (d), r17      \n"
    );

    //表示
    Serial.print(c);
    Serial.print(',');
    Serial.print(d);
    Serial.print('\n');
    delay(100);
  }
}

void loop() {
}
4
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?