DSP 之实时时钟(RTC)编程

/*
 *---------main_rtc1.c---------
 * This is an example of using the RTC configuration functions for 5509
 */

#include 
#include 
 
//---------Global data definition---------

int i; 
RTC_Time getTime;
RTC_Date getDate;
RTC_Config Config; 
RTC_Alarm getAlarm;


RTC_Config myConfig = {
     0x40,    /* Seconds 秒 */
     0x00,    /* Seconds Alarm 秒报警 */
     0x58,    /* Minutes */
     0x00,    /* Minutes Alarm */
     0x11,    /* Hour */
     0x00,    /* Hours Alarm */
     0x05,    /* Day of the week and day alarm 周和日报警的日 */
     0x10,    /* Day of the month	月报警的日  */
     0x10,    /* Month */
     0x03,    /* Year */
     0x08,    /* Register A */
     0x82,    /* Register B - 24-hour mode  设置为24 小时模式 */
};

RTC_Date myDate = {
     0x14,     /* Year */
     0x02,     /* Month February  */
     0x19,     /* Day of month 19 */
     0x03,     /* Day of week Wednesday  */
};

RTC_Time myTime = {
     0x11,     /* Hour */      
     0x58,     /* Minutes */
     0x40,     /* Seconds */
};

RTC_Alarm myAlarm = {
     0x12,     /* alHour */  
     0x03,     /* alMinutes - every minute */
     0x03,     /* alSeconds */
     0x05,     /* alDayw */
};


RTC_Alarm myAlarm1 = {
	0x1,		/* alHour, in 24-Hour format */
	0x0, 		//NONTCARE,	/* alMinutes */
	0x0,		/* alSeconds */
	0x02,		/* alDayw */
};


main()
{
	int i = 0;
	
	CSL_init();				// CSL 固件库初始化
	printf ("\nTESTING...\n");
  
	RTC_reset();    		// Reset the registers to their default values  
	RTC_config(&myConfig);  // Initialization  
	RTC_getConfig(&Config); // Reads RTC configuration struct  
	      
	printf ("RTCSEC value is: %x\n",Config.rtcsec);  	
	printf ("RTCMIN value is: %x\n",Config.rtcmin); 
	printf ("RTCHOUR value is: %x\n",Config.rtchour); 
	printf ("RTCDAYW value is: %x\n",Config.rtcdayw); 
	printf ("RTCDAYM value is: %x\n",Config.rtcdaym);        
	printf ("RTCYEAR value is: %x\n",Config.rtcyear);        

	RTC_setTime(&myTime);		// seting Time	  
	RTC_getTime(&getTime);		// Read the current time from the RTC register 	
	printf("Current RTC time is: %x:%x:%x\n",getTime.hour,getTime.minute,getTime.second);
  
  	RTC_setDate(&myDate);		// set RTC date 2014:2:19
	RTC_getDate(&getDate);  	// Reads current date from RTC register - only support 24hour mode       
	printf("Current RTC date is: %x/%x/%x\tDay of week: %x\n",getDate.month,getDate.daym,getDate.year,getDate.dayw); 
      
	/* Set an alarm at the time specified by myAlarm */         
	/* Alarm needs to be enabled to occur */
	
	RTC_setAlarm(&myAlarm);  // Sets alarm at specific  12:03:03AM every week on thoursday         
	//RTC_setAlarm(&myAlarm1); // This sets the alarm every minute, at 01:**:00, on Monday of eeek 
	
	
	printf("Alarm time: %x : %x : %x\tDay of week: %x\n",
						RTC_FGET(RTCHOURA,HAR),	// Reads RTC register field values - HOUR
						RTC_FGET(RTCMINA,MAR),	// MINUTE
						RTC_FGET(RTCSECA,SAR),	// SECOND
						RTC_FGET(RTCDAYW,DAR));	// DAY
   
   
   	/* decimal to BCD */
	for(i = 0; i < 10; ++ i)
	{
		printf("BCD of %d is %x \n", i, RTC_decToBcd(i));
	}
	
	
	RTC_start();    // start the RTC running
	
	
}


 

