VOOZH about

URL: https://qiita.com/crawd4274/items/8f8af1597698f0c5025a

⇱ arduinoのasm命令でanalog readをする #Arduino - Qiita


👁 Image
4

Go to list of users who liked

1

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@crawd4274(安藤 亮介)

arduinoのasm命令でanalog readをする

4
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

Go to list of users who liked

1
0

Go to list of comments

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

Go to list of users who liked

1