[DemoCode下载] N76E003的时钟信号还可以输出

[复制链接]
1920|12
 楼主| gejigeji521 发表于 2017-9-28 19:30 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2016 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2016
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 Clock Output demo code
  14. //***********************************************************************************************************

  15. #include <stdio.h>
  16. #include "N76E003.h"
  17. #include "Common.h"
  18. #include "Delay.h"
  19. #include "SFR_Macro.h"
  20. #include "Function_define.h"


  21. //======================================================================================================

  22. void main(void)
  23. {
  24.        
  25.     /* Note
  26.        MCU power on system clock is HIRC (16.0000MHz), if need change Fsys source pleaes copy hange system closk source demo
  27.     */
  28.    
  29.                 Set_All_GPIO_Quasi_Mode;                    //in Function_define.h
  30.     set_CLOEN;                                  //System Clock Output Enable
  31. //     Please measure P1.1 (CLO) pin for system clock output, it should as system clock;

  32.     while(1)
  33.     {
  34.         clr_GPIO1;
  35.         Timer0_Delay1ms(500);
  36.         set_GPIO1;
  37.         Timer0_Delay1ms(500);
  38.     }
  39. /* =================== */
  40. }


 楼主| gejigeji521 发表于 2017-9-28 19:31 | 显示全部楼层
把时钟信号输出来,可以做很多事。
 楼主| gejigeji521 发表于 2017-9-28 19:36 | 显示全部楼层
