C51 COMPILER V9.60.0.0 TIMER 03/23/2023 16:31:25 PAGE 1 C51 COMPILER V9.60.0.0, COMPILATION OF MODULE TIMER OBJECT MODULE PLACED IN .\Objects\timer.obj COMPILER INVOKED BY: d:\Keil_v5\C51\BIN\C51.EXE mycode\timer.c OPTIMIZE(8,SPEED) BROWSE INCDIR(.\myinc) DEBUG OBJECTEXTE -ND PRINT(.\Listings\timer.lst) TABS(2) OBJECT(.\Objects\timer.obj) line level source 1 /*---------------------------------------------------------------------*/ 2 /* --- STC MCU Limited ------------------------------------------------*/ 3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/ 4 /* --- Mobile: (86)13922805190 ----------------------------------------*/ 5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/ 6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/ 7 /* --- Web: www.STCMCU.com --------------------------------------------*/ 8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/ 9 /* --- QQ: 800003751 -------------------------------------------------*/ 10 /* Èç¹ûÒªÔÚ³ÌÐòÖÐʹÓô˴úÂë,ÇëÔÚ³ÌÐòÖÐ×¢Ã÷ʹÓÃÁËSTCµÄ×ÊÁϼ°³ÌÐò */ 11 /*---------------------------------------------------------------------*/ 12 13 /************* ¹¦ÄÜ˵Ã÷ ************** 14 15 ±¾ÎļþΪSTC8ϵÁеĶ¨Ê±Æ÷³õʼ»¯ºÍÖжϳÌÐò,Óû§¿ÉÒÔÔÚÕâ¸öÎļþÖÐÐÞ¸Ä×Ô¼ºÐèÒªµÄÖжϳÌÐò. 16 17 ******************************************/ 18 19 #include "timer.h" 20 #include "GPIO.h" 21 #include "common.h" 22 u32 timex; 23 static u16 displaytime = 0; 24 u8 displaydata = 0; 25 /********************* Timer0ÖжϺ¯Êý************************/ 26 void timer0_int(void) interrupt TIMER0_VECTOR 27 { 28 1 if (sunmode == 3) 29 1 { 30 2 if (timex <= 400 << subdivision3) 31 2 DIR = 0; 32 2 } 33 1 if (timex <= 0) 34 1 timex = 0; 35 1 else 36 1 { 37 2 38 2 if (pog == 1) 39 2 { 40 3 timex--; 41 3 PUL = ~PUL; 42 3 } 43 2 } 44 1 } 45 46 /********************* Timer1ÖжϺ¯Êý************************/ 47 void timer1_int(void) interrupt TIMER1_VECTOR 48 { 49 1 } 50 51 /********************* Timer2ÖжϺ¯Êý************************/ 52 void timer2_int(void) interrupt TIMER2_VECTOR 53 { 54 1 displaytime++; C51 COMPILER V9.60.0.0 TIMER 03/23/2023 16:31:25 PAGE 2 55 1 if (displaytime >= 200) 56 1 { 57 2 if (DIR) 58 2 { 59 3 if (displaydata >= 7) 60 3 displaydata = 0; 61 3 else 62 3 displaydata++; 63 3 } 64 2 else 65 2 { 66 3 if (displaydata <= 0) 67 3 displaydata = 7; 68 3 else 69 3 displaydata--; 70 3 } 71 2 displaytime = 0; 72 2 } 73 1 if (keyflag) 74 1 keytime++; 75 1 else 76 1 keytime = 0; 77 1 } 78 79 /********************* Timer3ÖжϺ¯Êý************************/ 80 void timer3_int(void) interrupt TIMER3_VECTOR 81 { 82 1 } 83 84 /********************* Timer4ÖжϺ¯Êý************************/ 85 void timer4_int(void) interrupt TIMER4_VECTOR 86 { 87 1 } 88 89 //======================================================================== 90 // º¯Êý: u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx) 91 // ÃèÊö: ¶¨Ê±Æ÷³õʼ»¯³ÌÐò. 92 // ²ÎÊý: TIMx: ½á¹¹²ÎÊý,Çë²Î¿¼timer.hÀïµÄ¶¨Òå. 93 // ·µ»Ø: ³É¹¦·µ»Ø0, ¿Õ²Ù×÷·µ»Ø1,´íÎó·µ»Ø2. 94 // °æ±¾: V1.0, 2012-10-22 95 //======================================================================== 96 u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx) 97 { 98 1 if (TIM > Timer4) 99 1 return 1; // ¿Õ²Ù×÷ 100 1 101 1 if (TIM == Timer0) 102 1 { 103 2 Timer0_Stop(); // Í£Ö¹¼ÆÊý 104 2 if (TIMx->TIM_Interrupt == ENABLE) 105 2 Timer0_InterruptEnable(); // ÔÊÐíÖÐ¶Ï 106 2 else 107 2 Timer0_InterruptDisable(); // ½ûÖ¹ÖÐ¶Ï 108 2 if (TIMx->TIM_Priority > Priority_3) 109 2 return 2; // ´íÎó 110 2 Timer0_Priority(TIMx->TIM_Priority); // Ö¸¶¨ÖжÏÓÅÏȼ¶(µÍµ½¸ß) Priority_0,Priority_1,Priority_2,Pr -iority_3 111 2 112 2 if (TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) 113 2 return 2; // ´íÎó 114 2 TMOD = (TMOD & ~0x03) | TIMx->TIM_Mode; // ¹¤×÷ģʽ,0: 16λ×Ô¶¯ÖØ×°, 1: 16λ¶¨Ê±/¼ÆÊý, 2: 8λ×Ô¶¯Ö -Ø×°, 3: ²»¿ÉÆÁ±Î16λ×Ô¶¯ÖØ×° C51 COMPILER V9.60.0.0 TIMER 03/23/2023 16:31:25 PAGE 3 115 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_12T) 116 2 Timer0_12T(); // 12T 117 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_1T) 118 2 Timer0_1T(); // 1T 119 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext) 120 2 Timer0_AsCounter(); // ¶ÔÍâ¼ÆÊý»ò·ÖƵ 121 2 else 122 2 Timer0_AsTimer(); // ¶¨Ê± 123 2 if (TIMx->TIM_ClkOut == ENABLE) 124 2 Timer0_CLKO_Enable(); // Êä³öʱÖÓ 125 2 else 126 2 Timer0_CLKO_Disable(); // ²»Êä³öʱÖÓ 127 2 128 2 T0_Load(TIMx->TIM_Value); 129 2 if (TIMx->TIM_Run == ENABLE) 130 2 Timer0_Run(); // ¿ªÊ¼ÔËÐÐ 131 2 return 0; // ³É¹¦ 132 2 } 133 1 134 1 if (TIM == Timer1) 135 1 { 136 2 Timer1_Stop(); // Í£Ö¹¼ÆÊý 137 2 if (TIMx->TIM_Interrupt == ENABLE) 138 2 Timer1_InterruptEnable(); // ÔÊÐíÖÐ¶Ï 139 2 else 140 2 Timer1_InterruptDisable(); // ½ûÖ¹ÖÐ¶Ï 141 2 if (TIMx->TIM_Priority > Priority_3) 142 2 return 2; // ´íÎó 143 2 Timer1_Priority(TIMx->TIM_Priority); // Ö¸¶¨ÖжÏÓÅÏȼ¶(µÍµ½¸ß) Priority_0,Priority_1,Priority_2,Pr -iority_3 144 2 if (TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) 145 2 return 2; // ´íÎó 146 2 TMOD = (TMOD & ~0x30) | (TIMx->TIM_Mode << 4); // ¹¤×÷ģʽ,0: 16λ×Ô¶¯ÖØ×°, 1: 16λ¶¨Ê±/¼ÆÊý, 2: 8 -λ×Ô¶¯ÖØ×°, 3: Í£Ö¹¹¤×÷ 147 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_12T) 148 2 Timer1_12T(); // 12T 149 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_1T) 150 2 Timer1_1T(); // 1T 151 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext) 152 2 Timer1_AsCounter(); // ¶ÔÍâ¼ÆÊý»ò·ÖƵ 153 2 else 154 2 Timer1_AsTimer(); // ¶¨Ê± 155 2 if (TIMx->TIM_ClkOut == ENABLE) 156 2 Timer1_CLKO_Enable(); // Êä³öʱÖÓ 157 2 else 158 2 Timer1_CLKO_Disable(); // ²»Êä³öʱÖÓ 159 2 160 2 T1_Load(TIMx->TIM_Value); 161 2 if (TIMx->TIM_Run == ENABLE) 162 2 Timer1_Run(); // ¿ªÊ¼ÔËÐÐ 163 2 return 0; // ³É¹¦ 164 2 } 165 1 166 1 if (TIM == Timer2) // Timer2,¹Ì¶¨Îª16λ×Ô¶¯ÖØ×°, ÖжÏÎÞÓÅÏȼ¶ 167 1 { 168 2 Timer2_Stop(); // Í£Ö¹¼ÆÊý 169 2 if (TIMx->TIM_Interrupt == ENABLE) 170 2 Timer2_InterruptEnable(); // ÔÊÐíÖÐ¶Ï 171 2 else 172 2 Timer2_InterruptDisable(); // ½ûÖ¹ÖÐ¶Ï 173 2 if (TIMx->TIM_ClkSource > TIM_CLOCK_Ext) 174 2 return 2; C51 COMPILER V9.60.0.0 TIMER 03/23/2023 16:31:25 PAGE 4 175 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_12T) 176 2 Timer2_12T(); // 12T 177 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_1T) 178 2 Timer2_1T(); // 1T 179 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext) 180 2 Timer2_AsCounter(); // ¶ÔÍâ¼ÆÊý»ò·ÖƵ 181 2 else 182 2 Timer2_AsTimer(); // ¶¨Ê± 183 2 if (TIMx->TIM_ClkOut == ENABLE) 184 2 Timer2_CLKO_Enable(); // Êä³öʱÖÓ 185 2 else 186 2 Timer2_CLKO_Disable(); // ²»Êä³öʱÖÓ 187 2 188 2 T2_Load(TIMx->TIM_Value); 189 2 if (TIMx->TIM_Run == ENABLE) 190 2 Timer2_Run(); // ¿ªÊ¼ÔËÐÐ 191 2 return 0; // ³É¹¦ 192 2 } 193 1 194 1 if (TIM == Timer3) // Timer3,¹Ì¶¨Îª16λ×Ô¶¯ÖØ×°, ÖжÏÎÞÓÅÏȼ¶ 195 1 { 196 2 Timer3_Stop(); // Í£Ö¹¼ÆÊý 197 2 if (TIMx->TIM_Interrupt == ENABLE) 198 2 Timer3_InterruptEnable(); // ÔÊÐíÖÐ¶Ï 199 2 else 200 2 Timer3_InterruptDisable(); // ½ûÖ¹ÖÐ¶Ï 201 2 if (TIMx->TIM_ClkSource > TIM_CLOCK_Ext) 202 2 return 2; 203 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_12T) 204 2 Timer3_12T(); // 12T 205 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_1T) 206 2 Timer3_1T(); // 1T 207 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext) 208 2 Timer3_AsCounter(); // ¶ÔÍâ¼ÆÊý»ò·ÖƵ 209 2 else 210 2 Timer3_AsTimer(); // ¶¨Ê± 211 2 if (TIMx->TIM_ClkOut == ENABLE) 212 2 Timer3_CLKO_Enable(); // Êä³öʱÖÓ 213 2 else 214 2 Timer3_CLKO_Disable(); // ²»Êä³öʱÖÓ 215 2 216 2 T3_Load(TIMx->TIM_Value); 217 2 if (TIMx->TIM_Run == ENABLE) 218 2 Timer3_Run(); // ¿ªÊ¼ÔËÐÐ 219 2 return 0; // ³É¹¦ 220 2 } 221 1 222 1 if (TIM == Timer4) // Timer3,¹Ì¶¨Îª16λ×Ô¶¯ÖØ×°, ÖжÏÎÞÓÅÏȼ¶ 223 1 { 224 2 Timer4_Stop(); // Í£Ö¹¼ÆÊý 225 2 if (TIMx->TIM_Interrupt == ENABLE) 226 2 Timer4_InterruptEnable(); // ÔÊÐíÖÐ¶Ï 227 2 else 228 2 Timer4_InterruptDisable(); // ½ûÖ¹ÖÐ¶Ï 229 2 if (TIMx->TIM_ClkSource > TIM_CLOCK_Ext) 230 2 return 2; 231 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_12T) 232 2 Timer4_12T(); // 12T 233 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_1T) 234 2 Timer4_1T(); // 1T 235 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext) 236 2 Timer4_AsCounter(); // ¶ÔÍâ¼ÆÊý»ò·ÖƵ C51 COMPILER V9.60.0.0 TIMER 03/23/2023 16:31:25 PAGE 5 237 2 else 238 2 Timer4_AsTimer(); // ¶¨Ê± 239 2 if (TIMx->TIM_ClkOut == ENABLE) 240 2 Timer4_CLKO_Enable(); // Êä³öʱÖÓ 241 2 else 242 2 Timer4_CLKO_Disable(); // ²»Êä³öʱÖÓ 243 2 244 2 T4_Load(TIMx->TIM_Value); 245 2 if (TIMx->TIM_Run == ENABLE) 246 2 Timer4_Run(); // ¿ªÊ¼ÔËÐÐ 247 2 return 0; // ³É¹¦ 248 2 } 249 1 return 2; // ´íÎó 250 1 } 251 /************************ ?¡§?¡À?¡Â???? ****************************/ 252 void Timer_config(void) 253 { 254 1 TIM_InitTypeDef TIM_InitStructure; //?¨¢???¡§?? 255 1 TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload; //???¡§?¡è¡Á¡Â????, TIM_16BitAutoRel -oad,TIM_16Bit,TIM_8BitAutoReload,TIM_16BitAutoReloadNoMask 256 1 TIM_InitStructure.TIM_Priority = Priority_0; //???¡§??????????(??????) Priority_0,P -riority_1,Priority_2,Priority_3 257 1 TIM_InitStructure.TIM_Interrupt = ENABLE; //??????¡¤????¨ª, ENABLE?¨°DISABLE 258 1 TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_1T; //???¡§?¡À????, TIM_CLOCK_1T,TIM_C -LOCK_12T,TIM_CLOCK_Ext 259 1 TIM_InitStructure.TIM_ClkOut = DISABLE; //??¡¤?????????????, ENABLE?¨°DISABLE 260 1 TIM_InitStructure.TIM_Value = 65536UL - (MAIN_Fosc / 100000UL); //????, 261 1 TIM_InitStructure.TIM_Run = ENABLE; //??¡¤????????¨®?????¡§?¡À?¡Â, ENABLE? -¨°DISABLE 262 1 Timer_Inilize(Timer0, &TIM_InitStructure); //??????Timer0 Timer0,Timer1,Timer2, -Timer3,Timer4 263 1 264 1 TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_1T; //???¡§?¡À????, TIM_CLOCK_1T,TIM_CLO -CK_12T,TIM_CLOCK_Ext 265 1 TIM_InitStructure.TIM_ClkOut = DISABLE; //??¡¤?????????????, ENABLE?¨°DISABLE 266 1 TIM_InitStructure.TIM_Value = 65536UL - (MAIN_Fosc / 1000UL); //????, 267 1 TIM_InitStructure.TIM_Run = ENABLE; //??¡¤????????¨®?????¡§?¡À?¡Â, ENABLE?¨° -DISABLE 268 1 Timer_Inilize(Timer2, &TIM_InitStructure); 269 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 1127 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 7 8 IDATA SIZE = ---- ---- BIT SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)