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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? rtc_experimental.c

?? TDK 6521 SOC 芯片 DEMO程序
?? C
字號(hào):
/***************************************************************************
 * This code and information is provided "as is" without warranty of any   *
 * kind, either expressed or implied, including but not limited to the     *
 * implied warranties of merchantability and/or fitness for a particular   *
 * purpose.                                                                *
 *                                                                         *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 ***************************************************************************/
//**************************************************************************
//  DESCRIPTION: 71M652x POWER METER - Real Time Clock Routines.
//  This experimental RTC adjustment algorithm was invented too close
//  to the release date to be tested.  If it works, it may reduce
//  the average error when compared to the older adjustment method.
// 
//  AUTHOR:  MTF/RGV
//
//  HISTORY: See end of file.
//**************************************************************************
// File: RTC.C
//               
#include "options.h"
#include "library.h" // get LRC calculation from the source
#include "meter.h"
#include "freq.h"    // to handle rtc adjustment from line's edge count
#include "lcd.h"
#if TIMERS
#include "stm.h" // use  for timing the write
#elif TMR1
#include "tmr1.h" // timer 1 can be used for timing the write
#elif TMR0
#include "tmr0.h" // timer 1 can be used for timing the write
#elif REAL_TIME_DATE
#error need timers to set the clock
#endif
#include "irq.h"  // interrupt control
#include "rtc.h"  // test the function definitions against the code

#include FILE_DEFINING_RTC

#if  OPERATING_TIME
// display the number of hours of operation
void operating_lcd (void)
{
    LCD_Number_Max (OperatingSeconds / 36, 2);  // Display max digits.
    LCD_2DP ();                                 // Two decimal places.
}
#endif

#if  REAL_TIME_DATE
/*** External functions referenced by this module ***/
// See includes

/*** External variables referenced by this module ***/
// Options.h must define:
// RTC_COPY, a structure in xdata RAM of type RTC_t that contains the 
// system's clock variables.  The demo code, defines RTC_COPY in options_gbl.h
// In the demo code, RTC_COPY is near the other meter data, in
// the data structure "Totals", defined in meter.h
// Some compensation data might also be needed: slow, trim, and trim_count
// These are nonvolatile because they are used to compensate the clock for 
// the time the unit was off.  SInce they're nonvolatile, they need to be
// in the nonvolatile memory.
// If COMPENSATION is nonzero, enabling temperature compensation, options.h
// must also somehow define:
// Y_Cal_Deg2 is   1 ppb =>   1 Y_Cal_Deg2 is 1 ppb.
// Y_Cal_Deg1 is  10 ppb =>  10 Y_Cal_Deg1 is 1 ppb.
// Y_Cal_Deg0 is 100 ppb => 100 Y_Cal_Deg0 is 1 ppb.
// In the demo code, these are in the "Parameter_t" section of Totals, 
// defined in meter.h


/*** Public functions declared within this module ***/
// See "rtc.h".

/*** Public variables declared within this module ***/
// rtc_ready, a bool set once per second by the isr.

/*** Private functions declared within this module ***/
static void RTClk_Write_Delay (void) small reentrant;

/*** Private variables declared within this module ***/
volatile bool rtc_ready;
static volatile bool rtc_adjusting_now;
static volatile uint8x_t RTC_idx = 0;


// display the date on the LCD
void date_lcd (void)
{
    LCD_Command (LCD_CLEAR);
    LCD_Year  (RTC_COPY.Year);
    LCD_Month (RTC_COPY.Month);
    LCD_Date  (RTC_COPY.Date);
}

// display the time on the LCD
void time_lcd (void)
{
    LCD_Command (LCD_CLEAR);
    LCD_Hour(RTC_COPY.Hour); 
    LCD_Min (RTC_COPY.Min);
    LCD_Sec (RTC_COPY.Sec);
}

