1 / 8

R8C I/O ポートの仕組み

R8C I/O ポートの仕組み. SFR 定義 ファイルの中身. SFR 定義ファイルとは. sfr_r815.h ファイル p1_1 などの変数名をプログラム中で利用できるようにする I/O ポートへのアクセスの場合、1バイト単位のアクセス以外に、1ビット毎(1つの I/O ポート毎)のアクセスもできるようにしている. SFR 定義ファイル の中身. # pragma ADDRESS p1_addr 00E1H : : struct bit_def { char b0:1; char b1:1; char b2:1; char b3:1 ;

ursala
Download Presentation

R8C I/O ポートの仕組み

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. R8CI/Oポートの仕組み SFR定義ファイルの中身

  2. SFR定義ファイルとは • sfr_r815.hファイル • p1_1などの変数名をプログラム中で利用できるようにする • I/Oポートへのアクセスの場合、1バイト単位のアクセス以外に、1ビット毎(1つのI/Oポート毎)のアクセスもできるようにしている

  3. SFR定義ファイルの中身 #pragma ADDRESS p1_addr 00E1H : : structbit_def{ char b0:1; char b1:1; char b2:1; char b3:1; char b4:1; char b5:1; char b6:1; char b7:1; }; union byte_def{ structbit_def bit; char byte; }; union byte_def p1_addr;

  4. SFR定義ファイルの中身 #pragmaADDRESS p1_addr 00E1H : : structbit_def{ char b0:1; char b1:1; char b2:1; char b3:1; char b4:1; char b5:1; char b6:1; char b7:1; }; union byte_def{ structbit_def bit; char byte; }; union byte_def p1_addr; #pragma(「プラグマ」)とは、コンパイラに特定の情報を渡すために使用するコンパイラ指令です。 この中身は、コンパイラごとに異なっています。 この場合は、p1_addrという変数名を、アドレス00E1に強制的に割り当てています。 こうすることで、p1_addrという変数名でSFRの00E1アドレスへアクセスできるようになります。

  5. SFR定義ファイルの中身 #pragma ADDRESS p1_addr 00E1H : : structbit_def{ char b0:1; char b1:1; char b2:1; char b3:1; char b4:1; char b5:1; char b6:1; char b7:1; }; union byte_def{ structbit_def bit; char byte; }; union byte_def p1_addr; これはbit_def構造体の定義です。 char b0:1;と宣言すると1ビットのデータとなります。 この構造体のサイズは全部で8ビットです。(b0~b7) この構造体の変数を作成した場合構造体変数名.b0などの方法で、対応するビットへアクセスできます。 プログラム 構造体変数名.b0=1; x=構造体変数名.b1 構造体に対応したメモリ 5V 1 1

  6. SFR定義ファイルの中身 #pragma ADDRESS p1_addr 00E1H : : structbit_def{ char b0:1; char b1:1; char b2:1; char b3:1; char b4:1; char b5:1; char b6:1; char b7:1; }; union byte_def{ structbit_def bit; char byte; }; union byte_def p1_addr; • これはbyte_def共用体の定義です。 • bitというメンバ変数(bit_def型)と、byteというメンバ変数(char型)は、どちらも8ビットのデータです。 • この共用体のサイズは全部で8ビットです。 • この共用体の変数を作成した場合共用体変数名.byteの方法で、8ビット全体にアクセスできます。 • この共用体の変数で共用体変数名.bit.b0の方法で、1ビット毎にアクセスできます。 プログラム 共用体変数名.bit.b0=1; 共用体変数名.byte=0x0F; 構造体に対応したメモリ 0 0 0 0 1 1 1 1 1

  7. SFR定義ファイルの中身 #pragma ADDRESS p1_addr 00E1H : : structbit_def{ char b0:1; char b1:1; char b2:1; char b3:1; char b4:1; char b5:1; char b6:1; char b7:1; }; union byte_def{ structbit_def bit; char byte; }; union byte_def p1_addr; これが実際の変数の宣言です。 変数名p1_addrはbyte_def共用体の変数として定義されています。 #pragmaでアドレスを00E1に割り当てているので、SFRにアクセスする変数となっています。 プログラム p1_addr.bit.b0=1; メモリのSFR領域  00E1 1

  8. SFR定義ファイルの中身2 #definep1 p1_addr.byte #define p1_0 p1_addr.bit.b0 : : #defineでp1_0などがプログラム中で利用できるように定義しています。 こうすることで、p1_0がSFR内のポート1のビット0にアクセスできるようになります。

More Related