找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3628|回复: 0
收起左侧

R7F0C802x Easy Start各功能测试程序+原理图

[复制链接]
ID:124161 发表于 2016-6-24 11:06 | 显示全部楼层 |阅读模式
0.png
用R7F0C802陆陆续编写了几个程序,小面分享一些经验,即将会用到的朋友一些参考。

1.CODE GENERATOR工作原理

         CODE GENERATOR是作为一个插件导入到CubeSuit+里面的。这个东西挺好的用的,基本上所有的外设的寄存器都可以用图形化配置了,用户只需要写自己的应用程序即可。它的原理没有找到,但是在使用过程中发现它其实就是由一系列模版组成,当你选择了某个功能后模版就自动加载那条语句,最后再把这个模版拷贝到用户工作区中。这种方法其实STM32也有,不过瑞萨把 CODE GENERATOR集成到了CubeSuit+里面,使得程序员使用起来还是很方便的。不过CODE GENERATOR生产配置代码虽然很方便但其隐藏了细节,对于我等这种喜欢刨根问底的人来说感觉有点不爽,还是直接配置寄存器来的舒服。

2.瑞萨单片机按位使用及声明位置
          在瑞萨单片机中是可以像51一样按位来使用引脚的,比如说点灯程序中我们就可以P0.4=1 ;P0.4=0 ;来控制P0.4引脚的输出电平。特别是对于寄存器的配置直接写
PU4 = 0xff
PMC0 =0x00
就行了,但是问题是P0.4, PU4, PMC0 的声明在哪呢?它们如何与具体芯片的地址对应呢?我找了一圈没找到,后来看了瑞萨的官方文档才知道原来所有的秘密都在#pragma sfr 这句话中,也就是加上这句话就把P0.4, PU4等的声明全部包含了,个人猜想瑞萨是把这些申请都包含在了库中,通过预处理来引入这些库。以前一直以为欧美的IC库封装都很好,但其至少还要包含一个头文件。而瑞萨只需要引入一个预编译命令即可。现在看来一山还比一山高,不得不佩服。
0.png




