timers.c

来自「str710系列的hdlc协议的通信」· C语言 代码 · 共 114 行

C
114
字号
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name          : timers.c
* Author             : jrl
* Date First Issued  : 1/1/04
* Description        : functions for using the wdog as a gp timer
*********************************************************************************
* History:
* 2/8/04: first issued
*
*********************************************************************************/
#include "71x_lib.h"

//EXT int FindFactors();
  
void wait_us (u32 Time)
	// wait Time(in uS) 
  {
	//WDG_ECFlagClear();
	WDG_PeriodValueConfig ( Time );  
	
	WDG_CntOnOffConfig ( ENABLE );
	while (WDG_ECStatus( ) < 1);
	//while ((WDG->SR & 1) < 1);
	WDG_CntOnOffConfig ( DISABLE );
	WDG_ECFlagClear ( );
	
  }

void wait_ms (u32 Time)
  {
  	u32 i;
	
	for (i=0; i < Time; i++)
	  {
		wait_us (1000);
		
          }
  }

void wait_s (u32 Time)
  {
  	u32 i;
	
	for (i=0; i < Time; i++)
	  {
		wait_ms (1000);
		
          }
  }


void rtcinit (void)
{
  u32 Myprescaler;

  
// Configure RTC prescaler
  Myprescaler = 0x00007d00;  //prescaler for  1 clock per second
  RTC_PrescalerConfig ( Myprescaler );

// Clear Pending Flags
  RTC_FlagClear ( RTC_OWIR );
  RTC_FlagClear ( RTC_AIR  );
  RTC_FlagClear ( RTC_SIR  );
  RTC_FlagClear ( RTC_GIR  );


/////////
// Initialize the XTI 
  XTI_Init();
  // Set Line 15 edge 
  XTI_LineModeConfig(XTI_Line15, XTI_RisingEdge);
  // Enable the External interrupts on line 15 
  XTI_LineConfig(XTI_Line15, ENABLE);
  // Set the XTI mode 
  XTI_ModeConfig(XTI_WakeUp, ENABLE);

  //Configure the P0.15 in INOUT-WeakPP mode 
  GPIO_Config(GPIO0,0x0001<<0x0F,GPIO_INOUT_WP);

///////////////

RTC_AlarmConfig ( RTC_CounterValue () + 65); //wait 65 seconds for alarm


// Enable alarm Interrupt
  RTC_ITConfig( RTC_AIR | RTC_GIR, ENABLE );

// Configure Port 2 pins
 GPIO_Config (GPIO0, 0x1000, GPIO_OUT_PP);
 GPIO0->PD = 0x0000;

}
	
u32 uptime (void)
// return the contents of the rtc in hours assumes rtc clock = 1/second
  {

   u32 hours;

   hours = (RTC_CounterValue ()/3600);

   return (hours);

  }

void delay(u32 clocks)
  {
	u32 i;
	
	for (i=0; i < clocks; i++);

  }

⌨️ 快捷键说明

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