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