部分测试代码:
  1. *******************************************************************************
  2. **  Include files
  3. *******************************************************************************
  4. */
  5. #pragma interrupt INTTM00 interrupt_inttm00
  6. #pragma interrupt INTTM01 interrupt_inttm01
  7. #pragma interrupt INTTM01H interrupt_inttm01h

  8. #include "common.h"

  9. /*
  10. *******************************************************************************
  11. **  Global declaration
  12. *******************************************************************************
  13. */
  14. void main(void);
  15. void IO_Init(void);
  16. void TAU0_PWM_Init(void);
  17. void TAU0_Start(void);
  18. void TAU0_Stop(void);

  19. unsigned long cnt[3];
  20. unsigned short breath;
  21. unsigned char breath_dir;

  22. /*
  23. **---------------------------------------------------------------------
  24. **        Abstract: This function  implements main function.
  25. **        Parameters: None
  26. **        Returns: None
  27. **---------------------------------------------------------------------
  28. */
  29. void main(void)
  30. {        
  31.         unsigned char mode;
  32.         
  33.         cnt[0] = 0;
  34.         cnt[1] = 0;
  35.         cnt[2] = 0;
  36.         
  37.         breath = 0;
  38.         breath_dir = 0;
  39.         
  40.         /* I/O Port Init */
  41.         IO_Init();
  42.         
  43.         /* TAU0 Timer Init */
  44.         TAU0_PWM_Init();
  45.         /* Enable Interrupt */
  46.         EI();
  47.         /* Start Timer, i.e. PWM output */
  48.         TAU0_Start();

  49.         mode = 1;
  50.         /* Program Loop */
  51.         while(1)
  52.         {
  53.                 if (P13.7 == 0)
  54.                 {
  55.                         if (mode)
  56.                         {
  57.                                 mode = 0;
  58.                                 TAU0_Stop();
  59.                         }
  60.                 }
  61.                 else
  62.                 {
  63.                         if (mode == 0)
  64.                         {
  65.                                 mode = 1;
  66.                                 TAU0_Start();
  67.                         }
  68.                 }

  69.         } /* while(1) */
  70. }

  71. /*
  72. **---------------------------------------------------------------------
  73. **        Abstract: This function  implements I/O port initialization.
  74. **        Parameters: None
  75. **        Returns: None
  76. **---------------------------------------------------------------------
  77. */
  78. void IO_Init(void)
  79. {
  80.         /* Port Mode '0'=Out, '1'=In */
  81.         PM0 = 0x01;
  82.         PM4 = 0x00;
  83.         /* Port Register */
  84.         P0 = 0x00;
  85.         P4 = 0x00;
  86.         /* Pull-up resistor */
  87.         PU0 = 0x00;
  88.         PU4 = 0x00;
  89.         PU12 = 0x00;
  90.         /* Port output mode '1'=open-drain */
  91.         POM0 = 0x03;
  92.         /* Port mode control '0'=I/O, '1'=AIN*/
  93.         PMC0 = 0xE1;
  94.         /* Peripheral I/O redirection */
  95.         PIOR = 0x00;
  96. }

  97. /*
  98. **---------------------------------------------------------------------
  99. **        Abstract: This function start the timer.
  100. **        Parameters: None
  101. **        Returns: None
  102. **---------------------------------------------------------------------
  103. */
  104. void TAU0_Start(void)
  105. {
  106.         TMIF00 = 0U;                /* clear INTTM00 interrupt flag */
  107.         TMMK00 = 0U;                /* enable INTTM00 interrupt */
  108.         TMIF01 = 0U;                /* clear INTTM01 interrupt flag */
  109.         TMMK01 = 0U;                /* enable INTTM01 interrupt */
  110.         TOE0 |= 0x03U;                /* enable CH1 output */
  111.         TS0 = 0x03U;                /* Trigger CH0 start */
  112. }

  113. /*
  114. **---------------------------------------------------------------------
  115. **        Abstract: This function stop the timer.
  116. **        Parameters: None
  117. **        Returns: None
  118. **---------------------------------------------------------------------
  119. */
  120. void TAU0_Stop(void)
  121. {
  122.         TT0 |= 0x03;                /* Trigger CH0, CH1 to stop */
  123.         TOE0 &= ~0x02;                /* disable CH1 output */
  124.         TMMK00 = 1U;                /* disable INTTM00 interrupt */
  125.         TMIF00 = 0U;                /* clear INTTM00 interrupt flag */
  126.         TMMK01 = 1U;                /* disable INTTM01 interrupt */
  127.         TMIF01 = 0U;                /* clear INTTM01 interrupt flag */
  128. }

  129. /*
  130. **---------------------------------------------------------------------
  131. **        Abstract        : This function implements timer initialization for PWM output.
  132. **        Parameters        : None
  133. **        Returns                : None
  134. **  Remark                : Set PWM frequency = 1KHz,
  135. **---------------------------------------------------------------------
  136. */
  137. void TAU0_PWM_Init(void)
  138. {
  139.     TAU0EN = 1;                    /* supplies input clock */
  140.     TPS0 = 0x0F;                /* CK01=fclk, CK00=fclk/2^15 */

  141.     /* Stop all channels */
  142.     TT0 = 0x00U;

  143.         /* Mask channel 0 interrupt */
  144.     TMMK00 = 1U;    /* disable INTTM00 interrupt */
  145.     TMIF00 = 0U;    /* clear INTTM00 interrupt flag */
  146.     /* Mask channel 1 interrupt */
  147.     TMMK01 = 1U;    /* disable INTTM01 interrupt */
  148.     TMIF01 = 0U;    /* clear INTTM01 interrupt flag */
  149.     /* Mask channel 1 higher 8 bits interrupt */
  150.     TMMK01H = 1U;    /* disable INTTM01H interrupt */
  151.     TMIF01H = 0U;    /* clear INTTM01H interrupt flag */
  152.     /* Set INTTM00 low priority */
  153.     TMPR100 = 1U;
  154.     TMPR000 = 1U;

  155.     /* Channel 0 is used as master channel for PWM output function */
  156.         TMR00H = 0x80U;                /* CK01 */
  157.         TMR00L = 0x01U;
  158. #if 0
  159.         TDR00H = 0x13U;                /* TDR00 = 4999+1 (0x1387H+1), 1KHz */
  160.         TDR00L = 0x87U;
  161. #else
  162.         TDR00H = 0x1FU;                /* TDR00 = 8191+1 (0x1fffH+1), ~610Hz */
  163.         TDR00L = 0xFFU;
  164. #endif
  165.         TOL0 &= ~0x01;
  166.         TO0 &= ~0x01;
  167.     TOE0 |= ~0x01;
  168.         
  169.     /* Channel 1 is used as slave channel for PWM output function */        
  170.         TMR01H = 0x84U;                /* CK01 */
  171.         TMR01L = 0x09U;
  172. #if 0        
  173.         TDR01H = 0x03U;                /* TDR01 set duty ratio of TDR00 */
  174.         TDR01L = 0xE7U;                /* TDR01 = 999+1 (0x03E7+1), 20% Duty ratio */
  175. #else
  176.         TDR01H = 0x00U;               
  177.         TDR01L = 0x00U;               
  178. #endif
  179.     TOM0 = 0x02U;
  180.     TO0 &= ~0x02;
  181.     TO0 |= 0x02U;
  182.     TOE0 |= 0x02U;        
  183.         TOL0 = 0x02U;

  184.     /* Set TO00, TO01 pin */
  185.     P0 &= 0xE7U;
  186.     PM0 &= 0xE7U;
  187. }


  188. /*
  189. **---------------------------------------------------------------------
  190. **        Abstract: This function implements timer interrupt.
  191. **        Parameters: None
  192. **        Returns: None
  193. **---------------------------------------------------------------------
  194. */
  195. __interrupt void interrupt_inttm00(){
  196.         cnt[0]++;
  197.         if (breath_dir == 0)
  198.         {
  199.                 /* dimm on */
  200.                 if (breath <= 0x1fff)
  201.                 {
  202.                         breath += 0x10;        
  203.                 }
  204.                 else
  205.                 {
  206.                         breath = 0x2000;
  207.                         breath_dir = 1;
  208.                 }
  209.                
  210.         }
  211.         else
  212.         {
  213.                 /* dimm off */
  214.                 if (breath > 0)
  215.                 {
  216.                         breath -= 0x100;        
  217.                 }
  218.                 else
  219.                 {
  220.                         breath = 0;
  221.                         breath_dir = 0;
  222.                 }
  223.         }
  224.         TDR01H = (unsigned char)(breath>>8);               
  225.         TDR01L = (unsigned char)(breath&0x00ff);        
  226. }

  227. /*
  228. **---------------------------------------------------------------------
  229. **        Abstract: This function implements timer interrupt.
  230. **        Parameters: None
  231. **        Returns: None
  232. **---------------------------------------------------------------------
  233. */
  234. __interrupt void interrupt_inttm01(){
  235.         cnt[1]++;
  236. }

  237. /*
  238. **---------------------------------------------------------------------
  239. **        Abstract: This function implements timer interrupt.
  240. **        Parameters: None
  241. **        Returns: None
  242. **---------------------------------------------------------------------
  243. */
  244. __interrupt void interrupt_inttm01h(){
  245.         cnt[2]++;
  246. }
复制代码

0.png


全部资料下载:

NEC78K0单片机常用的C语言扩展功能20090416.pdf

1.83 MB, 下载次数: 5, 下载积分: 黑币 -5

R7F0C80212目标板原理图.PDF

204.96 KB, 下载次数: 6, 下载积分: 黑币 -5

测试代码.zip

1.49 MB, 下载次数: 9, 下载积分: 黑币 -5

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表