void RTClk_Reset (void)                    // Reset RTC to defaults, if necessary.
{
    #if !RTC_LINE_LOCKED // if it's line-locked, don't do compensation
    struct RTC_t xdata rtc_temp;
    
    // save the last valid clock reading
    memcpy_xx((uint8x_t*)&rtc_temp, (uint8x_t*)&RTC_COPY, sizeof(RTC_COPY));
    #endif

    RTClk_Read ();
    if (RTC_COPY.Year == 0) // has the clock been set since it was first powered?
    {
        // Power to the clock failed, so set it. 
        // This could copy the last saved date and time, but that could 
        // cause the mistaken belief that the clock was "losing time" when the battery was bad.
        memset_x ((uint8x_t *) &RTC_COPY, 0x01, sizeof (RTC_COPY));
        RTClk_Write ();
        #if !RTC_LINE_LOCKED // if it's line-locked, don't do compensation
        trim_count = 0; // restart the trimming
        second_count = 0;
        #endif
        Status |= CLOCK_UNSET;
    }
    #if !RTC_LINE_LOCKED // if it's line-locked, don't do compensation
    // It needs to know how long the power was off.
    if (0 != ((POWER_BAD | CLOCK_UNSET) & Status))
    {
        // Either the last running date, or the current time is bad
        // Also, the trim was not saved, so it needs to be recalculated.
        #if RTC_COMPENSATION
        // deltaT, the difference in temperature from the calibration
        // temperature, is cleared to zero at start-up, so it stays zero
        // until it is measured. The constant drift (Y-Cal_Deg0) runs
        // right away, though.
        RTC_Compensation ();             // Calculate compensation of RTC.   
        #else
        // if no other clock compensation,
        // calculate a constant clock drift
        trim_value = (int32_t) (Y_Cal_Deg0 * 100L);
        #endif
    }
    else
    {
        // Compensate for the time off by simulating the normal adjustment.
        // It uses the last valid trim, which was collected when
        // the temperature was running, more accurate than
        // the trim for the calibration temperature.
        // Multiplication must be used, rather than a loop, because
        // the unit could be unpowered for millions of seconds while in
        // storage.
        float delta_trim = (float)Delta_Seconds (&rtc_temp, &RTC_COPY);
        int16_t seconds;

        irq_disable();
        delta_trim = (delta_trim * (float)trim_value) + (float)trim_count;
        seconds = (int16_t)(delta_trim / 1.0e9);
        second_count += seconds;
        trim_count = (int32_t)(delta_trim - (1.0e9 * ((float)seconds)));
        irq_enable();
    } 
    #endif
    RTC_idx = 0;
}

void RTClk_Write (void)
{
    #if RTC_COMPENSATION
    // clear the adjustment counts, because there's no error
    // when the clock is set, right?
    RTC_Adjust_Trim (TRUE, trim_value);
    #endif
    RTC_idx = sizeof(RTC)-1;    
    RTClk_Write_Delay ();
}


#if CE_OFF
bool RTC_Tic (void)                        // called to detect a 1-second tick.
{
    if (rtc_ready)
    {
       rtc_ready = FALSE;
       return (TRUE);
    }
    else
       return (FALSE);
}
#endif // ce_off

#pragma save
#pragma NOAREGS
static void RTClk_Write_Delay (void) small reentrant
{
    #if M6520
    WE = 0x00;                            // Write Enable RTC.
    #endif

    RTC[ RTC_idx ] = *(RTC_idx + ((uint8x_t*)&RTC_COPY));

    // keep it from overwriting I/O
    if (RTC_idx > 0)
    {
       // Switched to software timers to use less code, and free a timer.
       // The two is the minimum reliable number of clock ticks.
       #if TIMERS
       if(NULL != stm_start (2, 0, RTClk_Write_Delay))
           --RTC_idx;
       else
           RTC_idx = 0;
       #elif TMR0 || TMR1
       // 397us = 13/32768 of a second, the minimum time to write
       tmr_start (microseconds2tmr_reg(500), 0, RTClk_Write_Delay);
       --RTC_idx;
       #else
       #error need a timer
       #endif
    }
}
#pragma restore

void RTClk_Read (void)
{
    uint8_t xdata sec;
    uint8_t xdata old_sec;

    if(RTC_idx != 0)
        return;

    sec = -1;
    do
    {
       old_sec = sec;
       sec = RTC[ 0 ];
    } while (sec != old_sec);

    memcpy_xx ((uint8x_t *) &RTC_COPY, RTC, sizeof (RTC));    
}

#if RTC_COMPENSATION
// This is the RTC's temperature compensation.  It's updated in run_meter()
// in meter.c, running each time the meter measures the temperature.
// It figures the clock's compensation in parts per billion.
// Y_FREQ = XTAL_FREQ * {[Y_DEG2 * deltaT + Y_DEG1] * deltaT + Y_CAL}.      
//
// Y_Cal_Deg2 is   1 ppb =>   1 Y_Cal_Deg2 is 1 ppb.
// Y_Cal_Deg1 is  10 ppb =>  10 Y_Cal_Deg1 is 1 ppb.
// Y_Cal      is 100 ppb => 100 Y_Cal      is 1 ppb.
//
// deltaT     is 0.1 degrees => deltaT / 10 is degrees C.
// 
void RTC_Compensation (void)            // Do temperature compensation of RTC.
{
    int32_t value;

    value = (((((int32_t) Y_Cal_Deg2 * deltaT) / 100 + (int32_t) Y_Cal_Deg1) * deltaT) + (int32_t) Y_Cal_Deg0 * 100);

    RTC_Adjust_Trim (FALSE, value);
}

