ad657e6b6f501b818f2ef13eb57477bade75a77f.svn-base 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /* */
  3. /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved. */
  4. /* */
  5. /*---------------------------------------------------------------------------------------------------------*/
  6. //***********************************************************************************************************
  7. // Website: http://www.nuvoton.com
  8. // E-Mail : [email protected]
  9. // Date : Jan/21/2017
  10. //***********************************************************************************************************
  11. #include "Common.h"
  12. #include "Delay.h"
  13. uint8 BIT_TMP;
  14. //-------------------------------------------------------------------------
  15. void Timer0_Delay100us ( uint32 u32CNT )
  16. {
  17. clr_T0M; //T0M=0, Timer0 Clock = Fsys/12
  18. TMOD |= 0x01; //Timer0 is 16-bit mode
  19. set_TR0; //Start Timer0
  20. while ( u32CNT != 0 )
  21. {
  22. TL0 = LOBYTE ( TIMER_DIV12_VALUE_100us ); //Find define in "Function_define.h" "TIMER VALUE"
  23. TH0 = HIBYTE ( TIMER_DIV12_VALUE_100us );
  24. while ( TF0 != 1 ); //Check Timer0 Time-Out Flag
  25. clr_TF0;
  26. u32CNT --;
  27. }
  28. clr_TR0; //Stop Timer0
  29. }
  30. //------------------------------------------------------------------------------
  31. void Timer0_Delay1ms ( uint32 u32CNT )
  32. {
  33. clr_T0M; //T0M=0, Timer0 Clock = Fsys/12
  34. TMOD |= 0x01; //Timer0 is 16-bit mode
  35. set_TR0; //Start Timer0
  36. while ( u32CNT != 0 )
  37. {
  38. TL0 = LOBYTE ( TIMER_DIV12_VALUE_1ms ); //Find define in "Function_define.h" "TIMER VALUE"
  39. TH0 = HIBYTE ( TIMER_DIV12_VALUE_1ms );
  40. while ( TF0 != 1 ); //Check Timer0 Time-Out Flag
  41. clr_TF0;
  42. u32CNT --;
  43. }
  44. clr_TR0; //Stop Timer0
  45. }
  46. //------------------------------------------------------------------------------
  47. void Timer1_Delay10ms ( uint32 u32CNT )
  48. {
  49. clr_T1M; //T1M=0, Timer1 Clock = Fsys/12
  50. TMOD |= 0x10; //Timer1 is 16-bit mode
  51. set_TR1; //Start Timer1
  52. while ( u32CNT != 0 )
  53. {
  54. TL1 = LOBYTE ( TIMER_DIV12_VALUE_10ms ); //Find define in "Function_define.h" "TIMER VALUE"
  55. TH1 = HIBYTE ( TIMER_DIV12_VALUE_10ms );
  56. while ( TF1 != 1 ); //Check Timer1 Time-Out Flag
  57. clr_TF1;
  58. u32CNT --;
  59. }
  60. clr_TR1; //Stop Timer1
  61. }
  62. //------------------------------------------------------------------------------
  63. void Timer2_Delay500us ( uint32 u32CNT )
  64. {
  65. clr_T2DIV2; //Timer2 Clock = Fsys/4
  66. clr_T2DIV1;
  67. set_T2DIV0;
  68. set_TR2; //Start Timer2
  69. while ( u32CNT != 0 )
  70. {
  71. TL2 = LOBYTE ( TIMER_DIV4_VALUE_500us ); //Find define in "Function_define.h" "TIMER VALUE"
  72. TH2 = HIBYTE ( TIMER_DIV4_VALUE_500us );
  73. while ( TF2 != 1 ); //Check Timer2 Time-Out Flag
  74. clr_TF2;
  75. u32CNT --;
  76. }
  77. clr_TR2; //Stop Timer2
  78. }
  79. //------------------------------------------------------------------------------
  80. void Timer3_Delay100ms ( uint32 u32CNT )
  81. {
  82. T3CON = 0x07; //Timer3 Clock = Fsys/128
  83. set_TR3; //Trigger Timer3
  84. while ( u32CNT != 0 )
  85. {
  86. RL3 = LOBYTE ( TIMER_DIV128_VALUE_100ms ); //Find define in "Function_define.h" "TIMER VALUE"
  87. RH3 = HIBYTE ( TIMER_DIV128_VALUE_100ms );
  88. while ( ( T3CON & SET_BIT4 ) != SET_BIT4 ); //Check Timer3 Time-Out Flag
  89. clr_TF3;
  90. u32CNT --;
  91. }
  92. clr_TR3; //Stop Timer3
  93. }
  94. //------------------------------------------------------------------------------
  95. void Timer3_Delay10us ( uint32 u32CNT )
  96. {
  97. T3CON = 0x02; //Timer3 Clock = Fsys/4
  98. set_TR3; //Trigger Timer3
  99. while ( u32CNT != 0 )
  100. {
  101. RL3 = LOBYTE ( TIMER_DIV4_VALUE_10us ); //Find define in "Function_define.h" "TIMER VALUE"
  102. RH3 = HIBYTE ( TIMER_DIV4_VALUE_10us );
  103. while ( ( T3CON & SET_BIT4 ) != SET_BIT4 ); //Check Timer3 Time-Out Flag
  104. clr_TF3;
  105. u32CNT --;
  106. }
  107. clr_TR3; //Stop Timer3
  108. }
  109. //------------------------------------------------------------------------------
  110. #define TIMER_DIV4_VALUE_1us 65536-4 //4*4/16000000 = 1 uS, // Timer divider = 4 for TM2/TM3
  111. void Timer3_Delay1us ( uint32 u32CNT )
  112. {
  113. T3CON = 0x02; //Timer3 Clock = Fsys/4
  114. set_TR3; //Trigger Timer3
  115. while ( u32CNT != 0 )
  116. {
  117. RL3 = LOBYTE ( TIMER_DIV4_VALUE_1us ); //Find define in "Function_define.h" "TIMER VALUE"
  118. RH3 = HIBYTE ( TIMER_DIV4_VALUE_1us );
  119. while ( ( T3CON & SET_BIT4 ) != SET_BIT4 ); //Check Timer3 Time-Out Flag
  120. clr_TF3;
  121. u32CNT --;
  122. }
  123. clr_TR3; //Stop Timer3
  124. }
  125. //------------------------------------------------------------------------------
  126. void Timer3_Delay1ms ( uint32 u32CNT )
  127. {
  128. T3CON = 0x02; //Timer3 Clock = Fsys/4
  129. set_TR3; //Trigger Timer3
  130. while ( u32CNT != 0 )
  131. {
  132. RL3 = LOBYTE ( TIMER_DIV4_VALUE_1ms ); //Find define in "Function_define.h" "TIMER VALUE"
  133. RH3 = HIBYTE ( TIMER_DIV4_VALUE_1ms );
  134. while ( ( T3CON & SET_BIT4 ) != SET_BIT4 ); //Check Timer3 Time-Out Flag
  135. clr_TF3;
  136. u32CNT --;
  137. }
  138. clr_TR3; //Stop Timer3
  139. }