1: 2012-08-22 (水) 03:16:40 yuji ソース 現: 2020-12-26 (土) 15:07:42 yuji ソース
Attached file: pins_arduino.h, Attached file: ATmegaBOOT_168.c, Attached file: Makefile.168p, Attached file: avrdude.conf, Deleted an attach file: pins_arduino.h at 2012-08-22 (水) 13:46:06, Deleted an attach file: ATmegaBOOT_168.c at 2018-09-20 (木) 13:27:27, Deleted an attach file: Makefile.168p at 2018-09-20 (木) 13:27:38 at 2021-04-28 (水) 08:36:22, Deleted an attach file: avrdude.conf at 2021-04-28 (水) 12:55:08 at 2022-07-11 (月) 15:09:58, Deleted an attach file: ATmegaBOOT_168P_piramp_16mhz.hex at 2022-07-11 (月) 15:16:42, Deleted an attach file: ATmegaBOOT_168P_piramp_8mhz.hex at 2022-07-11 (月) 15:16:53, Deleted an attach file: usbio_pins_arduino.zip at 2022-10-18 (火) 10:13:25, Deleted an attach file: piramp_pins_arduino.zip at 2022-10-18 (火) 10:14:13, Deleted an attach file: optiboot.zip at 2022-10-27 (木) 09:30:13 at 2022-10-27 (木) 12:39:46
Line 1: Line 1:
*Arduinoって [#f6134257] *Arduinoって [#f6134257]
-Arduino(アルドゥイーノ)は,AVRを搭載した基板,Arduino言語とそれの統合開発環境から構成されるシステムのことらしい。~ +[[Arduino(アルドゥイーノ)>https://www.arduino.cc/]]は,ATMEL社のAVRチップ(ATmega8, ATmega168, ATmega328Pなど)を搭載したボードと,Arduino言語とそれらを使用して開発するための統合開発環境(IDE)から構成されるシステムのことらしい。
-イタリアの人が,当時入手可能であった他の学生向けのロボット制御用のデバイスよりも,安価なプロトタイピング・システムを製造することを目的にスタートしたようだ。+
-最近まで知らなかったんだけど便利らしいんで,試しに自分の作成した基板で試してみた。+イタリアのIDIIで学んでいたHernando Barragán氏が修士論文のテーマとして,「電子回路のハードウェアを抽象化して,より一般的な人が開発できるようにすること」を研究していた。実際に開発したものが後にArduinoというプラットフォームとなったようだ。当時のハードウェアや開発ツールに比べてできるだけ安価にすることがポイントだったらしい。~ 
 +Hernando Barragán氏の論文は[[ここで>http://people.interactionivrea.org/h.barragan/thesis/thesis_low_res.pdf]]読むことが出来る。 
 + 
 +その後,Hernando Barragán氏の論文アドバイザーだったMassimo Banzi氏が他の4人の人と''かってに''立ち上げたのがArduinoプロジェクト。Hernando Barragán氏には相談もなく,彼は参加もしていない。よりによって教育者の立場にある者が,生徒の成果を利用したということになる。 
 + 
 +ハードウェアの情報は公開されていて,誰でも機能が同じボードを作成することが出来る。実際に[[Arduino>https://www.arduino.cc/]]のオリジナルボード以外にも,多くのボードが市販されている。 
 + 
 +現在では入門用IoT機器の定番として扱われるようになり,世界的に人気になっているみたい。 
 + 
 +最近まで知らなかったんだけど便利らしいんで,Arduinoの開発用ソフトウェアのArduino IDEを試しに自分の作成したボードで使用できるかどうか試してみた。
**ハードウェア [#h2692f87] **ハードウェア [#h2692f87]
-これは自分で作成したATmega168pが乗った基板を使用する。~ +[[Arduinoのオフィシャルボード>https://www.arduino.cc/en/hardware]]として販売されているボードは,後述の[[Arduinoボード・スペック>./#p656e9d4]]のような物がある。~
-ポートの使用方法が違うんで,それはソフトウェアで何とかする。+
-**ソフトウェア [#rb6dfdc9] +ATmega168PA-20AUとFT232BLを実装した自作のボードがあるんで,そのボードがArduino IDEを使ってプログラム開発が出来るか試してみた。~
-Arduinoの統合開発環境は,クロスプラットフォームで動作するJavaアプリケーションで,エディタ,コンパイラ,基板へのファームウェア転送機能などを含んでいる。~ +
-実際には,コンパイラは[[AVR-GCC:http://www.nongnu.org/avr-libc/user-manual/index.html]]で,基板へ書き込むのには[[avrdude:http://www.nongnu.org/avrdude/]]が使われている。+
-プログラミングスタイルは,C言語/C++風の構文で,AVRの基板向けに最適化されているみたい。ちなみに,Arduinoではプログラムのことをスケッチと呼んでいる。+オフィシャルボードとは,CPU(Arduinoでは使われていないATmega168P)やポートの使用方法(LEDはPB0など)が違う。 
 + 
 +Arduino IDEからプログラムを書き込む時には,ソフトウェア的にはUART経由で書き込む。自作のボードはFTDIのUSB-シリアルコンバーターを実装しているんで,PCからは仮想COMポートでアクセスする。 
 + 
 +**ソフトウェア [#rb6dfdc9] 
 +''Arduino IDE''と呼ばれる統合開発環境はクロスプラットフォームで動作するJavaアプリケーションで,エディタ,コンパイラ,ボードへのプログラム転送機能,さらに各種ライブラリ,サンプルプログラム,Java JREなどを含んだALL IN ONEツール。~ 
 +下回りには,コンパイラが[[AVR-GCC:http://www.nongnu.org/avr-libc/user-manual/index.html]]で,ボードへプログラムを書き込むのには [[avrdude:http://www.nongnu.org/avrdude/]] といった,ATMEL AVR開発時に使われる一般的なツールが使われている。~ 
 +
 +プログラミングスタイルはC/C++言語風の構文で,Arduinoのボード向けに最適化されているみたい。ちなみに,Arduinoではプログラムのことを''スケッチ''と呼んでいる。~
***Arduino IDEのインストール [#l10a36d2] ***Arduino IDEのインストール [#l10a36d2]
-[[Arduinoのサイト:http://arduino.cc/en/]]のDounloadから[[Arduino 1.0.1のWindows版:http://arduino.googlecode.com/files/arduino-1.0.1-windows.zip]]をダウンロードする。+[[Arduinoのサイト:https://www.arduino.cc/en/software]]から[[Arduino IDE version1.0.1のWindows版>https://downloads.arduino.cc/arduino-1.0.1-windows.zip]](2012/05/21リリース)をダウンロードした。 [[1系の最終版version1.8.19のzip版>https://downloads.arduino.cc/arduino-1.8.19-windows.zip?_gl=1*owp70o*_ga*MjAzMTk1NDIxNS4xNjU2MjkzMDQx*_ga_NEXN8H46L5*MTY1NzUyMTQxNy4zLjEuMTY1NzUyMTc1Ny42MA..]] と2系の最新版version2.3.0は[[こちら>https://www.arduino.cc/en/software]]からダウンロード出来る。
-適当なディレクトリで解凍すればセットアップは完了。~ +09/14/2022にメジャーアップデートとなるArduino IDE 2.0.0がリリースされた。実行環境がJavaから[[Electron>https://www.electronjs.org/ja/]]に変更されている。~
-Windows版のArduino 1.0.1はavr-gccにはWinAVR-20081205が使われている。すでにWinAVR-20100110を入れてあるんだけど,気にしないでおく。+
-なぜか,MinGWをインストールしていて,CPLUS_INCLUDE_PATH環境変数を設定しているとArduinoでコンパイルがうまく行かなくなっちゃうので,CPLUS_INCLUDE_PATH環境変数を削除した。+適当なディレクトリに解凍(現在はversion1.8.19を使用している)すればセットアップは完了。~
-***いくつかのファイルの変更 [#ab3a1e26] +Windows版のArduino 1.0.1では,avr-gccにはWinAVR-20081205が使われている。すでにWinAVR-20100110を使っているのだが気にしないでおく。
-arduino-1.0.1\hardware\arduino\boards.txtの先頭に以下を追加, +
- ##############################################################+
- piramp8.name=Yuji's PIRAMP Board(8MHz)+なぜかMinGWをインストールしていてCPLUS_INCLUDE_PATH環境変数を設定していると,Arduinoでコンパイルがうまく行かなくなっちゃうので,CPLUS_INCLUDE_PATH環境変数を削除した。
- piramp8.upload.protocol=stk500+&shiftnote(); 
 + 
 +***いくつかのファイルの変更 [#ab3a1e26] 
 +自作のボードをArduino IDEから使えるように,いくつかのファイルを編集する。~ 
 + 
 +zipファイルを解凍したディレクトリにある((もし以前からArduino IDEをインストールして使用していた場合は,%LOCALAPPDATA%\Arduino15\packages\arduino\hardware\avr\1.8.5\ 以下にあるファイルも編集する必要がある。))''hardware\arduino\boards.txt''のmenu.cpu=Processorの行の下あたり(バージョン1.0.1だと先頭)に以下を追加する。 
 + ############################################################## 
 +  
 + piramp8.name=Yuji's AVR Board(8MHz) 
 +  
 + piramp8.vid.0=0x0403 
 + piramp8.pid.0=0x6001 
 +  
 + piramp8.upload.tool=avrdude 
 + piramp8.upload.protocol=arduino
 piramp8.upload.maximum_size=14336  piramp8.upload.maximum_size=14336
 piramp8.upload.speed=19200  piramp8.upload.speed=19200
 + 
 piramp8.bootloader.low_fuses=0xc2  piramp8.bootloader.low_fuses=0xc2
- piramp8.bootloader.high_fuses=0xdd+ piramp8.bootloader.high_fuses=0xdf
 piramp8.bootloader.extended_fuses=0xf8  piramp8.bootloader.extended_fuses=0xf8
- piramp8.bootloader.path=atmega + piramp8.bootloader.file=atmega/ATmegaBOOT_168P_piramp_8mhz.hex
- piramp8.bootloader.file=ATmegaBOOT_168P_piramp_8mhz.hex+
 piramp8.bootloader.unlock_bits=0x3F  piramp8.bootloader.unlock_bits=0x3F
- piramp8.bootloader.lock_bits=0x0F + piramp8.bootloader.lock_bits=0x2F 
 + 
 piramp8.build.mcu=atmega168p  piramp8.build.mcu=atmega168p
 piramp8.build.f_cpu=8000000L  piramp8.build.f_cpu=8000000L
 + piramp8.build.board=AVR_PIRAMP8
 piramp8.build.core=arduino  piramp8.build.core=arduino
 piramp8.build.variant=piramp  piramp8.build.variant=piramp
 + 
 ##############################################################  ##############################################################
- +  
- piramp16.name=Yuji's PIRAMP Board(16MHz) + piramp16.name=Yuji's AVR Board(16MHz) 
- +  
- piramp16.upload.protocol=stk500+ piramp16.vid.0=0x0403 
 + piramp16.pid.0=0x6001 
 +  
 + piramp16.upload.tool=avrdude 
 + piramp16.upload.protocol=arduino
 piramp16.upload.maximum_size=14336  piramp16.upload.maximum_size=14336
 piramp16.upload.speed=19200  piramp16.upload.speed=19200
 + 
 piramp16.bootloader.low_fuses=0xcf  piramp16.bootloader.low_fuses=0xcf
- piramp16.bootloader.high_fuses=0xdd+ piramp16.bootloader.high_fuses=0xdf
 piramp16.bootloader.extended_fuses=0xf8  piramp16.bootloader.extended_fuses=0xf8
- piramp16.bootloader.path=atmega + piramp16.bootloader.file=atmega/BOOT_168P_piramp_16mhz.hex
- piramp16.bootloader.file=ATmegaBOOT_168P_piramp_16mhz.hex+
 piramp16.bootloader.unlock_bits=0x3F  piramp16.bootloader.unlock_bits=0x3F
- piramp16.bootloader.lock_bits=0x0F + piramp16.bootloader.lock_bits=0x2F 
 + 
 piramp16.build.mcu=atmega168p  piramp16.build.mcu=atmega168p
 piramp16.build.f_cpu=16000000L  piramp16.build.f_cpu=16000000L
 + piramp16.build.board=AVR_PIRAMP16
 piramp16.build.core=arduino  piramp16.build.core=arduino
 piramp16.build.variant=piramp  piramp16.build.variant=piramp
 + 
 ##############################################################  ##############################################################
 + 
 + usbio8.name=Yuji's USBIO Board(8MHz)
 + 
 + usbio8.vid.0=0x0403
 + usbio8.pid.0=0x6001
 + 
 + usbio8.upload.tool=avrdude
 + usbio8.upload.protocol=arduino
 + usbio8.upload.maximum_size=28672
 + usbio8.upload.maximum_data_size=2048
 + usbio8.upload.speed=19200
 + 
 + usbio8.bootloader.tool=avrdude
 + usbio8.bootloader.low_fuses=0xc2
 + usbio8.bootloader.high_fuses=0xd8
 + usbio8.bootloader.extended_fuses=0xff
 + usbio8.bootloader.file=atmega/ATmegaBOOT_328_usbio_8mhz.hex
 + usbio8.bootloader.unlock_bits=0x3F
 + usbio8.bootloader.lock_bits=0x2F
 + 
 + usbio8.build.mcu=atmega328
 + usbio8.build.f_cpu=8000000L
 + usbio8.build.board=AVR_USBIO8
 + usbio8.build.core=arduino
 + usbio8.build.variant=usbio
 + 
 + ##############################################################
 +''hardware\arduino\programmers.txt''ファイルの先頭へ以下を追加する。
 + avrisp2.name=AVR ISP2 old one
 + avrisp2.communication=serial
 + avrisp2.protocol=stk500v2
 + 
 + yujiisp.name=Yuji Ueno's ISP Cable
 + yujiisp.communication=par
 + yujiisp.protocol=yuji
 +
 +これはbootloaderを書き込む時に使用するライターを指定する時に使われる。手持ちの古いAVR ISP(V2プロトコル版にしてある)を使用出来るようにするため。
 +
 +''hardware\arduino\variants\piramp''ディレクトリを作成して,その中へ&ref(piramp_pins_arduino.zip);の中にあるpins_arduino.hをコピーする。~
 +同様に,''hardware\arduino\variants\usbio''ディレクトリを作成して,その中へ&ref(usbio_pins_arduino.zip);の中にあるpins_arduino.hをコピーする。~
 +これは自作ボードでATmega168P/ATmega328のPB6,PB7やポートの機能違いを吸収するため。~
 +
 +''hardware\tools\avr\etc\avrdude.conf''ファイルに,自作のAVRライター用の定義とCPU定義を追加しておく。~
 +Arduino IDE 1.0.1用:&ref(avrdude.conf); ATmega168P用の定義はすでにあった。ATmega328用の定義がなかったので追加した。~
 +''バージョン1.8.19なんかの新しいバージョン'':avrdudeはversion6.3になっているのでavrdude.confも問題ないので,この作業は必要ない。~
 +
 +&shiftnote();
 +
 +***bootloader [#zecfbe10]
 +Arduinoの直接の機能ではないが,Arduino IDEからプログラム(スケッチ)をボードのFlash ROMに専用AVR Writerを使わず書き込むには,Arduino IDEからスケッチをコンパイルしたオブジェクトをボードに書き込む機能を持ったbootloaderを自作のボードに書き込んでおく必要がある。~
 +
 +ビルド済みのbootloaderもArduinoのパッケージに含まれているんだけど,ATmega168Pに対応していない事やオンボードLEDのポートが違うということもあり,同じような機能を持ったbootloader((stk500(avrisp)もどきで,簡単なモニター機能を入れてある))を作成してビルド後Flash ROMに書き込だ。~
 +''bootloaderをボードのCPUのFlash ROMエリアに書き込むには,AVRISP等の専用AVRライターを使う必要がある''。 bootloaderが書き込んだ後はシリアルポートからFlash ROMを書き込めるようになる。~
 +一般的に販売されているArduinoボードは,このようなbootloaderが書き込み済みで販売されている。
 +
 +''hardware\arduino\avr\bootloaders\atmega''ディレクトリに以下のzipファイル(自前のbootloader)を解凍してファイルをコピーする。~
 +&ref(piramp_usbio.zip);~
 +
 +こちらは自作のbootloaderではなくArduinoボードにも採用されている[[optiboot>https://github.com/Optiboot/optiboot]]のversionを自作ボード用にビルドしたもの。~
 +&ref(optiboot.zip);~
 +サイズが512byteに収まっているので,ユーザープログラムの最大サイズが大きくなる利点がある。~
 +
 +''既にbootloaderが書き込んである市販ボードではこの作業は必要ない''が,AVRを使った自作ボードをArduino IDEで使用する場合はbootloaderを書き込む必要がある。~
 +bootloaderを書き込んだら[[bootloaderエリアをロックビットを使ってプロテクトしておく>/開発/AVR/bootloaderのプロテクト]]。~
 +
 +bootloaderはArduino IDEからも書き込むことが出来る。IDEのツール>マイコンボードで基板を選んで,ツール>書き込み装置で専用Writer(AVR ISP等を選択)を指定して,ツール>ブートローダーを書き込むで書き込むことが出来る。(avrdudeを使っている。)
 +
 +*** 注意点 [#s3b90aa1]
 +スケッチを書き込む時はボードをリセットしbootloaderを立ち上げる必要がある。~
 +
 +この目的のために市販されているArduinoボードは,USB-シリアルコンバーターのDTR信号とCPUのResetピン間に0.1uFのコンデンサーを実装して,DTR信号でCPUのリセットを行えるようになっている。~
 +
 +''自作のボードにはリセット・スイッチもこのような回路も無いため,6pin ISPコネクタのRST端子とGNDをショートさせて手動でリセットさせる。''~
 +数秒後にユーザープログラムが立ち上がるまでにArduino IDEからプログラムを書き込む必要がある。(この操作が少しめんどくさい。)
 +
 +また自作のボードでCPUクロックが8MHzのボードは内蔵RC発振器を使っている。16MHzのボードではX'talを搭載している。~
 +AVRの内蔵RC発振器の周波数精度は±10%とあまり精度が良くない。このため8MHzのボードではArduino IDEからプログラムをブートローダーを使って書き込む時に低いbaudrateを使うようにしてある。
 +
 +*** Arduino IDEでblinkプログラムを試して見る [#yc98b968]
 +まず,ターゲットのボードをPCのUSBポートに接続する。~
 +Arduino IDEを起動して,「ツール>マイコンボード」からYuji's PIRAMP Board(8MHz)を選択する。~
 +「ツール>シリアルポート」で,ボードのCOMポートを設定する。
 +
 +「ファイル>スケッチの例>01.Basics>Blink」を開く。~
 +Arduino IDE 1.0.1の場合は,以下のように~
 + int led = 13;
 +  ↓
 + int led = LED_BUILTIN;
 +変更する。
 +
 +ツールアイコンの左から2番めにある→を押す。~
 +これでソースコードがビルドされボードのユーザープログラム領域に書き込まれる。(この時,手動のリセットが必要)
 +
 +プログラムが書き込まれた後,しばらくするとボード上のLEDが1秒毎に点滅した。
 +
 +これで,自作のボードのプログラム作成にArduino IDEが使えることがわかった。
 +
 +* Arduino IDEはどうか? [#vd1abfce]
 +Arduino IDEは,ソースコードを編集する機能(エディター)とオブジェクトをターゲット基板に書き込むI/Fが主な機能になっている。~
 +また,Arduino言語と呼ばれているdefineで定義したマクロを使用して,多少プログラムが書きやすくなるように工夫をしている。~
 +また,多くのユーザーが開発したプログラムをソースコード・ライブラリという形で利用できることが人気の一つでもある。~
 +
 +しかし,AVR-GCCと使い慣れたエディターやmakeツールでも同様にプログラム開発は行えるので,特にArduino IDEを使う必要があるかと言うと,必要はないなってのが感想。~
 +
 +また,AVRチップメーカーのATMEL社から純正の統合開発環境のAVR Studioがリリースされている。~
 +現在はATMEL社を買収したMicrochip社から[[Microchip Studio>https://www.microchip.com/en-us/tools-resources/develop/microchip-studio]]としてリリースされている。なので統合開発環境で開発したい場合はこちらを使うのが良いかも。
 +
 +** Arduino IDE 1.8.5でコンパイルエラー [#zaec480d]
 +Arduino IDE 1.8.5でコンパイルしてみると,エラーが出て失敗した。
 +
 +エラー直前の処理が''ctags''だったので,ctagsを単独で動かすと,appendモードについてのエラーが出ていた。
 + ctags: append mode is not compatible with tags to stdout
 +%HOME%/.ctagsを確認すると,
 + --append=yes
 + --recurse=yes
 + --langmap=PHP:+.inc
 + --php-kinds=cfd
 +になっていた。しょうがないんで,
 + --append=no
 + --recurse=yes
 + --langmap=PHP:+.inc
 + --php-kinds=cfd
 +に変更。~
 +これで無事コンパイル出来るようになった。
 +
 +** Arduino言語について [#z226258f]
 +
 +[[Arduino言語の日本語リファレンス>http://www.musashinodenpa.com/arduino/ref/]]を参照。
 +
 +- setup()~
 +setup()は,ボードの電源を入れたときやリセットしたときに,最初に一度だけ実行される。~
 +変数やピン端子の設定・初期化や,ライブラリの準備などに使用する。~
 +setup()は,省略できない。
 +- loop()~
 +loop()は,実行したいプログラムを書いときます。~
 +loopという名前のとおり,この部分は繰り返し実行される。~
 +loop()は,省略できない。
 +
 +*** main()は無いの? [#p7c3956c]
 +''arduino-1.0.1\hardware\arduino\cores\arduino\main.cpp''を覗いてみると,
 + #include <Arduino.h>
 + 
 + int main(void)
 + {
 +  init();
 + 
 + #if defined(USBCON)
 +  USBDevice.attach();
 + #endif
 + 
 +  setup();
 + 
 +  for (;;) {
 +  loop();
 +  if (serialEventRun) serialEventRun();
 +  }
 + 
 +  return 0;
 + }
 +となっていた。(バージョン1.0.1)~
 +なので,setup()とloop()を書き忘れると,エラーとなるわけです。
 +
 +それでは,init()はどこに書かれているかというと,''arduino-1.0.1\hardware\cores\arduino\wiring.c''にありました。~
 + void init()
 + {
 +  // this needs to be called before setup() or some functions won't
 +  // work there
 +  sei();
 + 
 +  // on the ATmega168, timer 0 is also used for fast hardware pwm
 +  // (using phase-correct PWM would mean that timer 0 overflowed half as often
 +  // resulting in different millis() behavior on the ATmega8 and ATmega168)
 + #if defined(TCCR0A) && defined(WGM01)
 +  sbi(TCCR0A, WGM01);
 +  sbi(TCCR0A, WGM00);
 + #endif
 + 
 +  // set timer 0 prescale factor to 64
 + #if defined(__AVR_ATmega128__)
 +  // CPU specific: different values for the ATmega128
 +  sbi(TCCR0, CS02);
 + #elif defined(TCCR0) && defined(CS01) && defined(CS00)
 +  // this combination is for the standard atmega8
 +  sbi(TCCR0, CS01);
 +  sbi(TCCR0, CS00);
 + #elif defined(TCCR0B) && defined(CS01) && defined(CS00)
 +  // this combination is for the standard 168/328/1280/2560
 +  sbi(TCCR0B, CS01);
 +  sbi(TCCR0B, CS00);
 + #elif defined(TCCR0A) && defined(CS01) && defined(CS00)
 +  // this combination is for the __AVR_ATmega645__ series
 +  sbi(TCCR0A, CS01);
 +  sbi(TCCR0A, CS00);
 + #else
 +  #error Timer 0 prescale factor 64 not set correctly
 + #endif
 + 
 +  // enable timer 0 overflow interrupt
 + #if defined(TIMSK) && defined(TOIE0)
 +  sbi(TIMSK, TOIE0);
 + #elif defined(TIMSK0) && defined(TOIE0)
 +  sbi(TIMSK0, TOIE0);
 + #else
 +  #error Timer 0 overflow interrupt not set correctly
 + #endif
 + 
 +  // timers 1 and 2 are used for phase-correct hardware pwm
 +  // this is better for motors as it ensures an even waveform
 +  // note, however, that fast pwm mode can achieve a frequency of up
 +  // 8 MHz (with a 16 MHz clock) at 50% duty cycle
 + 
 + #if defined(TCCR1B) && defined(CS11) && defined(CS10)
 +  TCCR1B = 0;
 + 
 +  // set timer 1 prescale factor to 64
 +  sbi(TCCR1B, CS11);
 + #if F_CPU >= 8000000L
 +  sbi(TCCR1B, CS10);
 + #endif
 + #elif defined(TCCR1) && defined(CS11) && defined(CS10)
 +  sbi(TCCR1, CS11);
 + #if F_CPU >= 8000000L
 +  sbi(TCCR1, CS10);
 + #endif
 + #endif
 +  // put timer 1 in 8-bit phase correct pwm mode
 + #if defined(TCCR1A) && defined(WGM10)
 +  sbi(TCCR1A, WGM10);
 + #elif defined(TCCR1)
 +  #warning this needs to be finished
 + #endif
 + 
 +  // set timer 2 prescale factor to 64
 + #if defined(TCCR2) && defined(CS22)
 +  sbi(TCCR2, CS22);
 + #elif defined(TCCR2B) && defined(CS22)
 +  sbi(TCCR2B, CS22);
 + #else
 +  #warning Timer 2 not finished (may not be present on this CPU)
 + #endif
 + 
 +  // configure timer 2 for phase correct pwm (8-bit)
 + #if defined(TCCR2) && defined(WGM20)
 +  sbi(TCCR2, WGM20);
 + #elif defined(TCCR2A) && defined(WGM20)
 +  sbi(TCCR2A, WGM20);
 + #else
 +  #warning Timer 2 not finished (may not be present on this CPU)
 + #endif
 + 
 + #if defined(TCCR3B) && defined(CS31) && defined(WGM30)
 +  sbi(TCCR3B, CS31); // set timer 3 prescale factor to 64
 +  sbi(TCCR3B, CS30);
 +  sbi(TCCR3A, WGM30); // put timer 3 in 8-bit phase correct pwm mode
 + #endif
 + 
 + #if defined(TCCR4A) && defined(TCCR4B) && defined(TCCR4D) /* beginning of timer4 block for 32U4 and similar */
 +  sbi(TCCR4B, CS42); // set timer4 prescale factor to 64
 +  sbi(TCCR4B, CS41);
 +  sbi(TCCR4B, CS40);
 +  sbi(TCCR4D, WGM40); // put timer 4 in phase- and frequency-correct PWM mode
 +  sbi(TCCR4A, PWM4A); // enable PWM mode for comparator OCR4A
 +  sbi(TCCR4C, PWM4D); // enable PWM mode for comparator OCR4D
 + #else /* beginning of timer4 block for ATMEGA1280 and ATMEGA2560 */
 + #if defined(TCCR4B) && defined(CS41) && defined(WGM40)
 +  sbi(TCCR4B, CS41); // set timer 4 prescale factor to 64
 +  sbi(TCCR4B, CS40);
 +  sbi(TCCR4A, WGM40); // put timer 4 in 8-bit phase correct pwm mode
 + #endif
 + #endif /* end timer4 block for ATMEGA1280/2560 and similar */
 + 
 + #if defined(TCCR5B) && defined(CS51) && defined(WGM50)
 +  sbi(TCCR5B, CS51); // set timer 5 prescale factor to 64
 +  sbi(TCCR5B, CS50);
 +  sbi(TCCR5A, WGM50); // put timer 5 in 8-bit phase correct pwm mode
 + #endif
 + 
 + #if defined(ADCSRA)
 +  // set a2d prescale factor to 128
 +  // 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
 +  // XXX: this will not work properly for other clock speeds, and
 +  // this code should use F_CPU to determine the prescale factor.
 +  sbi(ADCSRA, ADPS2);
 +  sbi(ADCSRA, ADPS1);
 +  sbi(ADCSRA, ADPS0);
 + 
 +  // enable a2d conversions
 +  sbi(ADCSRA, ADEN);
 + #endif
 + 
 +  // the bootloader connects pins 0 and 1 to the USART; disconnect them
 +  // here so they can be used as normal digital i/o; they will be
 +  // reconnected in Serial.begin()
 + #if defined(UCSRB)
 +  UCSRB = 0;
 + #elif defined(UCSR0B)
 +  UCSR0B = 0;
 + #endif
 + }
 +
 +
 +AVRマイコンを使用するプログラムを作成する場合,ポートの入出力方向の設定,クロック速度の設定,割込処理の設定など・・・,AVRマイコンの動作を決定する各種設定を行うためのプログラムが必要になります。~
 +sbi()関数は,レジスタの任意のビットを有効にするためのgccで定義されているマクロです。
-arduino-1.0.1\hardware\arduino\programmers.txtへ追加 +Arduino IDEで開発を行う時には,これらをユーザーに負担にならないようにあらかじめ用意してあるわけです。
- avrisp.name=AVR ISP2 +
- avrisp.communication=serial +
- avrisp.protocol=stk500v2+
-arduino-1.0.1\hardware\arduino\variants\pirampディレクトリと,その中へpins_arduino.hを作成する。これは,ATmega168pのPB6,PB7を使えるようにするため。+* Arduinoボード・スペック [#p656e9d4] 
 +オフィシャルでリリースされているArduinoボードのスペック。~ 
 +|            |Arduino Uno |Arduino Leonardo |Arduino Due |Arduino MEGA 2560 |Arduino MEGA ADK|h 
 +|外観      |&ref(uno.png,,8%);|&ref(leonardo.png,,14%);|&ref(due.png,,10%);|&ref(mega2560.png,,10%);|&ref(adk.png,,12%);| 
 +|特徴        |人気        |Arduino UNOの廉価版&br;USBはCPU内蔵|動作電圧が3.3V|ATmega2560で,Flash ROM大きい|USBでAndroid端末に接続| 
 +|価格        |2520円      |2100円          |4980円      |4910円            |6420円          | 
 +|CPU        |ATmega328P  |ATmega32u4      |AT91SAM3X8E |ATmega2560        |ATmega2560      | 
 +|Clock      |16MHz|16MHz|84MHz|16MHz|16MHz| 
 +|Flash ROM|32KB&br;(内0.5KBはbootloader用)|32KB&br;(内4KBはbootloader用)|512KB|256KB&br;(内8KBはbootloader用)|256KB&br;(内8KBはbootloader用)| 
 +|SRAM        |2KB|2.5KB|96KB|8KB|8KB| 
 +|EEPROM      |1KB|1KB|-|4KB|4KB| 
 +|デジタルI/Oピン|14本&br;(内6本はPWM出力)|20本&br;(内7本はPWM出力)|54本&br;(内12本はPWM出力)|54本&br;(内15本はPWM出力)|54本&br;(内15本はPWM出力)| 
 +|PWMピンNo  |3, 5, 6, 9, 10, 11|3, 5, 6, 9, 10, 11, 13|2〜13|2〜13,44〜46|2〜13,44〜46| 
 +|LEDピンNo  |13          |13              |13          |13                |13              | 
 +|Analog入力  |6本        |12本            |12本        |16本              |16本            | 
 +|Analog出力  |-      |-          |2本          |-            |-          | 
 +|動作電圧    |5V          |5V              |3.3V        |5V                |5V              | 
 +|電源電圧    |7-12V&br:(6-20V) |7-12V&br;(6-20V)      |7-12V&br;(6-20V)  |7-12V&br;(6-20V)|7-12V&br;(6-20V)| 
 +|電源        |USB or 外部電源(2.1mmプラグ)|USB or 外部電源(2.1mmプラグ)|USB or 外部電源(2.1mmプラグ)|USB or 外部電源(2.1mmプラグ)|USB or 外部電源(2.1mmプラグ)| 
 +#br 
 +|            |Arduino Ethernet|Arduino Mini|LilyPad Arduino|LilyPad Arduino USB|Arduino Micro|h 
 +|外観        |&ref(ethernet.png,,12%);|&ref(mini.png,,12%);|&ref(lilypad.png,,10%);|&ref(lilypadusb.png,,8%);|&ref(micro.png,,8%);| 
 +|特徴    |イーサネットポート付&br;USB-シリアルドライバチップ無し|ブレッドボード用&br;USB-シリアルドライバチップ無し|ウェアラブルデバイス用&br;USB-シリアルドライバチップ無し|USB接続|Adafruitと共同開発| 
 +|価格        |5030円          |2995円      |2195円        |2495円            |2260円      | 
 +|CPU        |ATmega328      |ATmega168 or ATmega328|ATmega168V or ATmega328V|ATmega32u4|ATmega32u4| 
 +|Clock      |16MHz          |16MHz      |8MHz          |8MHz              |16MHz        | 
 +|Flash ROM  |32KB&br;(内0.5KBはbootloader用)|32KB&br;(内2KBはbootloader用)|16KB&br;(内2KBはbootloader用)|32KB&br;(内4KBはbootloader用)|32KB&br;(内4KBはbootloader用)| 
 +|SRAM        |2KB            |2KB        |1KB            |2.5KB              |2.5KB        | 
 +|EEPROM      |1KB            |1KB        |512B          |1KB                |1KB          | 
 +|デジタルI/Oピン|14本&br;(内4本はPWM出力)|14本&br;(内6本はPWM出力)|14本&br;(内6本はPWM出力)|9本&br;(内4本はPWM出力)|10本&br;(内7本はPWM出力)| 
 +|PWMピンNo|3, 5, 6, 9, 10, 11 |3, 5, 6, 9 10, 11|3, 5, 6, 9, 10, 11|3, 9 ,10, 11, 13|3, 5, 6, 9, 10, 11, 13| 
 +|LEDピンNo  |9              |13          |13            |13                |13          | 
 +|Analog入力  |6本            |8本        |6本            |4本                |12本        | 
 +|Analog出力  |-          |-      |-        |-            |-      | 
 +|動作電圧    |5V              |5V          |2.7-5.5V      |3.3V              |5V          | 
 +|電源電圧    |7-12V&br;(6-20V)|7-9V        |2.7-5.5V      |3.8-5V            |7-12V&br;(6-20V)| 
 +|電源        |Ethernet (PoE) モジュール or FTDI ケーブル/USBシリアルコネクター|外部電源(5Vピン or 9Vピン)|USB or 外部電源|micro USB or 3.7V LiPoバッテリー|USB or 外部電源| 
 +#br 
 +|            |Arduino Nano    |Arduino Pro Mini |Arduino Pro  |Arduino Fio    |Arduino Esplora|h 
 +|外観        |&ref(nano.png,,8%);|&ref(promini.png,,12%);|&ref(pro.png,,12%);|&ref(fio.png,,12%);|&ref(esplora.png,10%);| 
 +|特徴    |Arduino Duemilanoveと同等で小さい&br;ブレッドボード用|製品組込用&br;USB-シリアルドライバチップ無し|製品組込用&br;USB-シリアルドライバチップ無し|ワイヤレスアプリケーション用&br;SparkFun生産|オンボードセンサー実装| 
 +|価格        |4200円          |1895円          |1995円        |2495円          |-        | 
 +|CPU        |ATmega168 or ATmega328P|ATmega328P|ATmega168 or ATmega328P|ATmega328P|ATmega32u4| 
 +|Clock      |16MHz          |8MHz            |8MHz or 16MHz  |8MHz          |16MHz          | 
 +|Flash ROM  |16KB or 32KB&br;(内4KBはbootloader用)|16KB&br;(内2KBはbootloader用)|16KB or 32KB&br;(内2KBはbootloader用)|32KB&br;(内2KBはbootloader用)|32KB&br;(内4KBはbootloader用)| 
 +|SRAM        |1KB or 2KB      |1KB              |1KB or 2KB    |2KB            |2.5KB          | 
 +|EEPROM      |512B or 1 KB    |512B            |512B or 1KB  |1KB            |1KB            | 
 +|デジタルI/Oピン|14本&br;(内6本はPWM出力)|14本&br;(内6本はPWM出力)|14本&br;(内6本はPWM出力)|14本&br;(内6本はPWM出力)|-  | 
 +|PWMピンNo  |3, 5, 6, 9, 10, 11|3, 5, 6, 9, 10, 11|3, 5, 6, 9, 10, 11|3, 5, 6, 9, 10, 11|-      | 
 +|LEDピンNo  |13              |13              |13            |13              |-        | 
 +|Analog入力  |8本            |6本              |6本          |8本            |-        | 
 +|Analog出力  |-          |-          |-        |-          |-        | 
 +|動作電圧    |5V              |3.3V or 5V      |3.3V or 5V    |3.3V            |5V            | 
 +|電源電圧    |7-12V&br;(6-20V)|3.35-12V or 5-12V|3.35-12V or 5-12V|3.35-12V    |-        | 
 +|電源        |Mini-B USB or 外部電源|FTDIケーブル or ブレイクアウトボード|USB or 外部電源 or JSTコネクター|FTDIケーブル or ブレイクアウトボード|USB|

  • 開発/AVR/Arduino のバックアップ一覧
  • 開発/AVR/Arduino のバックアップ差分(No. All)
    • 1: 2012-08-22 (水) 03:16:40 yuji
    • 現: 2020-12-26 (土) 15:07:42 yuji
      • Attached file: pins_arduino.h, Attached file: ATmegaBOOT_168.c, Attached file: Makefile.168p, Attached file: avrdude.conf, Deleted an attach file: pins_arduino.h at 2012-08-22 (水) 13:46:06, Deleted an attach file: ATmegaBOOT_168.c at 2018-09-20 (木) 13:27:27, Deleted an attach file: Makefile.168p at 2018-09-20 (木) 13:27:38 at 2021-04-28 (水) 08:36:22, Deleted an attach file: avrdude.conf at 2021-04-28 (水) 12:55:08 at 2022-07-11 (月) 15:09:58, Deleted an attach file: ATmegaBOOT_168P_piramp_16mhz.hex at 2022-07-11 (月) 15:16:42, Deleted an attach file: ATmegaBOOT_168P_piramp_8mhz.hex at 2022-07-11 (月) 15:16:53, Deleted an attach file: usbio_pins_arduino.zip at 2022-10-18 (火) 10:13:25, Deleted an attach file: piramp_pins_arduino.zip at 2022-10-18 (火) 10:14:13, Deleted an attach file: optiboot.zip at 2022-10-27 (木) 09:30:13 at 2022-10-27 (木) 12:39:46

トップ   差分 バックアップ 複製 名前変更 リロード   ページ新規作成 全ページ一覧 単語検索 最新ページの一覧   ヘルプ   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom
Counter: 1620, today: 3, yesterday: 0