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

📄 rtc_test.c

📁 IARSOURCECODE是基于LPC2478嵌入式软件IAR EWARM V4.42的应用实例代码
💻 C
字号:
/*****************************************************************************
 *   rtctest.c:  main C entry file for NXP LPC23xx/24xx Family Microprocessors
 *
 *   Copyright(C) 2006, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.07.13  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include "LPC2468.H"                        /* LPC23xx/24xx definitions */
#include "type.h"
#include "irq.h"
#include "target.h"
#include "rtc.h"

#include "timer.h"
#include "uart0.h"
#include "fio.h"

extern volatile DWORD rtc_alarm_on;
RTCTime local_time, alarm_time, current_time;

/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{	    		
  BYTE rtc_buf[21];           // 输出格式调整
  rtc_buf[4]=',';rtc_buf[7]=',';rtc_buf[10]=0x20;
  rtc_buf[13]=':';rtc_buf[16]=':';
  rtc_buf[19]='\n';rtc_buf[20]='\0';
  DWORD year,i=0;

  /* Initialize RTC module */
  TargetResetInit();
  RTCInit();

  local_time.RTC_Sec = 0;
  local_time.RTC_Min = 0;
  local_time.RTC_Hour = 0;
  local_time.RTC_Mday = 1;
  local_time.RTC_Wday = 2;
  local_time.RTC_Yday = 17;		/* current date 12/262007 */
  local_time.RTC_Mon = 1;
  local_time.RTC_Year = 2008;
  RTCSetTime( local_time );		/* Set local time */

  alarm_time.RTC_Sec = 0;
  alarm_time.RTC_Min = 0;
  alarm_time.RTC_Hour = 0;
  alarm_time.RTC_Mday = 1;
  alarm_time.RTC_Wday = 2;
  alarm_time.RTC_Yday = 1;		/* alarm date 01/01/2008 */
  alarm_time.RTC_Mon = 1;
  alarm_time.RTC_Year = 2008;
  RTCSetAlarm( alarm_time );		/* set alarm time */

  RTCStart();

  /* 每隔一秒用串口打印一次当前时间 */
  enable_timer(0);
  UART0Init(9600);
  GPIOInit(3,1,1);
  LedsInit();

  while (1)
  {					
    current_time = RTCGetTime();

    year = current_time.RTC_Year;
    rtc_buf[0] = 0x30 + year / 1000;year -= (rtc_buf[0]-0x30)*1000;
    rtc_buf[1] = 0x30 + year / 100;year -= (rtc_buf[1]-0x30)*100;
    rtc_buf[2] = 0x30 + year / 10;year -= (rtc_buf[2]-0x30)*10;
    rtc_buf[3] = 0x30 + year;

    rtc_buf[5] = 0x30 + current_time.RTC_Mon / 10;
    rtc_buf[6] = 0x30 + current_time.RTC_Mon % 10;

    rtc_buf[5] = 0x30 + current_time.RTC_Mon / 10;
    rtc_buf[6] = 0x30 + current_time.RTC_Mon % 10;

    rtc_buf[8] = 0x30 + current_time.RTC_Mday / 10;
    rtc_buf[9] = 0x30 + current_time.RTC_Mday % 10;

    rtc_buf[11] = 0x30 + current_time.RTC_Hour / 10;
    rtc_buf[12] = 0x30 + current_time.RTC_Hour % 10;

    rtc_buf[14] = 0x30 + current_time.RTC_Min / 10;
    rtc_buf[15] = 0x30 + current_time.RTC_Min % 10;

    rtc_buf[17] = 0x30 + current_time.RTC_Sec / 10;
    rtc_buf[18] = 0x30 + current_time.RTC_Sec % 10;

    UART0_puts(rtc_buf);

    LedOn(i);
    delayMs(0,1000);
    LedOff(i);
    i++;
  }


}

/******************************************************************************
**                            End Of File
******************************************************************************/

⌨️ 快捷键说明

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