C51 COMPILER V9.59.0.0 TIMER 05/28/2021 11:23:08 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE TIMER OBJECT MODULE PLACED IN .\list\timer.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE timer.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\list\timer.l -st) TABS(2) OBJECT(.\list\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 21 /********************* Timer0中断函数************************/ 22 void timer0_int (void) interrupt TIMER0_VECTOR 23 { 24 1 P67 = ~P67; 25 1 } 26 27 /********************* Timer1中断函数************************/ 28 void timer1_int (void) interrupt TIMER1_VECTOR 29 { 30 1 P66 = ~P66; 31 1 } 32 33 /********************* Timer2中断函数************************/ 34 void timer2_int (void) interrupt TIMER2_VECTOR 35 { 36 1 P65 = ~P65; 37 1 } 38 39 /********************* Timer3中断函数************************/ 40 void timer3_int (void) interrupt TIMER3_VECTOR 41 { 42 1 P64 = ~P64; 43 1 } 44 45 /********************* Timer4中断函数************************/ 46 void timer4_int (void) interrupt TIMER4_VECTOR 47 { 48 1 P63 = ~P63; 49 1 } 50 51 52 //======================================================================== 53 // 函数: u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx) 54 // 描述: 定时器初始化程序. C51 COMPILER V9.59.0.0 TIMER 05/28/2021 11:23:08 PAGE 2 55 // 参数: TIMx: 结构参数,请参考timer.h里的定义. 56 // 返回: 成功返回0, 空操作返回1,错误返回2. 57 // 版本: V1.0, 2012-10-22 58 //======================================================================== 59 u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx) 60 { 61 1 if(TIM > Timer4) return 1; //空操作 62 1 63 1 if(TIM == Timer0) 64 1 { 65 2 Timer0_Stop(); //停止计数 66 2 if(TIMx->TIM_Interrupt == ENABLE) Timer0_InterruptEnable(); //允许中断 67 2 else Timer0_InterruptDisable(); //禁止中断 68 2 if(TIMx->TIM_Polity > Polity_3) return 2; //错误 69 2 Timer0_Polity(TIMx->TIM_Polity); //指定中断优先级(低到高) Polity_0,Polity_1,Polity_2,Polity_3 70 2 71 2 if(TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) return 2; //错误 72 2 TMOD = (TMOD & ~0x30) | TIMx->TIM_Mode; //工作模式,0: 16位自动重装, 1: 16位定时/计数, 2: 8位自动重装 73 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer0_12T(); //12T 74 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer0_1T(); //1T 75 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer0_AsCounter(); //对外计数或分频 76 2 else Timer0_AsTimer(); //定时 77 2 if(TIMx->TIM_ClkOut == ENABLE) Timer0_CLKO_Enable(); //输出时钟 78 2 else Timer0_CLKO_Disable(); //不输出时钟 79 2 80 2 T0_Load(TIMx->TIM_Value); 81 2 if(TIMx->TIM_Run == ENABLE) Timer0_Run(); //开始运行 82 2 return 0; //成功 83 2 } 84 1 85 1 if(TIM == Timer1) 86 1 { 87 2 Timer1_Stop(); //停止计数 88 2 if(TIMx->TIM_Interrupt == ENABLE) Timer1_InterruptEnable(); //允许中断 89 2 else Timer1_InterruptDisable(); //禁止中断 90 2 if(TIMx->TIM_Polity > Polity_3) return 2; //错误 91 2 Timer1_Polity(TIMx->TIM_Polity); //指定中断优先级(低到高) Polity_0,Polity_1,Polity_2,Polity_3 92 2 if(TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) return 2; //错误 93 2 TMOD = (TMOD & ~0x30) | TIMx->TIM_Mode; //工作模式,0: 16位自动重装, 1: 16位定时/计数, 2: 8位自动重装 94 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer1_12T(); //12T 95 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer1_1T(); //1T 96 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer1_AsCounter(); //对外计数或分频 97 2 else Timer1_AsTimer(); //定时 98 2 if(TIMx->TIM_ClkOut == ENABLE) Timer1_CLKO_Enable(); //输出时钟 99 2 else Timer1_CLKO_Disable(); //不输出时钟 100 2 101 2 T1_Load(TIMx->TIM_Value); 102 2 if(TIMx->TIM_Run == ENABLE) Timer1_Run(); //开始运行 103 2 return 0; //成功 104 2 } 105 1 106 1 if(TIM == Timer2) //Timer2,固定为16位自动重装, 中断无优先级 107 1 { 108 2 Timer2_Stop(); //停止计数 109 2 if(TIMx->TIM_Interrupt == ENABLE) Timer2_InterruptEnable(); //允许中断 110 2 else Timer2_InterruptDisable(); //禁止中断 111 2 if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2; 112 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer2_12T(); //12T 113 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer2_1T(); //1T 114 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer2_AsCounter(); //对外计数或分频 115 2 else Timer2_AsTimer(); //定时 116 2 if(TIMx->TIM_ClkOut == ENABLE) Timer2_CLKO_Enable(); //输出时钟 C51 COMPILER V9.59.0.0 TIMER 05/28/2021 11:23:08 PAGE 3 117 2 else Timer2_CLKO_Disable(); //不输出时钟 118 2 119 2 T2_Load(TIMx->TIM_Value); 120 2 if(TIMx->TIM_Run == ENABLE) Timer2_Run(); //开始运行 121 2 return 0; //成功 122 2 } 123 1 124 1 if(TIM == Timer3) //Timer3,固定为16位自动重装, 中断无优先级 125 1 { 126 2 Timer3_Stop(); //停止计数 127 2 if(TIMx->TIM_Interrupt == ENABLE) Timer3_InterruptEnable(); //允许中断 128 2 else Timer3_InterruptDisable(); //禁止中断 129 2 if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2; 130 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer3_12T(); //12T 131 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer3_1T(); //1T 132 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer3_AsCounter(); //对外计数或分频 133 2 else Timer3_AsTimer(); //定时 134 2 if(TIMx->TIM_ClkOut == ENABLE) Timer3_CLKO_Enable(); //输出时钟 135 2 else Timer3_CLKO_Disable(); //不输出时钟 136 2 137 2 T3_Load(TIMx->TIM_Value); 138 2 if(TIMx->TIM_Run == ENABLE) Timer3_Run(); //开始运行 139 2 return 0; //成功 140 2 } 141 1 142 1 if(TIM == Timer4) //Timer3,固定为16位自动重装, 中断无优先级 143 1 { 144 2 Timer4_Stop(); //停止计数 145 2 if(TIMx->TIM_Interrupt == ENABLE) Timer4_InterruptEnable(); //允许中断 146 2 else Timer4_InterruptDisable(); //禁止中断 147 2 if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2; 148 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer4_12T(); //12T 149 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer4_1T(); //1T 150 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer4_AsCounter(); //对外计数或分频 151 2 else Timer4_AsTimer(); //定时 152 2 if(TIMx->TIM_ClkOut == ENABLE) Timer4_CLKO_Enable(); //输出时钟 153 2 else Timer4_CLKO_Disable(); //不输出时钟 154 2 155 2 T4_Load(TIMx->TIM_Value); 156 2 if(TIMx->TIM_Run == ENABLE) Timer4_Run(); //开始运行 157 2 return 0; //成功 158 2 } 159 1 return 2; //错误 160 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 827 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)