LoginSignup
3
0

More than 3 years have passed since last update.

フラッシュメモリー(rom)のテーブル参照について、

Last updated at Posted at 2019-12-03

Arduino Atmega328や168はフラッシュメモリー(rom)とramに分かれます。

Arduino コンパイラの場合

const 修飾子をつけてもなぜかRomに配置されません。

このあたりをgoogleっても昔の書き込み方式のページがヒットして
コンパイルエラーになります。(prog_int16_tなど.)

1.インクルード宣言

#include < avr/pgmspace.h > //この宣言が重要

2.データの定義

const 型  テーブル名[要素数] PROGMEM = { xxx,yyy,zzz };


const byte  bRomTable[] PROGMEM = { 0x01,0x02,0x04,0x08 };
const word  wRomTable[] PROGMEM = { 0x100,0x2000,0x4000,0x8000 };

3.読み出し部

pgm_read_byte(アドレス);
pgm_read_word(アドレス);

例:
a=pgm_read_byte(bRomTable+i);
b=pgm_read_word(wbRomTable+i);
を用いて読み出しましょう。

以上
Arudino カレンダー3日目でした。

3
0
0

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
3
0