zoukankan      html  css  js  c++  java
  • "static variable" defined in a function

    When I read codes of single chip, I find the following Timer Interrupt Function:

    void Timer_1(void) interrupt 3
    {	 
        static uint16 ms_count=0;
    	static uchar _100us_count=0;
    	//TH1     =   0xA9;   
        //TL1     =   0x9A;
    
    	Uart_timeout_count++;
    	if((Uart_timeout_count == 1000) && (rec_flag)) //´®¿Ú½ÓÊÕ1Ã볬ʱ
    	{
    		rec_flag = 0;
    	}
    
    	if(ms_count++ >= 1000)
    	{
    	     ms_count = 0;
    		 if(rec_flag)
    		 {
    		     LED5 = ~LED5;
    		 }
    		 else
    		 {
    		     LED5 = 1;
    		 }
    	}
    	 
    
     
    
    	 TH1     =   0xF7;   
         TL1     =   0x5C; //10KHZƵÂʶ¨Ê±
    
    	 _100us_count++;
    
    	 if(_100us_count <= Left_Speed) //×ó²àÕ¼¿Õ±È£¬1KHz
    	 {
    	     MOTOR_A_EN = 1;
    	 }
    	 else
    	 {
    	     MOTOR_A_EN = 0;
    	 }
    
    	 if(_100us_count <= Right_Speed)	//ÓÒ²àÕ¼¿Õ±È£¬1KHz
    	 {
    	     MOTOR_B_EN = 1;
    	 }
    	 else
    	 {
    	     MOTOR_B_EN = 0;
    	 }
    
    	 if(10 == _100us_count)
    	 {
    	      _100us_count = 0;
    		  MOTOR_A_EN = 0;
    		  MOTOR_B_EN = 0;
    	 }
    	 	
    }
    

      

    static uint16 ms_count=0;
    static uchar _100us_count=0;

    These two variables will be defined only once.

    After following call, it points to the same addresses.

    Actually we can make use of Global Variable to realize the same effect.

    But Global Variable is dangerous and vulnerable to be changed out of this effective region.

    Even if you defined a Static Global Variable only in this .obj. You have protected from changed by other .obj. However, it is still vulnerable to be changed in this very .obj by other functions.

    So "static" is local.

    "static" is proprietary.

  • 相关阅读:
    Burp Suite Professional单文件精简版该如何使用?
    快速掌握WinDBG
    Baymax大白补丁打油诗
    学员达标后完成的作业
    5星命名法:掌握这个软件全省
    挖掘IDA不可缺少的插件
    JEB安装和使用视频教程系列
    Ollydbg/x32dbg/x64dbg堆栈回溯要点总结
    Ollydbg狩猎从入门到精通
    Ollydbg/x32dbg爆破与逆向八法
  • 原文地址:https://www.cnblogs.com/stevenxiu/p/5824704.html
Copyright © 2011-2022 走看看