/*
 *---------main_rtc1.c---------
 * This is an example of using the RTC configuration functions for 5509
 */
 
 /*
  * 100 年 - 2099 年 
  * 时分秒,年月日计数 和闰年补偿 
  * BCD码,日历,闹钟
  * 12小时模式和24小时模式,但CSL只支持24小时模式 
  * 时分秒分别的闹钟中断
  * 更新周期中断和定时中断
  * 该时钟来自于外部的32KHz的晶振
  * 。。。
  */

#include 
#include 
 
//---------Global data definition---------

int i; 
RTC_Time getTime;
RTC_Date getDate;
RTC_Config Config; 
RTC_Alarm getAlarm;


RTC_Config myConfig = {
     0x40,    /* Seconds 秒 */
     0x00,    /* Seconds Alarm 秒报警 */
     0x58,    /* Minutes */
     0x00,    /* Minutes Alarm */
     0x11,    /* Hour */
     0x00,    /* Hours Alarm */
     0x05,    /* Day of the week and day alarm 周和日报警的日 */
     0x10,    /* Day of the month	月报警的日  */
     0x10,    /* Month */
     0x03,    /* Year */
     0x08,    /* Register A */
     0x82,    /* Register B - 24-hour mode  设置为24 小时模式 */
};

RTC_Date myDate = {
     0x14,     /* Year */
     0x02,     /* Month February  */
     0x19,     /* Day of month 19 */
     0x03,     /* Day of week Wednesday  */
};

RTC_Time myTime = {
     0x11,     /* Hour */      
     0x58,     /* Minutes */
     0x40,     /* Seconds */
};

RTC_Alarm myAlarm = {
     0x12,     /* alHour */  
     0x03,     /* alMinutes - every minute */
     0x03,     /* alSeconds */
     0x05,     /* alDayw */
};


RTC_Alarm myAlarm1 = {
	0x1,		/* alHour, in 24-Hour format */
	0x0, 		//NONTCARE,	/* alMinutes */
	0x0,		/* alSeconds */
	0x02,		/* alDayw */
};


main()
{
	Uint16 address = 0;
	Uint16 s = 0x13, mi = 0x15, d = 0x13, h = 11, m = 2, y = 14;
	Uint16 field1, field2, field3;
	
	
	CSL_init();				// CSL 固件库初始化
	printf ("\nTESTING...\n");
  
	RTC_reset();    		// Reset the registers to their default values  
	RTC_config(&myConfig);  // Initialization  
	RTC_getConfig(&Config); // Reads RTC configuration struct  
	      
	printf ("RTCSEC value is: %x\n",Config.rtcsec);  	
	printf ("RTCMIN value is: %x\n",Config.rtcmin); 
	printf ("RTCHOUR value is: %x\n",Config.rtchour); 
	printf ("RTCDAYW value is: %x\n",Config.rtcdayw); 
	printf ("RTCDAYM value is: %x\n",Config.rtcdaym);        
	printf ("RTCYEAR value is: %x\n",Config.rtcyear);        

	/* Read register address */
	printf("Read register address: %d\n", RTC_ADDR(RTCSEC));
	
	/* Creates value of RTC register */
	printf("Creates value of RTC register: %d\n", 
						RTC_RTCDAYW_RMK(field1, field2, field3));
	
	/* Write RTC register value */
	printf("Write RTC register value %d-%d-%d---%d-%d-%d\n", 
						RTC_RSET(RTCSEC, s), RTC_RSET(RTCMIN, mi), RTC_RSET(RTCHOUR, h),
						RTC_RSET(RTCDAYW, d), RTC_RSET(RTCDAYM, m), RTC_RSET(RTCYEAR, y) );	
	
	
	
	printf(" Reads RTC register value: %d-%d-%d---%d-%d-%d",
			 			RTC_RGET(RTCSEC), RTC_RGET(RTCMIN), RTC_RGET(RTCHOUR),
						RTC_RGET(RTCDAYW), RTC_RGET(RTCDAYM), RTC_RGET(RTCYEAR));
	
	
	
	RTC_start();    // start the RTC running
	
	
}


 

本程序已在TMS320C5509A 上测试通过- !欢迎各位交流指导-

你可能感兴趣的:([,Embedded,Techology,])