Compilers for Microchip PIC

東大の CubeSat が PICマイコンを使っていた経緯からか、 他の CubeSat でも PIC が多く使われています。 PICマイコンの中でも、 PIC16F877 が 2003年の東大CubeSat “XI” (サイ) に使われていたようです。

PIC は Microchip Technology 社が開発・販売しているマイコンです。 8 bit から 32 bit まで幅広くライナップを揃えています。 PIC16F877 は、 8 bit マイコンです。 8 bit PIC については、 Microchip のサイトを確認してください。

MPLAB

さて、 PIC 用のコンパイラーですが Microchip から “MPLAB” シリーズとして IDE (統合開発環境) やコンパイラー単体という形でリリースされています。ふつうに使うのであれば、 MPLAB X IDE をダウンロードして使うのが簡単でしょう。

IDE 嫌いの人や Continuous Integration で使う場合は、 MPLAB XC Compiler がおすすめです。 一昔前は xc8 というバイナリがコンパイラードライバーでしたが、 2022年現在は xc8-cc というバイナリになっています。 xc8 は、 C90 に対応した 「レガシー」コンパイラーという位置づけのようです。 xc8-cc の方は、 C99 に対応しています (MPLAB XC8 - v2.20 2020年)

| コマンド | C Standard
|—|—|—|
| xc8 | C90
| xc8-cc | C99

Docuemnt

SDCC

Open Source のコンパイラーで PIC に対応しているもので有名なのは、 SDCC - Small Device C Compiler です。 PIC専用のコンパイラーではなく、色々なマイコンに対応しています。 SDCC 自体は PIC16F877 にも対応していますが、 残念なことのに PIC16F877 対応は Free ではなく、 Debian や Ubuntu のパッケージからははずされています。 Debian 上で使いたい場合は、 SDCC のサイトからダウンロード するか、 自分でビルドする必要があります。 Subversion で管理されています。

PIC16F877 の対応が Free ではない理由は、 SDCC Compiler User Guide に以下のように記載されています。

Pic device specific header and c source files are automatically generated from MPLAB include files, which are published by Microchip with a special requirement that they are only to be used with authentic Microchip devices. This req[u]irement prevents to publish generated header and c source files under the GPL compatible license, so they are located in non-free directory (see section 2.3). In order to include them in include and library search paths, the --use-non-free command line option should be defined.