void RTC_Adjust_Trim (bool clr_cnt, int32_t value)
{
    irq_disable();                     // Begin critical section.

    // using a signed value means that opposite signs cancel, as they should
    trim_value = value;

    if (clr_cnt)
    {
        trim_count = 0;
        second_count = 0;
    }

    irq_enable();                      // End critical section.
}
#endif // RTC_COMPENSATION.

#if !RTC_LINE_LOCKED
// time since midnight, january 1, 2000
int32_t Julian (struct RTC_t xdata *ptm)
{
    int32_t a, y, m, j;
    a = (14 - (*ptm).Month) / 12L;
    y = (int32_t)(*ptm).Year + 6800L - a;
    m = (int32_t)(*ptm).Month + (12 * a) - 3;
    // julian days since Jan 1, 2000; 5.8e6 years range in 32-bit signed no.
    j = (int32_t)(*ptm).Date 
        + (((153 * m) + 2)/5)
        + (365 * y)
        + (y / 4)
        - (y / 100)
        + (y / 400)
        - 2483590;
    #if 1
    // julian seconds... 68 years range in a 32-bit signed number
    j = (j * 86400) 
         + (((int32_t) (*ptm).Hour - 12) * 3600)
         + ((int32_t) (*ptm).Min * 60)
         + (int32_t) (*ptm).Sec;
    #elif 0
    // julian millihours... 244 years range in a 32-bit signed number
    j = (((j * 24) + ((int32_t) (*ptm).Hour - 12)) * 1000)
        + ((((int32_t) (*ptm).Min * 50) + 1) / 3)
        + ((((int32_t) (*ptm).Sec * 5) + 9) / 18);
    #elif 0
    // julian decihours... 24,497 years range in a 32-bit signed number
    j = (((j * 24) + ((int32_t)(*ptm).Hour - 12)) * 10)
        + (((int32_t) (*ptm).Min + 3) / 6);
    #endif
    return j;
}

int32_t Delta_Seconds (struct RTC_t xdata *start, struct RTC_t xdata *end)
{
    return (Julian(end) - Julian(start));  // delta time. 
}
#endif

#endif // REAL_TIME_DATE

