⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simple_eos_t0.c

📁 CODE for embedded C ,hand coding version
💻 C
字号:
/*------------------------------------------------------------------*-
 Simple_EOS_T0.C (v1.00)
 ---------------------------------------------------------------------
 Main file for Simple Embedded Operating System (sEOS) for 8051 
 *** This version uses T0 (easily adapted to T1 )***
 Demostration version with dummy task ()

 -*-----------------------------------------------------------------*/

  #include "Main.H"
  #include "Simple_EOS_T0.H"
  //Header for dummy task
  #include "X.H"

  //------------Private variable definition -------------------------
  static tByte Reload_08H;
  static tByte Reload_08L;

  //------------Private function prototypes -------------------------
  static void sEOS_Manual_Timer0_Reload(void);
  /*-----------------------------------------------------------------*-
  sEOS_ISR()
  Invoked periodically by Timer 0 overflow 
  see sEOS_Init_Timer0() for timing details 
  -*------------------------------------------------------------------*/

  void sEOS_ISR () interrupt INTERRUPT_Timer_0_Overflow
  {
   //Flag cleared automatically but must reload the timer
    sEOS_Manual_Timer0_Reload();
	//==========USER CODE -Begin =====================================
	//Call dummy task here
	X();

	//==============USER COED - End ===================================
  }

  /*------------------------------------------------------------------*-
  sEOS_Init_Timer0()
  Sets up Timer 0 to drive the simple EOS
  Parameter gives tick interval in MILLISECONDS
  Max tick interval is ~60 ms (12 MHZ oscillator)

  Note: Precise tick intervals are only possible with certain oscillator / tick
  interval combinations .If timing is important ,you should check the timing calculations manually
  -*------------------------------------------------------------------*/

  void sEOS_Init_Timer0(const tByte TICK_MS){
    tLong Inc ;
	tWord Reload_16;
	//Using Timer 0 ,16 bit ***manuall reload ***
	TMOD &= 0xF0; //Clear all T0 bits (T1 left unchanged)
	TMOD |= 0x01; //Set required T0 bits (T1 left unchanged)

	//Number of timer increments required (max 65536)
	Inc = ((tLong )TICK_MS * (OSC_FREQ/1000))/(tLong)OSC_PER_INST;

	// 16-bit reload value
	Reload_16 = (tWord)(65536UL - Inc);
	//8-bit reload value 
	Reload_08H = (tByte) (Reload_16 / 256);
	Reload_08L = (tByte) (Reload_16 % 256);


	//USE for manually checking timing (in simulator)
	P2 = Reload_08H;
	P3 = Reload_08L;

	TL0 = Reload_08L ;
	TH0 = Reload_08H ;

	//Timer 0 interrupt is enabled ,and ISR will be called whenever the timer overflow 
	ET0 = 1 ;

	//Start Timer 0 running 
	TR0 = 1;

	EA = 1 ;//Globally enable interrupts




  }
 /*-------------------------------------------------------------------*-
 sEOS_Manual_Timer0_Reload()
 This OS uses a (manually reloaded ) 16 bit timer 

 The manual reload means that all timings are approximate

 THIS OS IS NOT SUITABLE FOR APPLICATIONS WHERE ACCURATE TIMING IS REQUIRE!!!

 Timer reload is carried out in this function

 -*--------------------------------------------------------------------*/

 void sEOS_Manual_Timer0_Reload(){
  //Stop Timer 0
  TR0 = 0 ;

  //See Init function for calculations 
  TL0 = Reload_08L;
  TH0 = Reload_08H ;

  //Start Timer 0 

  TR0 = 1 ;
 }


 /*------------------------------------------------------------------*-
 sEOS_Go_To_Sleep()

 This operating system enters 'idle mode' between clock ticks
 to save power.The next clock tick will return the processor to the normal
 operating state .
 -*-------------------------------------------------------------------*/

 void sEOS_Go_To_Sleep(void){
   PCON |= 0x01 ; //enter idle mode (generic 8051 version )
 }
/*-------------------------------------------------------------------*-
 -------------END OF FILE ---------------------------------------------
 -*-------------------------------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -