Renesas provides a code generator called Applilet (“Application Leading Tool”) for the RL78 family and others as well.
瑞萨为RL78系列以及其他芯片提供了一款代码生成器叫做Applilet(“Application Leading Tool”)。
A valuable feature of Applilet is that it provides “round-trip engineering” in that you can generate code with Applilet, add in your own code, and read it back into Applilet for further modification without deleting or breaking your additions.
“双向工程”是该Applilet的一项极具价值的特性,你可以使用Applilet生成代码,添加自己编写的代码,然后读回到Applilet中作进一步的修正,而不会把你添加的代码删掉或者打乱。
In order to configure all port bits of a port as outputs, we need to check “Out” for each port bit.
若要将一个端口的所有位配置成输出,需要将每一位都选中“Out”。
we can specify the initial value of the output bits as one (by checking the “1� box) or zero (by leaving it unchecked).
输出位的初始值可以设置为1(选中复选框1)或者0(复选框不选中)。
The code generated by Applilet after we press “Generate Code” can be viewed by selecting the “File” tab next to “Module” and navigating the file tree view of the generated files.
按“生成代码”后Applilet生成的代码可以选择在“模块”旁边的“文件”标签页中进行浏览。
/*
Port Register (Pm)
*/
/* Pmn pin data (Pm0 to Pm7) */
#define _00_Pn0_OUTPUT_0 (0x00U) /* Pn0 output 0 */
#define _01_Pn0_OUTPUT_1 (0x01U) /* Pn0 output 1 */
#define _00_Pn1_OUTPUT_0 (0x00U) /* Pn1 output 0 */
#define _02_Pn1_OUTPUT_1 (0x02U) /* Pn1 output 1 */
#define _00_Pn2_OUTPUT_0 (0x00U) /* Pn2 output 0 */
#define _04_Pn2_OUTPUT_1 (0x04U) /* Pn2 output 1 */
#define _00_Pn3_OUTPUT_0 (0x00U) /* Pn3 output 0 */
#define _08_Pn3_OUTPUT_1 (0x08U) /* Pn3 output 1 */
#define _00_Pn4_OUTPUT_0 (0x00U) /* Pn4 output 0 */
#define _10_Pn4_OUTPUT_1 (0x10U) /* Pn4 output 1 */
#define _00_Pn5_OUTPUT_0 (0x00U) /* Pn5 output 0 */
#define _20_Pn5_OUTPUT_1 (0x20U) /* Pn5 output 1 */
#define _00_Pn6_OUTPUT_0 (0x00U) /* Pn6 output 0 */
#define _40_Pn6_OUTPUT_1 (0x40U) /* Pn6 output 1 */
#define _00_Pn7_OUTPUT_0 (0x00U) /* Pn7 output 0 */
#define _80_Pn7_OUTPUT_1 (0x80U) /* Pn7 output 1 */
解释含义
_00_Pn0_OUTPUT_0 代表:
- _00: 符号的实际值 (0x00)
- _Pn0: 端口寄存器第0位(no0)
- _OUTPUT_0: 输出值为 0
同样, _02_Pn1_OUTPUT_1 代表: - _02: 符号的实际值 (0x02)
- _Pn1: 端口寄存器第1位(n1)
- _OUTPUT_1: 输出值为 1
/*
Port Mode Register (PMm)
*/
/* Pmn pin I/O mode selection (PMm7 - PMm0) */
#define _01_PMn0_NOT_USE (0x01U) /* not use Pn0 as digital I/O */
#define _01_PMn0_MODE_INPUT (0x01U) /* use Pn0 as input mode */
#define _00_PMn0_MODE_OUTPUT (0x00U) /* use Pn0 as output mode */
#define _02_PMn1_NOT_USE (0x02U) /* not use Pn1 as digital I/O */
#define _02_PMn1_MODE_INPUT (0x02U) /* use Pn1 as input mode */
#define _00_PMn1_MODE_OUTPUT (0x00U) /* use Pn1 as output mode */
#define _04_PMn2_NOT_USE (0x04U) /* not use Pn2 as digital I/O */
#define _04_PMn2_MODE_INPUT (0x04U) /* use Pn2 as input mode */
#define _00_PMn2_MODE_OUTPUT (0x00U) /* use Pn2 as output mode */
#define _08_PMn3_NOT_USE (0x08U) /* not use Pn3 as digital I/O */
#define _08_PMn3_MODE_INPUT (0x08U) /* use Pn3 as input mode */
#define _00_PMn3_MODE_OUTPUT (0x00U) /* use Pn3 as output mode */
#define _10_PMn4_NOT_USE (0x10U) /* not use Pn4 as digital I/O */
#define _10_PMn4_MODE_INPUT (0x10U) /* use Pn4 as input mode */
#define _00_PMn4_MODE_OUTPUT (0x00U) /* use Pn4 as output mode */
#define _20_PMn5_NOT_USE (0x20U) /* not use Pn5 as digital I/O */
#define _20_PMn5_MODE_INPUT (0x20U) /* use Pn5 as input mode */
#define _00_PMn5_MODE_OUTPUT (0x00U) /* use Pn5 as output mode */
#define _40_PMn6_NOT_USE (0x40U) /* not use Pn6 as digital I/O */
#define _40_PMn6_MODE_INPUT (0x40U) /* use Pn6 as input mode */
#define _00_PMn6_MODE_OUTPUT (0x00U) /* use Pn6 as output mode */
#define _80_PMn7_NOT_USE (0x80U) /* not use Pn7 as digital I/O */
#define _80_PMn7_MODE_INPUT (0x80U) /* use Pn7 as input mode */
#define _00_PMn7_MODE_OUTPUT (0x00U) /* use Pn7 as output mode */
解释含义
- _00_PMn0_MODE_OUTPUT 代表:
- _00: 符号的实际值 (0x00)
- _Pmn0: 端口状态寄存器第0位(no0)
- _MODE_OUTPUT: 输出位
同样, _01_PMn0_MODE_INPUT 代表: - _01: 符号的实际值 (0x01)
- _PMn0: 端口状态寄存器第0位
- _MODE_INPUT: 输入位
词汇
- sink currents,反向电流
- Servos,伺服电机
- Stepper motors,步进马达
- level converter,电平变换器
- comparator,比较器
- quantization,数字化
- polling,轮询
Pulse Width Modulation###
A common method for controlling the speed of a simple DC motor or the brightness of an LED is Pulse Width Modulation. Pulse Width Modulation works as a DAC by changing the duty cycle of an oscillating digital output as shown in Figure 2.20. In the case of an LED, the more time the duty cycle is HIGH, the brighter the LED. This method works in cases where the oscillating frequency is so fast that the resulting output seems smooth. The LED is actually turning on and off many tens of times per second; however, the human eye cannot
detect the independent flashes of the LED due to their speed. Motor speed can be controlled this way because the inertia of the spinning armature carries the motor forward through the moments when no power is applied. A PWM signal is typically generated by a timer peripheral which sets or clears the output signal when the internal counter reaches configurable count values.
控制简单直流电机的转速,或者LED亮度的普通方法是PWM,PWM通过改变震荡数字输出的占空比按DAC工作,对于LED来说,高占空比的时间越长,LED越亮,实际上LED每秒钟点亮熄灭次数太高,这样的高速人眼根本不能反应过来。马达的控制也是一样。计时器外设产生PWM信号。