亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? rtc.c

?? IAR5.2下 AT91SAM9260 ARM 對 MCP2515 控制源化碼
?? C
字號:
/* ----------------------------------------------------------------------------
 *         ATMEL Microcontroller Software Support 
 * ----------------------------------------------------------------------------
 * Copyright (c) 2008, Atmel Corporation
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the disclaimer below.
 *
 * Atmel's name may not be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * ----------------------------------------------------------------------------
 */

#ifndef trace_LEVEL
	#define trace_LEVEL trace_INFO
#endif

//------------------------------------------------------------------------------
//         Headers
//------------------------------------------------------------------------------

#include "rtc.h"
#include <board.h>
#include <utility/assert.h>
#include <utility/trace.h>

//------------------------------------------------------------------------------
//         Exported functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// Sets the RTC in either 12- or 24-hour mode.
/// \param mode  Hour mode.
//------------------------------------------------------------------------------
void RTC_SetHourMode(unsigned int mode)
{
	SANITY_CHECK((mode & 0xFFFFFFFE) == 0);

    trace_LOG(trace_DEBUG, "-D- RTC_SetHourMode()\n\r");

	AT91C_BASE_RTC->RTC_MR = mode;
}

//------------------------------------------------------------------------------
/// Enables the selected interrupt sources of the RTC.
/// \param sources  Interrupt sources to enable.
//------------------------------------------------------------------------------
void RTC_EnableIt(unsigned int sources)
{
    SANITY_CHECK((sources & ~0x1F) == 0);

    trace_LOG(trace_DEBUG, "-D- RTC_EnableIt()\n\r");

    AT91C_BASE_RTC->RTC_IER = sources;
}

//------------------------------------------------------------------------------
/// Disables the selected interrupt sources of the RTC.
/// \param sources  Interrupt sources to disable.
//------------------------------------------------------------------------------
void RTC_DisableIt(unsigned int sources)
{
    SANITY_CHECK((sources & ~0x1F) == 0);

    trace_LOG(trace_DEBUG, "-D- RTC_DisableIt()\n\r");

    AT91C_BASE_RTC->RTC_IDR = sources;
}

//------------------------------------------------------------------------------
/// Sets the current time in the RTC.
/// \param hour  Current hour.
/// \param minute  Current minute.
/// \param second  Current second.
//------------------------------------------------------------------------------
void RTC_SetTime(unsigned char hour, unsigned char minute, unsigned char second)
{
	unsigned int time;

	SANITY_CHECK(hour < 24);
	SANITY_CHECK(minute < 60);
	SANITY_CHECK(second < 60);

    trace_LOG(trace_DEBUG, "-D- RTC_SetTime(%02d:%02d:%02d)\n\r", hour, minute, second);

	time = (second % 10) | ((second / 10) << 4)
		   | ((minute % 10) << 8) | ((minute / 10) << 12);

	// 12-hour mode
	if ((AT91C_BASE_RTC->RTC_MR & AT91C_RTC_HRMOD) == AT91C_RTC_HRMOD) {

		if (hour > 12) {

			hour -= 12;
			time |= AT91C_RTC_AMPM;
		}
	}

	time |= ((hour % 10) << 16) | ((hour / 10) << 20);

	// Set time
	AT91C_BASE_RTC->RTC_CR |= AT91C_RTC_UPDTIM;
	while ((AT91C_BASE_RTC->RTC_SR & AT91C_RTC_ACKUPD) != AT91C_RTC_ACKUPD);
	AT91C_BASE_RTC->RTC_SCCR = AT91C_RTC_ACKUPD;
	AT91C_BASE_RTC->RTC_TIMR = time;
	AT91C_BASE_RTC->RTC_CR &= ~AT91C_RTC_UPDTIM;
	SANITY_CHECK((AT91C_BASE_RTC->RTC_CR & AT91C_RTC_UPDTIM) != AT91C_RTC_UPDTIM);
}

