GR-SAKURA 用拡張ボード AS-E402 サンプルプログラム アプリケーションノート 1. 概要 GR-SAKURA AS-E402 CubeSuite+ 2. 用意するもの AS-E402 GR-SAKURA E1 DC GR-SAKURA AC E1 CubeSuite+ V2.01.00 3. サンプルプログラムの動作 AS-E402 LED SW1 LED1 SW2 LED2 LED3 LED4 1 SW1 SW2 3-1 203 Contrast CN5 RESET ADM3202 TSSOP-16 JP1 128 64 Dots 5V 3.3V TB6617FNG TSSOP-16 TXS0108E TSSOP-20 CN1 1 20 CN3 U4 LM75AIM SOP-8 SW2 LED4 LED3 LED2 LED1 VR1 PWR SW3 74AHC00 TSSOP-14 CN6 SW1 CN4 S V G 定 する スイッチを押すごと する 図 3-1 サンプルプログラムの動作
4. サンプルプログラムの構成 test01 4-1 プロジェクトフ ルダ CubeSuite+ 4-1 図 4-1 サンプルプログラムの構成 表 4-1 スタートアップルーチン ファイル名 内容 resetprg.c 初期設定ルーチン ( リセットベクタ関数 ) intprg.c ベクタ関数の定義 vecttbl.c 固定ベクタテーブル dbsct.c セクションの初期化処理 ( テーブル ) lowsrc.c 低水準インタフェースルーチン (C 言語部分 ) lowlvl.src 低水準インタフェースルーチン ( アセンブリ言語部分 ) sbrk.c 低水準インタフェースルーチン (sbrk 関数 ) typedefine.h 型定義ヘッダ vect.h ベクタ関数のヘッダ stacksct.h スタックサイズの設定 lowsrc.h 低水準インタフェースルーチン (C 言語ヘッダ ) sbrk.h 低水準インタフェースルーチン (sbrk 関数のヘッダ ) main test01.c 4-2
アプリケーションノート AS-E402 サンプルプログラム 表 4-2 追加したソースファイル ファイル名 内容 r_init_clock.c 動作クロックの初期設定 r_init_non_existent_port.c 未使用ポートの設定 r_init_stop_module.c 未使用モジュールの停止 r_init_clock.h r_init_clock.c の定義ファイル r_init_non_existent_port.h r_init_non_existent_port.c の定義ファイル r_init_stop_module.h r_init_stop_module.c の定義ファイル RX63N RX631 5. サンプルプログラムの内容 main test01.c 5-1 main 4 SW1 SW2 CMT0 0.5 0.5 5-2 LED 5-1 表 5-1 割り込み要因と対応する関数 LED 割り込み要因 呼び出される割り込み関数 割り込み処理を行う関数 対応する LED 押ボタンスイッチ SW1 の押下 void Excep_ICU_IRQ15(void) void IRQ15IntFunc(void) LED1 押ボタンスイッチ SW2 の押下 void Excep_ICU_IRQ7(void) void IRQ7IntFunc(void) LED2 タイマー CMT0 のコンペアマッチ ( 約 0.5 秒ごと )void Excep_CMT0_CMI0(void) void Cmt0IntFunc(void) LED3 リアルタイムクロックの 0.5 秒経過 void Excep_RTC_PRD(void) void RTCIntFunc(void) LED4 リスト 5-1 test01.c // / / / FILE :Main.c or Main.cpp / / DATE :Tue, Oct 31, 2006 / / DESCRIPTION :Main Program / / CPU TYPE : / / / / NOTE:THIS IS A TYPICAL EXAMPLE. / / / // //#include "typedefine.h" #ifdef cplusplus //#include <ios> // Remove the comment when you use ios //_SINT ios_base::init::init_cnt; // Remove the comment when you use ios #endif #include "iodefine.h" #include <machine.h> #include "r_init_clock.h" #include "r_init_non_existent_port.h" #include "r_init_stop_module.h" void main(void); void IRQ15IntFunc(void); void IRQ7IntFunc(void); void Cmt0IntFunc(void); void RTCIntFunc(void); #ifdef cplusplus
extern "C" void abort(void); #endif void main(void) clrpsw_i(); / Disable maskable interrupts / R_INIT_StopModule(); / Stopping the peripherals which start operations / R_INIT_NonExistentPort(); / Initialization of the non-existent ports / R_INIT_Clock(); / Initialization of the clock / setpsw_i(); / Enable maskable interrupts / SYSTEM.PRCR.WORD = 0xA502; / Register write enable / / PORT init / PORTE.PDR.BYTE = 0xE0; / set porte5,e6,e7(output) / PORTE.DSCR.BYTE = 0xE0; / drive high / PORTE.PODR.BYTE = 0x20; / LED2 off, LED3,4 on / PORTJ.PDR.BYTE = 0x08; / set portj3(output) / PORTJ.PODR.BYTE = 0x08; / LED1 off / / CMT0 init / MSTP(CMT0) = 0; / set mstpcra(cmt0 enable) / IEN(CMT0,CMI0) = 0; / Disable Interrupt / IPR(CMT0,CMI0) =0x07; / Priority set / CMT0.CMCR.WORD = 0x0043; / PCLK(48MHz) / 512 = 93.75kHz / CMT0.CMCNT = 0x0000; / Timer Counter clear / CMT0.CMCOR = 0xB71B; / set cmcor(compare match =500ms) / CMT.CMSTR0.WORD = 0x0001; / CMT0 start / IR(CMT0,CMI0) = 0; / Interrupt flag clear / IEN(CMT0,CMI0) = 1; / Enable Interrupt / / RTC init / IEN(RTC,PRD) = 0; / Disable Interrupt / RTC.RCR2.BIT.START = 0; / RTC stop / while (0!= RTC.RCR2.BIT.START) / wait for stop / / Confirm that the written value can be read correctly. / IPR(RTC,PRD) =0x07; / Priority set / RTC.RSECCNT.BYTE = 0; / sec counter clear / RTC.RCR1.BYTE = 0xD4; / 1/2sec periodic interrupt / RTC.RCR2.BIT.START = 1; / RTC start / while (1!= RTC.RCR2.BIT.START) / wait for start / / Confirm that the written value can be read correctly. / IR(RTC,PRD) = 0; / Interrupt flag clear / IEN(RTC,PRD) = 1; / Enable Interrupt / / ICU init / IEN(ICU,IRQ15) = 0; / Disable Interrupt / IEN(ICU,IRQ7) = 0; / Disable Interrupt / ICU.IRQFLTE1.BIT.FLTEN15 = 0; / Disable digital filter / ICU.IRQFLTE0.BIT.FLTEN7 = 0; / Disable digital filter / ICU.IRQFLTC1.BIT.FCLKSEL15 = 0x3; / Digital filter clock select / ICU.IRQFLTC0.BIT.FCLKSEL7 = 0x3; / Digital filter clock select / MPC.PWPR.BIT.B0WI = 0; / PFSWE Write Enable / MPC.PWPR.BIT.PFSWE = 1; / PFS Write Enable / MPC.P07PFS.BYTE = 0x40; / P07 for IRQ15 / MPC.P17PFS.BYTE = 0x40; / P17 for IRQ7 / MPC.PWPR.BIT.PFSWE = 0; / PFS Write Disable / MPC.PWPR.BIT.B0WI = 1; / PFSWE Write Disable / PORT0.PMR.BIT.B7 = 1; / Port mode:irq15 / PORT1.PMR.BIT.B7 = 1; / Port mode:irq7 / ICU.IRQCR[15].BYTE = 0x08; / Falling Edge Interrupt / ICU.IRQCR[7].BYTE = 0x08; / Falling Edge Interrupt / IPR(ICU,IRQ15) =0x07; / Priority set / IPR(ICU,IRQ7) =0x07; / Priority set /
アプリケーションノート AS-E402 サンプルプログラム IR(ICU,IRQ15) = 0; / Interrupt flag clear / IR(ICU,IRQ7) = 0; / Interrupt flag clear / ICU.IRQFLTE1.BIT.FLTEN15 = 1; / Enable digital filter / ICU.IRQFLTE0.BIT.FLTEN7 = 1; / Enable digital filter / IEN(ICU,IRQ15) = 1; / Enable Interrupt / IEN(ICU,IRQ7) = 1; / Enable Interrupt / while(1) ; void IRQ15IntFunc(void) / SW1 / PORTJ.PODR.BIT.B3 = ~PORTJ.PIDR.BIT.B3; / LED1 / void IRQ7IntFunc(void) / SW2 / PORTE.PODR.BIT.B5 = ~PORTE.PIDR.BIT.B5; / LED2 / void Cmt0IntFunc(void) / CMT0 / PORTE.PODR.BIT.B6 = ~PORTE.PIDR.BIT.B6; / LED3 / void RTCIntFunc(void) / RTC / PORTE.PODR.BIT.B7 = ~PORTE.PIDR.BIT.B7; / LED4 / #ifdef cplusplus void abort(void) #endif / Option-Setting Memory / #pragma address OFS1_REG = 0xFFFFFF88 / OFS1 register / const unsigned long OFS1_REG = 0xFFFFFFFF; #pragma address OFS0_REG = 0xFFFFFF8C / OFS0 register / const unsigned long OFS0_REG = 0xFFFFFFFF; リスト 5-2 intprg.c( 抜粋 ) / Device : RX/RX600/RX63N,RX631 File Name : intprg.c Abstract : Interrupt Program. History : 0.10 (2011-02-21) [Hardware Manual Revision : 0.01] : 1.00 (2012-06-12) [Hardware Manual Revision : 1.00] : 1.10 (2013-02-18) [Hardware Manual Revision : 1.00] NOTE : THIS IS A TYPICAL EXAMPLE. Copyright (C) 2013 (2011,2012) Renesas Electronics Corporation and Renesas Solutions Corp. All rights reserved. / #include <machine.h> #include "vect.h"
#pragma section IntPRG extern void IRQ15IntFunc(void); extern void IRQ7IntFunc(void); extern void Cmt0IntFunc(void); extern void RTCIntFunc(void); ~ 中略 ~ // CMT0 CMI0 void Excep_CMT0_CMI0(void) Cmt0IntFunc(); ~ 中略 ~ // ICU IRQ7 void Excep_ICU_IRQ7(void) IRQ7IntFunc(); ~ 中略 ~ // ICU IRQ15 void Excep_ICU_IRQ15(void) IRQ15IntFunc(); ~ 中略 ~ // RTC PRD void Excep_RTC_PRD(void) RTCIntFunc(); ~ 中略 ~
アプリケーションノート AS-E402 サンプルプログラム 6. サンプルプログラムを開く C: WorkSpace RX63N test01 CubeSuite+ Windows Renesas Electronics CubeSuite+ CubeSuite+ CubeSuite+ GO 6-1 G ボタンをクリックし 既存のプロジェクトを開く 図 6-1 既存のプロジェクトを開く test01. mtpj RX E1 JTAG RX E1 JTAG RX RX E1 JTAG 6-2
R E1( T G) を 図 6-2 デバッグツールの設定 RX E1 JTAG MHz 12.000 6-3 メインクロック周波数 M の 12.000 と る とを確認 図 6-3 メインクロック周波数の設定を確認
アプリケーションノート AS-E402 サンプルプログラム MHz 96.000 6-4 デバッグツール設定 のタブをクリック 動作周波数 M の 96.000 と る とを確認 図 6-4 動作周波数の設定を確認 6-5 ファイル名をダブルクリック 図 6-5 動作周波数の設定を確認
AS-E402 6-6 図 6-6 デバッグを開始する 6-7 図 6-7 プログラムを実行する AS-E402 LED3 LED4 10
アプリケーションノート AS-E402 サンプルプログラム SW1 LED1 SW2 LED2 6-8 停止ボタンをクリック 図 6-8 プログラムを停止する 6-9 デバッグツールから切断ボタンをクリック 図 6-9 デバッグツールから切断 11
RX63N Microsoft Windows Microsoft https:// www.sunhayato.co.jp/inquiry/ http://www.sunhayato.co.jp/ Copyright 2013 Sunhayato Corp. 2013 年 12 月 1 日発行 REV.1.00 SG13013 ホームページ :www.sunhayato.co.jp