其实就是通过IO输出高电平和低电平。。
huangcunxiake 发表于 2017-9-30 20:21 | 显示全部楼层
貌似就是输出0,然后输出1,然后循环。以为配置好,自动输出呢。
598330983 发表于 2017-10-1 21:12 来自手机 | 显示全部楼层
这个延时函数我要好好研究一下
734774645 发表于 2017-10-2 10:55 来自手机 | 显示全部楼层
原来是这种,把我吸引进来,如果有配置好,不用操作就可以的就更好了
xinpian101 发表于 2017-10-2 22:45 来自手机 | 显示全部楼层
利用定时器写的吧,有个疑问,定时器不配置,那么默认情况是运行的吗?
dongnanxibei 发表于 2017-10-3 10:54 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2016 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2016
  11. //***********************************************************************************************************

  12. #include "N76E003.h"
  13. #include "Common.h"
  14. #include "Delay.h"
  15. #include "SFR_Macro.h"
  16. #include "Function_define.h"
  17. bit BIT_TMP;

  18. //-------------------------------------------------------------------------
  19. void Timer0_Delay100us(UINT32 u32CNT)
  20. {
  21.     clr_T0M;                                                //T0M=0, Timer0 Clock = Fsys/12
  22.     TMOD |= 0x01;                                           //Timer0 is 16-bit mode
  23.     set_TR0;                                                //Start Timer0
  24.     while (u32CNT != 0)
  25.     {
  26.         TL0 = LOBYTE(TIMER_DIV12_VALUE_100us);        //Find  define in "Function_define.h" "TIMER VALUE"
  27.         TH0 = HIBYTE(TIMER_DIV12_VALUE_100us);
  28.         while (TF0 != 1);                                   //Check Timer0 Time-Out Flag
  29.         clr_TF0;
  30.         u32CNT --;
  31.     }
  32.     clr_TR0;                                                       //Stop Timer0
  33. }
  34. //------------------------------------------------------------------------------
  35. void Timer0_Delay1ms(UINT32 u32CNT)
  36. {
  37.     clr_T0M;                                                //T0M=0, Timer0 Clock = Fsys/12
  38.     TMOD |= 0x01;                                           //Timer0 is 16-bit mode
  39.     set_TR0;                                                //Start Timer0
  40.     while (u32CNT != 0)
  41.     {
  42.         TL0 = LOBYTE(TIMER_DIV12_VALUE_1ms);                 //Find  define in "Function_define.h" "TIMER VALUE"
  43.         TH0 = HIBYTE(TIMER_DIV12_VALUE_1ms);
  44.         while (TF0 != 1);                                   //Check Timer0 Time-Out Flag
  45.         clr_TF0;
  46.         u32CNT --;
  47.     }
  48.     clr_TR0;                                                //Stop Timer0
  49. }

  50. //------------------------------------------------------------------------------
  51. void Timer1_Delay10ms(UINT32 u32CNT)
  52. {
  53.     clr_T1M;                                                                                                                                                //T1M=0, Timer1 Clock = Fsys/12
  54.     TMOD |= 0x10;                                                                                                                                //Timer1 is 16-bit mode
  55.     set_TR1;                                                                                                                                                //Start Timer1
  56.     while (u32CNT != 0)
  57.     {
  58.         TL1 = LOBYTE(TIMER_DIV12_VALUE_10ms);                //Find  define in "Function_define.h" "TIMER VALUE"
  59.         TH1 = HIBYTE(TIMER_DIV12_VALUE_10ms);
  60.         while (TF1 != 1);                                                                                                //Check Timer1 Time-Out Flag
  61.         clr_TF1;
  62.         u32CNT --;
  63.     }
  64.     clr_TR1;                                                       //Stop Timer1
  65. }
  66. //------------------------------------------------------------------------------
  67. void Timer2_Delay500us(UINT32 u32CNT)
  68. {
  69.     clr_T2DIV2;                                                                                                                                        //Timer2 Clock = Fsys/4
  70.     clr_T2DIV1;
  71.     set_T2DIV0;
  72.     set_TR2;                                                //Start Timer2
  73.     while (u32CNT != 0)
  74.     {
  75.         TL2 = LOBYTE(TIMER_DIV4_VALUE_500us);                //Find  define in "Function_define.h" "TIMER VALUE"
  76.         TH2 = HIBYTE(TIMER_DIV4_VALUE_500us);
  77.         while (TF2 != 1);                                   //Check Timer2 Time-Out Flag
  78.         clr_TF2;
  79.         u32CNT --;
  80.     }
  81.     clr_TR2;                                                //Stop Timer2
  82. }
  83. //------------------------------------------------------------------------------
  84. void Timer3_Delay100ms(UINT32 u32CNT)
  85. {
  86.     T3CON = 0x07;                                           //Timer3 Clock = Fsys/128
  87.     set_TR3;                                                //Trigger Timer3
  88.     while (u32CNT != 0)
  89.     {
  90.         RL3 = LOBYTE(TIMER_DIV128_VALUE_100ms); //Find  define in "Function_define.h" "TIMER VALUE"
  91.         RH3 = HIBYTE(TIMER_DIV128_VALUE_100ms);
  92.         while ((T3CON&SET_BIT4) != SET_BIT4);                //Check Timer3 Time-Out Flag
  93.         clr_TF3;
  94.         u32CNT --;
  95.     }
  96.     clr_TR3;                                                //Stop Timer3
  97. }
  98. //------------------------------------------------------------------------------
  99. void Timer3_Delay10us(UINT32 u32CNT)
  100. {
  101.     T3CON = 0x07;                                           //Timer3 Clock = Fsys/128
  102.     set_TR3;                                                //Trigger Timer3
  103.     while (u32CNT != 0)
  104.     {
  105.         RL3 = LOBYTE(TIMER_DIV4_VALUE_10us); //Find  define in "Function_define.h" "TIMER VALUE"
  106.         RH3 = HIBYTE(TIMER_DIV4_VALUE_10us);
  107.         while ((T3CON&SET_BIT4) != SET_BIT4);                //Check Timer3 Time-Out Flag
  108.         clr_TF3;
  109.         u32CNT --;
  110.     }
  111.     clr_TR3;                                                //Stop Timer3
  112. }
捉虫天师 发表于 2017-10-4 12:25 来自手机 | 显示全部楼层
虽然这些库函数看着不知道怎么实现,有时候自己能力差理解不了
zhuomuniao110 发表于 2017-10-5 14:25 | 显示全部楼层
延时函数怎么没有讲在什么主频下,什么晶振都可以吗
jiekou001 发表于 2017-10-5 23:00 | 显示全部楼层
输出的这个可以接个LED灯泡显示。
heisexingqisi 发表于 2017-10-6 13:33 | 显示全部楼层
其实我们关心的就是延时函数能否适应时钟的变化。
wahahaheihei 发表于 2017-10-6 13:36 | 显示全部楼层
清零和置位都是宏实现的,方便不少
您需要登录后才可以回帖 登录 | 注册

本版积分规则

196

主题

2465

帖子

8

粉丝
快速回复 在线客服 返回列表 返回顶部