STM32 ISL1208编程
时间:11-23
来源:互联网
点击:
[html]view plaincopy
- //ISL1208.h
- #ifndef_ISL1208_H_
- #define_ISL1208_H_
- #include"stm32f10x.h"
- typedefstructMy_Time
- {
- u8_year;
- u8_month;
- u8_day;
- u8_hour;
- u8_min;
- u8_sec;
- u8_week;
- }MY_TIME,*pMY_TIME;
- externMY_TIMEsMyTime;
- voidISL128Init(void);
- voidSetTime(pMY_TIME_mytime);
- voidGetTime(pMY_TIME_mytime);
- voidAuto_Time_Set(void);
- #endif//_ISL1208_H_
[html]view plaincopy
- //ISL128.C
- #include"isl1208.h"
- #include"i2c_ee.h"
- constu8*COMPILED_DATE=__DATE__;//获得编译日期
- constu8*COMPILED_TIME=__TIME__;//获得编译时间
- constu8Month_Tab[12][3]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
- u8consttable_week[12]={0,3,3,6,1,4,6,2,5,0,3,5};//月修正数据表
- MY_TIMEsMyTime={0x13,0x04,0x13,0x14,0x10,0x05,0x03};
- staticintIntToBCD(inti);//十进制转BCD
- staticintBCDToInt(intbcd);//BCD转十进制
- staticu8RTC_Get_Week(u16year,u8month,u8day);
- intIntToBCD(inti)//十进制转BCD
- {
- return(((i/10)<4)+((i%10)&0x0f));
- }
- intBCDToInt(intbcd)//BCD转十进制
- {
- return(0xff&(bcd>>4))*10+(0xf&bcd);
- }
- //比较两个字符串指定长度的内容是否相等
- //参数:s1,s2要比较的两个字符串;len,比较长度
- //返回值:1,相等;0,不相等
- u8my_strcmp(u8*s1,u8*s2,u8len)
- {
- u8i;
- for(i=0;i
- return1;
- }
- voidISL128Init()
- {
- u8SR_REG_DATA=0x91;
- u8INT_REG_DATA=0xca;
- EEPROM_ADDRESS=ISL1208_ADDRESS;
- I2C_EE_ByteWrite(&SR_REG_DATA,0x07);
- I2C_EE_ByteWrite(&INT_REG_DATA,0x08);
- }
- voidSetTime(pMY_TIME_mytime)
- {
- EEPROM_ADDRESS=ISL1208_ADDRESS;
- I2C_EE_ByteWrite(&_mytime->_sec,0x00);
- I2C_EE_ByteWrite(&_mytime->_min,0x01);
- I2C_EE_ByteWrite(&_mytime->_hour,0x02);
- I2C_EE_ByteWrite(&_mytime->_day,0x03);
- I2C_EE_ByteWrite(&_mytime->_month,0x04);
- I2C_EE_ByteWrite(&_mytime->_year,0x05);
- I2C_EE_ByteWrite(&_mytime->_week,0x06);
- }
- voidGetTime(pMY_TIME_mytime)
- {
- EEPROM_ADDRESS=ISL1208_ADDRESS;
- I2C_EE_BufferRead(&_mytime->_sec,0x00,1);
- I2C_EE_BufferRead(&_mytime->_min,0x01,1);
- I2C_EE_BufferRead(&_mytime->_hour,0x02,1);
- I2C_EE_BufferRead(&_mytime->_day,0x03,1);
- I2C_EE_BufferRead(&_mytime->_month,0x04,1);
- I2C_EE_BufferRead(&_mytime->_year,0x05,1);
- I2C_EE_BufferRead(&_mytime->_week,0x06,1);
- _mytime->_sec=BCDToInt(_mytime->_sec);
- _mytime->_min=BCDToInt(_mytime->_min);
- _mytime->_hour=BCDToInt(_mytime->_hour);
- _mytime->_day=BCDToInt(_mytime->_day);
- _mytime->_month=BCDToInt(_mytime->_month);
- _mytime->_year=BCDToInt(_mytime->_year);
- _mytime->_week=BCDToInt(_mytime->_week);
- }
- voidAuto_Time_Set()
- {
- u8temp[3];
- u8i;
- u8mon,date,week;
- u16year;
- u8sec,min,hour;
- for(i=0;i<3;i++)temp[i]=COMPILED_DATE[i];
- for(i=0;i<12;i++)if(my_strcmp((u8*)Month_Tab[i],temp,3))break;
- mon=i+1;//得到月份
- if(COMPILED_DATE[4]==)date=COMPILED_DATE[5]-0;
- elsedate=10*(COMPILED_DATE[4]-0)+COMPILED_DATE[5]-0;
- year=10*(COMPILED_DATE[9]-0)+COMPILED_DATE[10]-0;
- hour=10*(COMPILED_TIME[0]-0)+COMPILED_TIME[1]-0;
- min=10*(COMPILED_TIME[3]-0)+COMPILED_TIME[4]-0;
- sec=10*(COMPILED_TIME[6]-0)+COMPILED_TIME[7]-0;
- week=RTC_Get_Week(year+2000,mon,date);
- sMyTime._day=IntToBCD(date);
- sMyTime._hour=IntToBCD(hour);
- sMyTime._min=IntToBCD(min);
- sMyTime._month=IntToBCD(mon);
- sMyTime._sec=IntToBCD(sec);
- sMyTime._year=IntToBCD(year);
- sMyTime._week=IntToBCD(week);
- SetTime(&sMyTime);
- }
- u8RTC_Get_Week(u16year,u8month,u8day)
- {
- u16temp2;
- u8yearH,yearL;
- yearH=year/100;yearL=year%100;
- //如果为21世纪,年份数加100
- if(yearH>19)yearL+=100;
- //所过闰年数只算1900年之后的
- temp2=yearL+yearL/4;
- temp2=temp2%7;
- temp2=temp2+day+table_week[month-1];
- if(yearL%4==0&&month<3)temp2--;
- return(temp2%7);
- }
STM32ISL1208编 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)