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

📄 rtc.c

📁 ucos2.83在LPC2148上的例子
💻 C
字号:

#define  RTC_GLOBALS
#include <includes.h>

/*
*********************************************************************************************************
*                                                VARIABLES
*********************************************************************************************************
*/

OS_STK          AppTaskRTCStk[APP_TASK_RTC_STK_SIZE];

static  void  AppTaskRTC (void *p_arg);


/****************************************************************************

****************************************************************************/

void  RTCInit(void)
{  
    
   PREINT = CPU_FPCLK_FREQ / 32768 - 1;	// 设置基准时钟分频器
   PREFRAC = CPU_FPCLK_FREQ - (CPU_FPCLK_FREQ / 32768) * 32768;
   
   YEAR = 2007;				    // 初始化年
   MONTH = 12;				    // 初始化月
   DOM = 25;				    // 初始化日
   
   SEC = 30;
   MIN = 05;
   HOUR = 15;
   
   CIIR = 0x01;				    // 设置秒值的增量产生一次中断
   
   CCR = 0x01;				    // 启动RTC
}   
/****************************************************************************
* SetTimeRtc
* 功能:
* 入口参数:
* 出口参数:无
****************************************************************************/
void SetTimeRtc(int year, int moth, int day,int hour,int min,int sec)
{
	CCR = 0x00;
	YEAR = year;				    
	MONTH = moth;				    
   	DOM = day;				    
   
   	SEC = sec;
  	MIN = min;
   	HOUR = hour;
   	CCR = 0x01;
}
/****************************************************************************
* 名称:SendTimeRtc()
* 功能:读取RTC的时间值,并将读出的时分秒值由串口发送到上位机显示。
* 入口参数:无
* 出口参数:无
****************************************************************************/

void  SendTimeRtc(void)
{  
	CPU_INT32U  times;
	CPU_INT08U  bak;
	CPU_INT08U  MESSAGE[15] = "RTC Time is : ";
	CPU_INT08U send_buf[16];              // UART0数据接收缓冲区 
	CPU_INT32U  bak2;
	MESSAGE[14] = 0;

	printf("%s", MESSAGE);
	times = CTIME1;	
	
	bak2 = (times>>16)&0xFFF;		  // 取得年的值
	send_buf[0] = bak2/1000+'0';
	send_buf[1] = (bak2 - (bak2/1000)*1000)/100+'0';
	send_buf[2] = (bak2 - (bak2/100)*100)/100+'0';
	send_buf[3] = bak2%10+'0';		
	send_buf[4] = '-';
	
	bak = (times>>8)&0x0F;				// 取得月的值
	send_buf[5] = bak/10+'0';
	send_buf[6] = bak%10+'0';		
	send_buf[7] = '-';
	
	bak = (times)&0x1F;				// 取得日的值
	send_buf[8] = bak/10+'0';
	send_buf[9] = bak%10+'0';		
	send_buf[10] = ' ';
	send_buf[11] = 0;
	printf("%s",send_buf);   // 发送数据
	
	
	
	times = CTIME0;			    		// 读取完整时钟寄存器0
   
	bak = (times>>16)&0x1F;				// 取得时的值
	send_buf[0] = bak/10+'0';
	send_buf[1] = bak%10+'0';		
	send_buf[2] = ':';
   
	bak = (times>>8)&0x3F;				// 取得分的值
	send_buf[3] = bak/10+'0';
	send_buf[4] = bak%10+'0';		
	send_buf[5] = ':';
   
	bak = times&0x3F;					// 取得秒的值
	send_buf[6] = bak/10+'0';
	send_buf[7] = bak%10+'0';		
	send_buf[8] = '\n';
	send_buf[9] = 0;
   
	//UART0_SendStr((char*)MESSAGE);				// 发送数据
	//UART0_SendStr((char*)send_buf);
	printf("%s",send_buf);   // 发送数据
	
	
}



/****************************************************************************
*  RTCTaskStart()
* 功能:
* 入口参数:无
* 出口参数:无
****************************************************************************/

RTC_EXT INT8U RTCTaskStart(void)
{
	INT8U      err;
	OSTaskCreateExt(AppTaskRTC,
                    (void *)0,
                    (OS_STK *)&AppTaskRTCStk[APP_TASK_RTC_STK_SIZE - 1],
                    APP_TASK_RTC_PRIO,
                    APP_TASK_RTC_PRIO,
                    (OS_STK *)&AppTaskRTCStk[0],
                    APP_TASK_RTC_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 13

    OSTaskNameSet(APP_TASK_RTC_PRIO, (INT8U*)"RTC", &err);  
    
#endif
	return 0;
}

/*
*********************************************************************************************************
*                                          STARTUP TASK
*
* Description : This is an example of a startup task.  As mentioned in the book's text, you MUST
*               initialize the ticker only once multitasking has started.
* Arguments   : p_arg   is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
* Notes       : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                  used.  The compiler should not generate any code for this statement.
*               2) Interrupts are enabled once the task start because the I-bit of the CCR register was
*                  set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************/

static  void  AppTaskRTC (void *p_arg)
{
    (void)p_arg;

    SetTimeRtc(2007,12,25,15,30,30);
    while (DEF_TRUE) 
    {                              /* Task body, always written as an infinite loop.  */
      while( 0==(ILR&0x01) )	    // 等待RTC增量中断标志
      {
        OSTimeDly(10);
      }
      ILR = 0x01;				    // 清除中断标志

      OSTimeDlyHMSM(0, 0, 2, 0);

    }
}

⌨️ 快捷键说明

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