原创 根据温度调整时间精确度

2012-7-1 19:03 1228 17 17 分类: 消费电子

时钟总是受温度影响,SD2068 可以通过调整的时钟走时 来调整精度。

温度采集用的是热敏电阻,价格低,但是有1%的误差。

//******************************************************************

if (sec > 600) // 每10分钟根据温度校准精度
    {
   sec = 0;
  y = AD_Tempreture();    //采集热敏电阻阻值
    i= rtTable[y];     //把热敏电阻阻值变换成温度值 ,16进制显示。
                x = ((i&0xf0)>>4)*10+ (i&0x0f);    //16进制变换成10进制
    if (y >0xbd)  i = TTFTable[x];  //0xbd 0点
    else i = TTZTable[x];
    SetTimeAdject(i);
    }

/********** 调整时间误差 *********************/
void SetTimeAdject(unsigned char dat)
{
WriteTimeOn();
I2CStart();
 I2CSendByte(Sd2068_W_Addr);     
 I2CWaitAck();  
    I2CSendByte(0x12);   //设置写起始地址     
 I2CWaitAck();  
    I2CSendByte(dat);   //清零数字调整寄存器     
 I2CWaitAck();       
 I2CStop(); 
 WriteTimeOff();  

 

const  rom unsigned char rtTable[] = {                    //上拉电阻10K    k3470
// 0   1   2     3    4     5    6   7    8    9    A    B    C    D   E     F    
0X99,0X99,0X99,0X99,0X99, 0X99,0X99,0X99,0X99,0X99,0X99,0X99,0X99,0X99,0X99,0X99,   //0
0X99,0X99,0X99,0X99,0X99, 0X99,0X99,0X99,0X99,0X99,0X99,0X99,0X99,0X85,0X85,0X84,   // 1
0X83,0X82,0X81,0X80,0X79, 0X77,0X76,0X75,0X74,0X73,0X72,0X71,0X71,0X70,0X69,0X68,   // 2
0X67,0X66,0X66,0X65,0X64, 0X63,0X63,0X62,0X61,0X60,0X60,0X59,0X58,0X58,0X57,0X56,   // 3
0X56,0X55,0X54,0X53,0X53, 0X52,0X52,0X51,0X51,0X50,0X50,0X49,0X49,0X48,0X48,0X47,   // 4
0X47,0X46,0X45,0X45,0X44, 0X44,0X43,0X43,0X42,0X42,0X41,0X41,0X40,0X40,0X39,0X39,  //  5
0X39,0X38,0X38,0X37,0X37, 0X36,0X36,0X35,0X35,0X35,0X34,0X33,0X33,0X33,0X32,0X32,  //6
0X31,0X31,0X30,0X30,0X30, 0X29,0X29,0X29,0X28,0X28,0X27,0X27,0X27,0X26,0X26,0X25,  // 7
0X25,0X24,0X24,0X24,0X23, 0X23,0X22,0X22,0X22,0X21,0X21,0X20,0X20,0X20,0X19,0X19,   //8
0X18,0X18,0X18,0X17,0X17, 0X16,0X16,0X16,0X15,0X15,0X14,0X14,0X14,0X13,0X13,0X12,   //9
0X12,0X12,0X11,0X11,0X10, 0X10,0X10,0X09,0X09,0X08,0X08,0X07,0X07,0X07,0X06,0X06, //A
0X05,0X05,0X05,0X04,0X04, 0X03,0X03,0X02,0X02,0X02,0X01,0X01,0X01, 0  ,0X01,0X01,  //B ----
0X02,0X02,0X03,0X03,0X04, 0X04,0X05,0X05,0X06,0X06,0X07,0X07,0X07,0X08,0X09,0X09,    // C
0X10,0X10,0X11,0X12,0X12, 0X13,0X13,0X14,0X15,0X15,0X16,0X16,0X17,0X18,0X19,0X19,   //D
0X20,0X21,0X22,0X22,0X23, 0X24,0X25,0X26,0X27,0X29,0X29,0X30,0X31,0X32,0X33,0X34,  //E
0X35,0X36,0X37,0X38,0X39, 0X40,0X40,0X40,0X40,0X40,0X40,0X40,0X40,0X40,0X40,0X40   //F
};

const rom unsigned char TTZTable[86]
= {
   0x7a,0x7a,0x7b,0x7c,0x7c,0x7c,0x7d,0x7d,0x7d,0x7e,  //0~9
   0x7e,0x7e,0x7f,0x7f,0x7f,0x7f,0,    0,    0,   0,  //10~19
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  //20~29
   0x00,0x7f,0x7f,0x7f,0x7f,0x7e,0x7e,0x7e,0x7e,0x7d,    //30~39
   0x7d,0x7d,0x7c,0x7c,0x7c,0x7b,0x7b,0x7a,0x79,0x79,  //40~49
   0x78,0x77,0x77,0x76,0x75,0x75,0x74,0x73,0x72,0x72,  //50~59
   0x71,0x70,0x6e,0x6e,0x6d,0x6c,0x6b,0x6a,0x69,0x68,  //60~69
   0x67,0x66,0x65,0x63,0x62,0x60,0x5f,0x5d,0x5c,0x5a,  //70~79
   0x59,0x58,0x56,0x55,0x54,0x52
  }; 
//----------------------------------------------------------------
const rom  unsigned char TTFTable[40]
= {
 0x78,0x78,0x77,0x77,0x76,0x76,0x75,0x74,0x74,0x73, //-1~-10
 0x72,0x72,0x71,0x70,0x6f,0x6f,0x6e,0x6d,0x6c,0x6b, //-11~-20
 0x6a,0x6a,0x69,0x68,0x67,0x66,0x65,0x64,0x63,0x62, //-21~-30
 0x61,0x60,0x5f,0x5e,0x5c,0x5b,0x5a,0x59,0x58,0x57  //-31~-40
}; 

 

 

 

文章评论0条评论)

登录后参与讨论
我要评论
0
17
关闭 站长推荐上一条 /2 下一条