//------------------------------------------------------------------------------
/// Retrieves the current time as stored in the RTC in several variables.
/// \param pHour  If not null, current hour is stored in this variable.
/// \param pMinute  If not null, current minute is stored in this variable.
/// \param pSecond  If not null, current second is stored in this variable.
//------------------------------------------------------------------------------
void RTC_GetTime(
	unsigned char *pHour,
	unsigned char *pMinute,
	unsigned char *pSecond)
{
	unsigned int time;

	SANITY_CHECK(pHour || pMinute || pSecond);

    trace_LOG(trace_DEBUG, "-D- RTC_GetTime()\n\r");

	// Get current RTC time
	time = AT91C_BASE_RTC->RTC_TIMR;
	while (time != AT91C_BASE_RTC->RTC_TIMR) {

		time = AT91C_BASE_RTC->RTC_TIMR;
	}

	// Hour
	if (pHour) {

		*pHour = ((time & 0x00300000) >> 20) * 10
				 + ((time & 0x000F0000) >> 16);
		if ((time & AT91C_RTC_AMPM) == AT91C_RTC_AMPM) {

			*pHour += 12;
		}
	}
	
	// Minute
	if (pMinute) {

		*pMinute = ((time & 0x00007000) >> 12) * 10
				   + ((time & 0x00000F00) >> 8);
	}

	// Second
	if (pSecond) {

		*pSecond = ((time & 0x00000070) >> 4) * 10
				   + (time & 0x0000000F);
	}
}

//------------------------------------------------------------------------------
/// Sets a time alarm on the RTC. The match is performed only on the provided
/// variables; setting all pointers to 0 disables the time alarm.
/// Note: in AM/PM mode, the hour value must have bit #7 set for PM, cleared for
/// AM (as expected in the time registers).
/// \param pHour  If not null, the time alarm will hour-match this value.
/// \param pMinute  If not null, the time alarm will minute-match this value.
/// \param pSecond  If not null, the time alarm will second-match this value.
//------------------------------------------------------------------------------
void RTC_SetTimeAlarm(
	unsigned char *pHour,
	unsigned char *pMinute,
	unsigned char *pSecond)
{
	unsigned int alarm = 0;

    SANITY_CHECK(!pHour || ((*pHour & 0x80) == 0));
    SANITY_CHECK(!pMinute || (*pMinute < 60));
    SANITY_CHECK(!pSecond || (*pSecond < 60));

	trace_LOG(trace_DEBUG, "-D- RTC_SetTimeAlarm()\n\r");

	// Hour
	if (pHour) {

		alarm |= AT91C_RTC_HOUREN | ((*pHour / 10) << 20) | ((*pHour % 10) << 16);
	}

	// Minute
	if (pMinute) {

		alarm |= AT91C_RTC_MINEN | ((*pMinute / 10) << 12) | ((*pMinute % 10) << 8);
	}

	// Second
	if (pSecond) {

		alarm |= AT91C_RTC_SECEN | ((*pSecond / 10) << 4) | (*pSecond % 10);
	}

	AT91C_BASE_RTC->RTC_TIMALR = alarm;
}

//------------------------------------------------------------------------------
/// Retrieves the current year, month and day from the RTC. Month, day and week
/// values are numbered starting at 1.
/// \param pYear  Current year (optional).
/// \param pMonth  Current month (optional).
/// \param pDay  Current day (optional).
/// \param pWeek  Current day in current week (optional).
//------------------------------------------------------------------------------
void RTC_GetDate(
    unsigned short *pYear,
    unsigned char *pMonth,
    unsigned char *pDay,
    unsigned char *pWeek)
{
    unsigned int date;

    // Get current date (multiple reads are necessary to insure a stable value)
    do {

        date = AT91C_BASE_RTC->RTC_CALR;
    }
    while (date != AT91C_BASE_RTC->RTC_CALR);

    // Retrieve year
    if (pYear) {

        *pYear = (((date  >> 4) & 0x7) * 1000)
                 + ((date & 0xF) * 100)
                 + (((date >> 12) & 0xF) * 10)
                 + ((date >> 8) & 0xF);
    }

    // Retrieve month
    if (pMonth) {

        *pMonth = (((date >> 20) & 1) * 10) + ((date >> 16) & 0xF);
    }

    // Retrieve day
    if (pDay) {

        *pDay = (((date >> 28) & 0x3) * 10) + ((date >> 24) & 0xF);
    }

    // Retrieve week
    if (pWeek) {

        *pWeek = ((date >> 21) & 0x7);
    }
}

