basic.c

来自「RTC programming in eCos.」· C语言 代码 · 共 48 行

C
48
字号
//============================================================================
//        Include
//============================================================================

#include <stdio.h>
#include <cyg/kernel/kapi.h>
#include <cyg/io/rtc/fie702x_rtc.h>
#include "RTCSystem.h"

//============================================================================
//        Global Variables
//============================================================================

cyg_io_handle_t rtc_handle;

int main (void)
{	
	RTC_Time mytime;
	RTC_Date mydate;	
	int err;	
	
	/* open rtc driver
	*/
	err = cyg_io_lookup( "/dev/rtc", &rtc_handle );

	if (ENOERR != err) 
	{
		printf("Can't open '%s'\n", "/dev/rtc");
	}
	
	API_RTC_set_RecTime(rtc_handle, 0x1234);
	
	printf("record time = %d\n", API_RTC_get_RecTime(rtc_handle));
  
  while (1)
  {
  	cyg_thread_delay(100);
  	
		API_RTC_get_Date(rtc_handle, &mydate);
		API_RTC_get_Time(rtc_handle, &mytime);
	
		printf("\nYear:%d Month:%d Day:%d\n",mydate.year,mydate.month,mydate.day);
		printf("Hour:%d Min:%d Sec:%d\n",mytime.hour,mytime.minute,mytime.second);
	}
	
	return 0;
}

⌨️ 快捷键说明

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