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

📄 simple_eos.c

📁 CODE for embedded C ,hand coding version
💻 C
字号:
/*-------------------------------------------------------------------*-
  Simple_EOS.C(v1.00)
  Author: 06_Digital_Media
  All Right Reserved
  ---------------------------------------------------------------------
  Main file for Simple Embedded Operation System (sEOS) for 8051 
  -- This version for milk-flow-rate monitoring 
 -*-------------------------------------------------------------------*/

 #include "Main.H"
 #include "Simple_EOS.H"
 #include "Pulse_count.H"

 /*-------------------------------------------------------------------*-
 sEOS_ISR()
  Invoked periodically by Timer 2 overflow :
  see sEOS_Init_Timer2() for timing details.
  -*------------------------------------------------------------------*/
  void sEOS_ISR() interrupt INTERRUPT_Timer_2_Overflow
  {
   //Must manually reset the T2 flag
   TF2 = 0 ;
   //========USER CODE -Begin =========================================
   //Call 'Update' function here
   PULSE_COUNT_Update();

  //=========USE CODE -End ============================================

  }
 /*--------------------------------------------------------------------*-
   sEOS_Init_Timer2()
   Sets up Timer2 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
   combination .If timing is important ,you should check the timing calculations manually

    -*----------------------------------------------------------------*/
	void sEOS_Init_Timer2(const tByte TICK_MS){
	 tLong Inc;
	 tWord Reload_16;
	 tByte Reload_08H,Reload_08L;
	 //Timer 2 is configured as a 16 bit timer 
	 //which is automatically reloaded when it overflows
	 T2CON = 0x04 ; //Load Timer 2 control register
	 
	 //Number of timer increment 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 values (High & Low )
     Reload_08H = (tByte)(Reload_16 / 256 );
	 Reload_08L = (tByte)(Reload_16 % 256 );

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

	 TH2 = Reload_08H;
	 RCAP2H = Reload_08H;
	 TH1 = Reload_08L ;
     RCAP2L= Reload_08L ;

	 //Timer 2 interrupt is enabled and ISR will be called whenever the timer overflows 
	 ET2 = 1 ;

	 //Start Timer 2 running 
	 TR2 = 1 ;

	 EA = 1  ; //Globally enable interrupts




 

	}

  /*-----------------------------------------------------------------*-
  sEOS_Go_To_Sleep()
  This operating system enter 'idle mode' between clock ticks to save power
  The next 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 + -