新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > STM32 ISL1208編程

        STM32 ISL1208編程

        作者: 時間:2016-11-23 來源:網絡 收藏
        [html]view plaincopy
        1. //ISL1208.h
        2. #ifndef_ISL1208_H_
        3. #define_ISL1208_H_
        4. #include"stm32f10x.h"
        5. typedefstructMy_Time
        6. {
        7. u8_year;
        8. u8_month;
        9. u8_day;
        10. u8_hour;
        11. u8_min;
        12. u8_sec;
        13. u8_week;
        14. }MY_TIME,*pMY_TIME;
        15. externMY_TIMEsMyTime;
        16. voidISL128Init(void);
        17. voidSetTime(pMY_TIME_mytime);
        18. voidGetTime(pMY_TIME_mytime);
        19. voidAuto_Time_Set(void);
        20. #endif//_ISL1208_H_

        本文引用地址:http://www.104case.com/article/201611/320433.htm

        [html]view plaincopy
        1. //ISL128.C
        2. #include"isl1208.h"
        3. #include"i2c_ee.h"
        4. constu8*COMPILED_DATE=__DATE__;//獲得編譯日期
        5. constu8*COMPILED_TIME=__TIME__;//獲得編譯時間
        6. constu8Month_Tab[12][3]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
        7. u8consttable_week[12]={0,3,3,6,1,4,6,2,5,0,3,5};//月修正數據表
        8. MY_TIMEsMyTime={0x13,0x04,0x13,0x14,0x10,0x05,0x03};
        9. staticintIntToBCD(inti);//十進制轉BCD
        10. staticintBCDToInt(intbcd);//BCD轉十進制
        11. staticu8RTC_Get_Week(u16year,u8month,u8day);
        12. intIntToBCD(inti)//十進制轉BCD
        13. {
        14. return(((i/10)<<4)+((i%10)&0x0f));
        15. }
        16. intBCDToInt(intbcd)//BCD轉十進制
        17. {
        18. return(0xff&(bcd>>4))*10+(0xf&bcd);
        19. }
        20. //比較兩個字符串指定長度的內容是否相等
        21. //參數:s1,s2要比較的兩個字符串;len,比較長度
        22. //返回值:1,相等;0,不相等
        23. u8my_strcmp(u8*s1,u8*s2,u8len)
        24. {
        25. u8i;
        26. for(i=0;i
        27. return1;
        28. }
        29. voidISL128Init()
        30. {
        31. u8SR_REG_DATA=0x91;
        32. u8INT_REG_DATA=0xca;
        33. EEPROM_ADDRESS=ISL1208_ADDRESS;
        34. I2C_EE_ByteWrite(&SR_REG_DATA,0x07);
        35. I2C_EE_ByteWrite(&INT_REG_DATA,0x08);
        36. }
        37. voidSetTime(pMY_TIME_mytime)
        38. {
        39. EEPROM_ADDRESS=ISL1208_ADDRESS;
        40. I2C_EE_ByteWrite(&_mytime->_sec,0x00);
        41. I2C_EE_ByteWrite(&_mytime->_min,0x01);
        42. I2C_EE_ByteWrite(&_mytime->_hour,0x02);
        43. I2C_EE_ByteWrite(&_mytime->_day,0x03);
        44. I2C_EE_ByteWrite(&_mytime->_month,0x04);
        45. I2C_EE_ByteWrite(&_mytime->_year,0x05);
        46. I2C_EE_ByteWrite(&_mytime->_week,0x06);
        47. }
        48. voidGetTime(pMY_TIME_mytime)
        49. {
        50. EEPROM_ADDRESS=ISL1208_ADDRESS;
        51. I2C_EE_BufferRead(&_mytime->_sec,0x00,1);
        52. I2C_EE_BufferRead(&_mytime->_min,0x01,1);
        53. I2C_EE_BufferRead(&_mytime->_hour,0x02,1);
        54. I2C_EE_BufferRead(&_mytime->_day,0x03,1);
        55. I2C_EE_BufferRead(&_mytime->_month,0x04,1);
        56. I2C_EE_BufferRead(&_mytime->_year,0x05,1);
        57. I2C_EE_BufferRead(&_mytime->_week,0x06,1);
        58. _mytime->_sec=BCDToInt(_mytime->_sec);
        59. _mytime->_min=BCDToInt(_mytime->_min);
        60. _mytime->_hour=BCDToInt(_mytime->_hour);
        61. _mytime->_day=BCDToInt(_mytime->_day);
        62. _mytime->_month=BCDToInt(_mytime->_month);
        63. _mytime->_year=BCDToInt(_mytime->_year);
        64. _mytime->_week=BCDToInt(_mytime->_week);
        65. }
        66. voidAuto_Time_Set()
        67. {
        68. u8temp[3];
        69. u8i;
        70. u8mon,date,week;
        71. u16year;
        72. u8sec,min,hour;
        73. for(i=0;i<3;i++)temp[i]=COMPILED_DATE[i];
        74. for(i=0;i<12;i++)if(my_strcmp((u8*)Month_Tab[i],temp,3))break;
        75. mon=i+1;//得到月份
        76. if(COMPILED_DATE[4]==)date=COMPILED_DATE[5]-0;
        77. elsedate=10*(COMPILED_DATE[4]-0)+COMPILED_DATE[5]-0;
        78. year=10*(COMPILED_DATE[9]-0)+COMPILED_DATE[10]-0;
        79. hour=10*(COMPILED_TIME[0]-0)+COMPILED_TIME[1]-0;
        80. min=10*(COMPILED_TIME[3]-0)+COMPILED_TIME[4]-0;
        81. sec=10*(COMPILED_TIME[6]-0)+COMPILED_TIME[7]-0;
        82. week=RTC_Get_Week(year+2000,mon,date);
        83. sMyTime._day=IntToBCD(date);
        84. sMyTime._hour=IntToBCD(hour);
        85. sMyTime._min=IntToBCD(min);
        86. sMyTime._month=IntToBCD(mon);
        87. sMyTime._sec=IntToBCD(sec);
        88. sMyTime._year=IntToBCD(year);
        89. sMyTime._week=IntToBCD(week);
        90. SetTime(&sMyTime);
        91. }
        92. u8RTC_Get_Week(u16year,u8month,u8day)
        93. {
        94. u16temp2;
        95. u8yearH,yearL;
        96. yearH=year/100;yearL=year%100;
        97. //如果為21世紀,年份數加100
        98. if(yearH>19)yearL+=100;
        99. //所過閏年數只算1900年之后的
        100. temp2=yearL+yearL/4;
        101. temp2=temp2%7;
        102. temp2=temp2+day+table_week[month-1];
        103. if(yearL%4==0&&month<3)temp2--;
        104. return(temp2%7);
        105. }



        關鍵詞: STM32ISL1208編

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 曲阳县| 措勤县| 阜平县| 淮北市| 佛坪县| 绥中县| 讷河市| 陆丰市| 察隅县| 桂平市| 隆尧县| 乐安县| 民权县| 镇雄县| 西青区| 肥乡县| 天气| 南郑县| 鄂伦春自治旗| 张家口市| 文化| 吉木萨尔县| 凭祥市| 安丘市| 响水县| 白沙| 增城市| 东丽区| 乐业县| 安阳市| 南投市| 四平市| 沙坪坝区| 武宁县| 建水县| 中宁县| 饶阳县| 民县| 尉氏县| 长沙县| 隆林|