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

📄 rtc.c

📁 移植好的UCOS2.86版
💻 C
字号:
#include "2440addr.h"

#include "rtc.h"

#define RGB(r,g,b)   (unsigned int)( (r << 16) + (g << 8) + b )
int g_Year, g_Month,g_Date,g_DayOfWeek,g_Hour,g_Minute,g_Second;
const unsigned char g_week[7][10]={"Monday","Thesday","Wednesday","Thursday","Friday","Staturday","Sunday"};
//************************[ Rtc_Init ]*********************************
void Rtc_Init(void)
{
	int wYear, wMonth,wDate,wDayOfWeek,wHour,wMinute,wSecond;

    wYear = 2008;
    wMonth = 9;
    wDate = 5;
    wDayOfWeek = 7;
    wHour= 9;
    wMinute = 41;
    wSecond = 30;
	
	rRTCCON = 1 ;		//RTC read and write enable

	rBCDYEAR = (unsigned char)TO_BCD(wYear%100);	//年
    rBCDMON  = (unsigned char)TO_BCD(wMonth);		//月
    rBCDDATE = (unsigned char)TO_BCD(wDate);			//日	
	rBCDDAY  = wDayOfWeek;						//星期
	rBCDHOUR = (unsigned char)TO_BCD(wHour);		//小时
	rBCDMIN  = (unsigned char)TO_BCD(wMinute);		//分
	rBCDSEC  = (unsigned char)TO_BCD(wSecond);		//秒
	
	rRTCCON &= ~1 ;		//RTC read and write disable
}

//************************[ Rtc_display ]*********************************
void rtc_display(void)
{
  g_Year    = (2000 + rBCDYEAR);
  g_Month   = FROM_BCD(rBCDMON & 0x1f);
  g_Date		= FROM_BCD(rBCDDATE & 0x03f);
  g_DayOfWeek = rBCDDAY;
  g_Hour    = FROM_BCD(rBCDHOUR & 0x3f);
  g_Minute     = FROM_BCD(rBCDMIN & 0x7f);
  g_Second     = FROM_BCD(rBCDSEC & 0x7f);
  Uart_Printf("\n %02d:%02d:%02d %s %02d/%02d/%04d", g_Hour, g_Minute,
              g_Second,g_week[g_DayOfWeek-1],g_Month,g_Date,g_Year);	
}

//************************[ Rtc_set ]*********************************
void rtc_set(void)
{
  unsigned char wYear, wMonth,wDate,wDayOfWeek,wHour,wMinute,wSecond;
  Uart_Printf("\n Dislay current date and time:");
  rtc_display();
  Uart_Printf("\n Please input decimal digit than press Enter,such as 99.\n");
  Uart_Printf(" Year (\?\?):");
  wYear = Uart_GetIntNum();
  
  Uart_Printf(" Month (\?\?):");
  wMonth = Uart_GetIntNum();
  
  Uart_Printf(" Date (\?\?):");
  wDate = Uart_GetIntNum();
  
  Uart_Printf(" 1:Monday 2:Thesday 3:Wednesday 4:Thursday 5:Friday 6:Saturday 7:Sunday \n");
  Uart_Printf(" Week (\?\?):");
  wDayOfWeek = Uart_GetIntNum();
  
  Uart_Printf(" Hour (\?\?):");
  wHour = Uart_GetIntNum();
  
  Uart_Printf(" Minute (\?\?):");
  wMinute = Uart_GetIntNum();
  Uart_Printf(" Second (\?\?):");
  wSecond = Uart_GetIntNum();
  
  rRTCCON = 1 ;		//RTC read and write enable
  
  rBCDYEAR = (unsigned char)TO_BCD(wYear%100);	//年
  rBCDMON  = (unsigned char)TO_BCD(wMonth);		//月
  rBCDDATE = (unsigned char)TO_BCD(wDate);			//日	
  rBCDDAY  = wDayOfWeek;						//星期
  rBCDHOUR = (unsigned char)TO_BCD(wHour);		//小时
  rBCDMIN  = (unsigned char)TO_BCD(wMinute);		//分
  rBCDSEC  = (unsigned char)TO_BCD(wSecond);		//秒
	
  rRTCCON &= ~1 ;		//RTC read and write disable
  
  Uart_Printf("\n Dislay current date and time:");
  rtc_display();	
  Uart_Printf( "\n press any key to continue!\n" );
//  Lcd_printf(0,15,RGB( 0xFF,0xFF,0xFF),RGB( 0x00,0x00,0x00),0,"%4d-%02d-%02d %s 中国移动\n",
//        	      g_Year, g_Month, g_Date,g_week[g_DayOfWeek-1]);
  Uart_Getch() ;		//wait uart input
}

void __irq ISR_rtc_alarm(void)
{
  ClearPending(BIT_RTC);
  rtc_display();
  Uart_Printf("\n RTC ALARM TEST O.K.");
  // rtc_display();
  rINTMSK |=BIT_RTC;
}
//************************[ Rtc_test ]*********************************
void rtc_alarm_test(void)
{
  Uart_Printf("\n RTC Alarm Test for S3C2440");
  //Rtc_Init();
  
  rRTCCON = 1 ;		//RTC read and write enable
  
  rALMYEAR = rBCDYEAR;	//年
  rALMMON  = rBCDMON;		//月
  rALMDATE = rBCDDATE;			//日	
  rALMHOUR = rBCDHOUR;		//小时
  rALMMIN  = rBCDMIN;		//分
  rALMSEC  = rBCDSEC+4;		//秒
  
  pISR_RTC = (unsigned int)ISR_rtc_alarm;  //设置中断向量
  rRTCALM = 0x7f;
  rRTCCON &= ~1 ;		//RTC read and write disable
  rINTMSK &=~(BIT_RTC);
  rtc_display();
}

⌨️ 快捷键说明

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