//------------------------------------------------------------------------------
/// Sets the current year, month and day in the RTC. Month, day and week values
/// must be numbered starting from 1.
/// \param year  Current year.
/// \param month  Current month.
/// \param day  Current day.
/// \param week  Day number in current week.
//------------------------------------------------------------------------------
void RTC_SetDate(
    unsigned short year,
    unsigned char month,
    unsigned char day,
    unsigned char week)
{
    unsigned int date;

    SANITY_CHECK((year >= 1900) && (year <= 2099));
    SANITY_CHECK((month >= 1) && (month <= 12));
    SANITY_CHECK((day >= 1) && (day <= 31));
    SANITY_CHECK((week >= 1) && (week <= 7));

    // Convert values to date register value
    date = ((year / 100) % 10)
           | ((year / 1000) << 4)
           | ((year % 10) << 8)
           | (((year / 10) % 10) << 12)
           | ((month % 10) << 16)
           | ((month / 10) << 20)
           | (week << 21)
           | ((day % 10) << 24)
           | ((day / 10) << 28);

    // Update calendar register
    AT91C_BASE_RTC->RTC_CR |= AT91C_RTC_UPDCAL;
    while ((AT91C_BASE_RTC->RTC_SR & AT91C_RTC_ACKUPD) != AT91C_RTC_ACKUPD);
    AT91C_BASE_RTC->RTC_SCCR = AT91C_RTC_ACKUPD;
    AT91C_BASE_RTC->RTC_CALR = date;
    AT91C_BASE_RTC->RTC_CR &= ~AT91C_RTC_UPDCAL;
}

