此次的實驗要對YRPBRL78G13上的LED D2做閃爍,每300ms改變一次狀態
會使用到GPIO及Timer
1. Code Generator(Design Tool)設定
Port > Port7 > P77 > Out
Timer > General setting > Channel 0 > Interval timer
Channel 0 > Interval(16 bits) : 300 ms
Channel 0 > Generates INTTM00 when counting is started : 勾選 (計時到後便進入中斷)
按Generate Code後,會產生對應的檔案
r_cg_timer.c 包含著對timer的initial / start / stop functions, timer中斷則是進入r_cg_timer_user.c裡的 r_tau0_channel0_interrupt()
2. 在檔案 r_systeminit.c裡的 R_Systeminit(void), 已自動加上P77及timer的初始化
user無須再做修改
3. 在r_main.c的 main()裡加入R_TAU0_Channel0_Start() 讓timer 在程式初始後便開始動作
R_TAU0_Channel0_Start() 來自于r_cg_timer.c
4. timer計數到時後便會進入檔案r_cg_timer_user.c裡的r_tau0_channel0_interrupt(void)
加入一行 P7.7 =! P7.7; 即可改變D2 led的狀態
5. Build & Download
按F7或 Build > Build Project
無錯誤發生,即可把程式download到板子上執行
download完成後,畫面會進入debug mode
按F5或綠色箭頭便可執行程式
留言
張貼留言