#if OPERATING_TIME || REAL_TIME_DATE
#define BILLION (1000000000L)
#pragma save
#pragma NOAREGS
// called from the interrupt decode routines in io65??.c
void rtc_isr (void) small reentrant
{
    // This produces a calibration signal, usable when the
    // pulse output is disabled.  It's needed to set the compensation.
    // It is enabled automatically after autocalibration.
    // It must be first in this routine to reduce timing uncertainties.
    #if 0
    DIO_7 ^= 1;                     // toggle pulse output
    #endif

    #if REAL_TIME_DATE
    rtc_ready = TRUE;

    #if !RTC_LINE_LOCKED  // at least a constant adjustment is the default
    // adjust the clock in real time
    trim_count += trim_value;
    if (trim_count < 0) // same speed as checking a flag
    {
        // keep maximum error +/- 0.5 seconds, +/- 5.8 ppm/day
        if (trim_count < (-BILLION / 2))  // -500.0e8 equals -1/2 second
        {
            second_count -= 1;
            trim_count += BILLION;
        }
    }
    else
    {
        // keep maximum error +/- 0.5 seconds, +/- 5.8 ppm
        if (trim_count > (BILLION / 2))  // 500.0e8 = 1/2 second
        {
            second_count += 1;
            trim_count -= BILLION;
        }
    }
    // catch up on adjustments; 
    // Adjustments have to be distributed, no more than one per two seconds
    // Normally this would be done just by the slow rate of adjustment,
    // but the unit might be in storage for years.  After that, it would
    // have many seconds of adjustment at once.
    if (rtc_adjusting_now)
    {
        rtc_adjusting_now = FALSE;
    }
    else
    {
        if (second_count < 0)
        {
            second_count += 1;
            // Pulse decrement.
            #if M6520
            WE = 0x00;                        // Write Enable RTC.
            #endif
            RTC_ADJUST =  RTC_DEC_SEC;
            rtc_adjusting_now = TRUE;
        }
        else if (second_count > 0)
        {
            second_count -= 1;
            // Pulse increment.
            #if M6520
            WE = 0x00;                        // Write Enable RTC.
            #endif
            RTC_ADJUST =  RTC_INC_SEC;   
            rtc_adjusting_now = TRUE;
        }
    }

    #else
    // This locks the RTC to the line frequency
    // This requires no calibration.
    {
        // get the nominal counts per second, calculated in meter\freq.c
        int8_t cnt = (int8_t)main_edge_cnt_nom;

        // Are mains data available? (demo code is often run without mains)
        if (cnt != 0) // from meter\freq.c
        {
            // how much error has accumulated?
            MainEdgeCount -= (long) cnt;       // remove this second's counts
            if (MainEdgeCount < (long)(-cnt)) // clock is too fast
            {
                MainEdgeCount += (long)cnt;    // adjust the measurement

                #if M6520
                WE = 0x00;                     // Write Enable RTC.
                #endif
                RTC_ADJUST =  RTC_DEC_SEC;     // Decrement the seconds.  
            }
            else if (MainEdgeCount > (long)cnt)     // clock is too slow
            {
                MainEdgeCount -= (long)cnt;    // adjust the measurement

                #if M6520
                WE = 0x00;                     // Write Enable RTC.
                #endif
                RTC_ADJUST =  RTC_INC_SEC;     // increment second.  
            }
        }
    }
    #endif // RTC_LINE_LOCKED
    #endif // REAL_TIME_DATE
    
    #if  OPERATING_TIME
    OperatingSeconds += 1;           // count seconds of operation
    #endif
}
#pragma restore
#endif // REAL_TIME_DATE || OPERATING_TIME
/***************************************************************************
 * $Log: rtc_experimental.c,v $
 * Revision 1.1  2006/10/13 00:47:30  tvander
 * Removed compile options for 6530, 6515;
 * renamed 6511 and 6513 to trace11 and trace13;
 * Binary verified unchanged from previous version.
 *
 *
 * Copyright (C) 2006 Teridian Semiconductor Corp. All Rights Reserved.    *
 * this program is fully protected by the United States copyright          *
 * laws and is the property of Teridian Semiconductor Corporation.         *
 ***************************************************************************/

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
麻豆91在线播放免费| 欧美三级电影在线观看| 精品国产百合女同互慰| 久久精品国产亚洲一区二区三区| 91精品欧美一区二区三区综合在| 日本成人超碰在线观看| 久久亚洲精精品中文字幕早川悠里 | 欧美老年两性高潮| 久热成人在线视频| 国产精品灌醉下药二区| 欧洲生活片亚洲生活在线观看| 天天综合色天天| 精品免费国产一区二区三区四区| 国产a久久麻豆| 亚洲精品国产品国语在线app| 8v天堂国产在线一区二区| 精品制服美女久久| 亚洲欧美自拍偷拍色图| 欧美精品日日鲁夜夜添| 国产精品一级在线| 亚洲国产精品久久人人爱| 欧美成人福利视频| 色综合天天做天天爱| 免费人成黄页网站在线一区二区 | 亚洲欧洲av在线| 欧美精品精品一区| 国产91精品一区二区麻豆网站| 亚洲愉拍自拍另类高清精品| 精品理论电影在线观看| 在线视频综合导航| 国产在线观看一区二区| 亚洲国产日韩a在线播放性色| 久久亚洲精精品中文字幕早川悠里| 91捆绑美女网站| 国产一区二区三区免费观看| 亚洲成av人片一区二区三区| 亚洲国产精品t66y| 91精选在线观看| 91蜜桃婷婷狠狠久久综合9色| 精品亚洲国产成人av制服丝袜| 亚洲美女淫视频| 国产女人水真多18毛片18精品视频| 欧美日韩一区精品| av一区二区三区黑人| 久草在线在线精品观看| 亚洲已满18点击进入久久| 中文字幕乱码亚洲精品一区| 日韩欧美一区在线观看| 欧美优质美女网站| av成人免费在线观看| 国产精品一区在线观看你懂的| 日韩高清在线观看| 亚洲综合激情网| 亚洲免费观看高清完整 | 亚洲人精品一区| 久久一区二区视频| 欧美一级夜夜爽| 欧美视频你懂的| 91免费精品国自产拍在线不卡| 成人精品小蝌蚪| 国产成人精品午夜视频免费| 精品在线播放午夜| 老司机精品视频在线| 日韩黄色片在线观看| 亚洲成av人片在www色猫咪| 亚洲精选免费视频| 亚洲免费看黄网站| 一区二区三区四区在线免费观看 | 日本中文字幕一区二区视频| 亚洲一区电影777| 亚洲国产毛片aaaaa无费看| 亚洲女人的天堂| 一区二区三区电影在线播| 亚洲女同一区二区| 亚洲自拍与偷拍| 亚洲在线成人精品| 日本中文字幕一区| 精油按摩中文字幕久久| 国产一区二区精品久久91| 国精品**一区二区三区在线蜜桃| 日韩影院在线观看| 韩国女主播成人在线观看| 国产精品主播直播| 不卡的电影网站| 91成人在线免费观看| 欧美美女一区二区| 日韩欧美在线一区二区三区| www国产精品av| 国产精品久久久久久福利一牛影视| 亚洲欧洲性图库| 亚洲午夜激情网页| 麻豆精品久久精品色综合| 国产一区二区成人久久免费影院| 丁香天五香天堂综合| 91一区二区三区在线观看| 欧美在线观看一二区| 日韩欧美一二三区| 国产欧美中文在线| 亚洲综合免费观看高清在线观看| 偷窥少妇高潮呻吟av久久免费| 精品亚洲国内自在自线福利| 成人黄色777网| 欧美视频一区在线观看| 精品国产乱码久久久久久蜜臀| 国产日本一区二区| 亚洲综合精品自拍| 韩国午夜理伦三级不卡影院| 99re66热这里只有精品3直播| 欧美色精品天天在线观看视频| 精品区一区二区| 国产精品传媒入口麻豆| 日日骚欧美日韩| 风间由美性色一区二区三区| 欧美性色黄大片| 亚洲免费观看视频| 六月丁香综合在线视频| 99久久综合色| 欧美人牲a欧美精品| 国产欧美日韩视频在线观看| 亚洲r级在线视频| 国产ts人妖一区二区| 欧美日韩高清影院| 亚洲欧洲日本在线| 精品夜夜嗨av一区二区三区| 在线观看国产日韩| 久久久精品欧美丰满| 亚洲成人免费视| 99久久夜色精品国产网站| 日韩欧美在线123| 亚洲成人777| 国产xxx精品视频大全| 日韩欧美一区二区在线视频| 亚洲人成网站影音先锋播放| 蜜桃av噜噜一区| 欧美性三三影院| 亚洲欧洲av在线| 成人天堂资源www在线| 欧美一级电影网站| 亚洲午夜一区二区三区| 国产主播一区二区三区| 制服丝袜亚洲色图| 亚洲一区在线观看免费| 国产成人免费在线视频| 精品国产一二三区| 免费成人性网站| 欧美日韩视频不卡| 亚洲精品久久久久久国产精华液| 国产大陆a不卡| 亚洲精品一区二区三区蜜桃下载| 五月天激情综合网| 色美美综合视频| 中文字幕高清不卡| 九色|91porny| 欧美mv和日韩mv的网站| 奇米精品一区二区三区四区 | 日韩电影免费在线观看网站| 在线免费观看一区| 亚洲精品免费看| 91在线观看一区二区| 亚洲欧洲成人自拍| 99re热视频这里只精品| 国产精品久久久久精k8| 91视频免费播放| 有坂深雪av一区二区精品| 色综合久久中文字幕| 国产精品国模大尺度视频| 成人午夜伦理影院| 亚洲欧洲99久久| 在线免费一区三区| 视频一区欧美日韩| 精品欧美乱码久久久久久1区2区| 捆绑调教美女网站视频一区| 亚洲国产成人午夜在线一区| 国产精品综合av一区二区国产馆| 久久久精品2019中文字幕之3| 国产精品99久久久久| 国产午夜亚洲精品午夜鲁丝片| 国产成人丝袜美腿| 亚洲欧美日韩电影| 欧美精品一级二级| 奇米亚洲午夜久久精品| 国产午夜精品一区二区三区视频| 粉嫩av一区二区三区| 亚洲婷婷综合色高清在线| 欧美色欧美亚洲另类二区| 丝袜诱惑亚洲看片| 久久免费美女视频| 97精品超碰一区二区三区| 亚洲一区二区三区三| 日韩欧美激情一区| 成人免费三级在线| 一区二区三区欧美| 日韩精品中文字幕一区二区三区| 国产大片一区二区| 亚洲成人免费视| 国产日本欧美一区二区| 欧美在线视频日韩| 极品少妇一区二区| 一区二区三区日韩| 精品国内片67194|