//------------------------------------------------------------------------------
/// Sets a date alarm in the RTC. The alarm will match only the provided values;
/// passing a null-pointer disables the corresponding field match.
/// \param pMonth  If not null, the RTC alarm will month-match this value.
/// \param pDay  If not null, the RTC alarm will day-match this value.
//------------------------------------------------------------------------------
void RTC_SetDateAlarm(unsigned char *pMonth, unsigned char *pDay)
{
    unsigned int alarm = 0;

    SANITY_CHECK(!pMonth || ((*pMonth >= 1) && (*pMonth <= 12)));
    SANITY_CHECK(!pDay || ((*pDay >= 1) && (*pDay <= 31)));

    trace_LOG(trace_DEBUG, "-D- RTC_SetDateAlarm()\n\r");

    // Compute alarm field value
    if (pMonth) {

        alarm |= AT91C_RTC_MONTHEN | ((*pMonth / 10) << 20) | ((*pMonth % 10) << 16);
    }
    if (pDay) {

        alarm |= AT91C_RTC_DATEEN | ((*pDay / 10) << 28) | ((*pDay % 10) << 24);
    }

    // Set alarm
    AT91C_BASE_RTC->RTC_CALALR = alarm;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久综合九色综合欧美亚洲| 裸体在线国模精品偷拍| 欧美极品美女视频| 欧美经典一区二区三区| 久久色中文字幕| 国产调教视频一区| 国产精品青草久久| 国产精品久久久久9999吃药| 亚洲欧洲av在线| 亚洲精品欧美专区| 亚洲v中文字幕| 日韩国产高清影视| 久久精品999| 国产成人精品免费在线| 99免费精品视频| 91精品1区2区| 4438亚洲最大| 久久久夜色精品亚洲| 日本一区二区免费在线观看视频 | 亚洲欧洲精品一区二区三区| 国产精品色婷婷久久58| 一区二区三区日韩精品| 日本亚洲天堂网| 国产露脸91国语对白| 99精品视频在线观看| 欧美日本在线播放| 日韩免费高清电影| 国产精品欧美极品| 亚洲一线二线三线久久久| 午夜精品123| 日韩国产成人精品| 粉嫩一区二区三区在线看| 99re6这里只有精品视频在线观看| 91一区在线观看| 91麻豆精品国产无毒不卡在线观看| 欧美成va人片在线观看| 国产精品二三区| 国产成人亚洲综合a∨婷婷| 99精品欧美一区二区三区综合在线| 欧美在线观看一二区| 欧美一级欧美三级| 国产精品短视频| 日韩高清一区在线| 国产精品一色哟哟哟| 一本色道a无线码一区v| 日韩女优电影在线观看| 亚洲欧美日韩中文字幕一区二区三区 | 777午夜精品视频在线播放| 久久综合一区二区| 亚洲永久免费视频| 国产老妇另类xxxxx| 欧美综合视频在线观看| 国产亚洲一二三区| 亚洲一区二区三区在线| 国产高清精品久久久久| 欧美亚洲国产一区二区三区| 国产欧美中文在线| 日本少妇一区二区| av激情综合网| 欧美va亚洲va在线观看蝴蝶网| 日韩美女久久久| 激情综合五月婷婷| 欧美性受xxxx黑人xyx| 国产欧美一区视频| 麻豆精品国产91久久久久久| 在线免费av一区| 国产精品麻豆欧美日韩ww| 日本美女一区二区三区视频| 色综合久久中文字幕| 久久免费的精品国产v∧| 性久久久久久久久久久久| www.久久久久久久久| 精品国产制服丝袜高跟| 亚洲第一久久影院| 色综合色狠狠综合色| 中文字幕av不卡| 久久精品国产成人一区二区三区| 在线亚洲人成电影网站色www| 欧美激情在线观看视频免费| 激情成人综合网| 日韩欧美色综合| 青青青伊人色综合久久| 色欧美片视频在线观看在线视频| 久久品道一品道久久精品| 另类小说一区二区三区| 3d动漫精品啪啪一区二区竹菊| 亚洲综合999| 色国产综合视频| 亚洲欧洲性图库| 成人黄色网址在线观看| 欧美国产日本韩| 欧美图区在线视频| 亚洲黄网站在线观看| 91网站最新网址| 中文字幕欧美一| 91一区二区在线| 日韩理论电影院| 日本精品一级二级| 亚洲精品视频免费观看| 91美女片黄在线| 亚洲品质自拍视频| 在线视频综合导航| 一区二区三区小说| 色综合久久综合网| 亚洲一区二区视频在线| 欧美亚洲国产一区在线观看网站 | 色婷婷久久综合| 亚洲欧美另类在线| 色狠狠一区二区| 夜夜精品视频一区二区 | 91精品国产手机| 日本va欧美va精品发布| 日韩三级在线观看| 国产在线播放一区| 国产色产综合色产在线视频| 粉嫩aⅴ一区二区三区四区| 国产精品的网站| 91在线视频网址| 亚洲大片一区二区三区| 日韩一级免费观看| 久久se这里有精品| 国产日韩欧美综合在线| 99国产精品一区| 亚洲国产视频直播| 日韩视频永久免费| 国产大陆精品国产| 亚洲色图欧美激情| 欧美日韩三级视频| 久久精品二区亚洲w码| 久久午夜免费电影| 91免费版pro下载短视频| 一级做a爱片久久| 欧美成人aa大片| 成人97人人超碰人人99| 亚洲小说欧美激情另类| 欧美一区二区视频免费观看| 国产成人免费网站| 亚洲视频在线一区二区| 欧美男男青年gay1069videost| 久久精品理论片| 中文字幕一区二区在线观看| 欧美网站一区二区| 国产一区二区三区最好精华液| 国产精品毛片大码女人| 欧美日韩国产首页在线观看| 久88久久88久久久| 亚洲精品五月天| 精品国产一区二区三区忘忧草| 国产91对白在线观看九色| 亚洲国产精品一区二区www在线| 日韩精品一区二区在线观看| 成人av电影在线网| 日本不卡一二三| 亚洲桃色在线一区| 亚洲精品一线二线三线无人区| 91蜜桃在线观看| 国产呦精品一区二区三区网站| 一区二区三区影院| 国产视频一区二区三区在线观看| 日本一区二区久久| 欧美三级一区二区| 成人av电影在线播放| 麻豆精品蜜桃视频网站| 一区二区久久久| 成人免费av网站| 欧美一区二区视频免费观看| 国产精品天美传媒沈樵| 日韩欧美在线不卡| 色偷偷成人一区二区三区91| 国产乱码字幕精品高清av| 亚洲一区二区三区在线看| 国产精品美日韩| 精品国产免费视频| 欧美日韩中文精品| av在线一区二区| 国产一区二区三区免费播放| 日韩精品成人一区二区在线| 亚洲欧美一区二区三区极速播放| 久久女同性恋中文字幕| 欧美日韩极品在线观看一区| aaa亚洲精品| 国产白丝网站精品污在线入口| 男女男精品视频网| 亚洲地区一二三色| 一区二区三区成人在线视频| 国产精品久久午夜夜伦鲁鲁| 久久久精品tv| 日韩免费一区二区三区在线播放| 欧美无人高清视频在线观看| 91在线精品一区二区| 国产成人免费视频网站| 精品一区二区三区在线观看国产 | 毛片不卡一区二区| 五月综合激情日本mⅴ| 亚洲乱码国产乱码精品精可以看| 久久久精品影视| 久久精品人人做人人爽97| 久久综合给合久久狠狠狠97色69| 日韩欧美国产综合一区| 日韩免费视频一区|