STM32F103DS1302驅(qū)動(dòng)程序文件_第1頁(yè)
STM32F103DS1302驅(qū)動(dòng)程序文件_第2頁(yè)
STM32F103DS1302驅(qū)動(dòng)程序文件_第3頁(yè)
STM32F103DS1302驅(qū)動(dòng)程序文件_第4頁(yè)
STM32F103DS1302驅(qū)動(dòng)程序文件_第5頁(yè)
已閱讀5頁(yè),還剩9頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、#include "stm32f10x_conf.h"#include "mrhh_f1.h"#include "HPF_TIME.h"#include "HpfDS1302Drive.h"/DS1302? y ? - F103IO? u ? ? ? ?/Ver1.0 By MrHDS/2016,4.23/#if 1#define clkreset#define clksetGPIOE->BRR=GPIO_Pin_1GPIOE->BSRR=GPIO_Pin_1#define rstreset#defin

2、e rstsetGPIOE->BRR=GPIO_Pin_2GPIOE->BSRR=GPIO_Pin_2#define datreset#define datsetGPIOE->BRR=GPIO_Pin_0GPIOE->BSRR=GPIO_Pin_0#define datredGPIO_ReadInputDataBit(GPIOE,GPIO_Pin_0)/ ? a e ? e y ? Y#define DS1302Enable HpfDS1302WritByte(control_add,0x80) '6?a±£?。#define DS1302D

3、isEnable HpfDS1302WritByte(control_add,0x00)1?±?±£?。0x250#define testdat#define cheaken#endif#define dstim 1Ds1302Time DSTime=21,16,1,1,12,0,0,1;void HpfDS1302PinInData(void)GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);GPIO_InitStructure.GPIO

4、_Mode=GPIO_Mode_IPD; / e ? a - e ? e ?GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOE,&GPIO_InitStructure); void HpfDS1302PinOutData(void)GPIO_InitTypeDef GPIO_InitSyructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);GPIO_InitSyruct

5、ure.GPIO_Mode=GPIO_Mode_Out_PP;/ i ? ? a e ? 3 ?GPIO_InitSyructure.GPIO_Pin=GPIO_Pin_0;GPIO_InitSyructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOE,&GPIO_InitSyructure);void HpfDS1302PinClkRst(void)GPIO_InitTypeDef GPIO_InitSyructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);GPIO_Ini

6、tSyructure.GPIO_Mode=GPIO_Mode_Out_PP;/ i ? ? a e ? 3 ?GPIO_InitSyructure.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_2;GPIO_InitSyructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOE,&GPIO_InitSyructure); void HpfDS1302Init(void)HpfDS1302PinClkRst();clkreset;rstreset;? ' ?+? 土? 6? e ? 3 ?科/DS1302? y? - D&#

7、39; e? o? ? 。y?Y/Ver1.0 By MrHDS/2016,4.23/110/111 ffD513口工驅(qū)動(dòng)寫入一"b地址和數(shù)據(jù)112 /Verl.O By MrHDS113 /201r4.23114 /D' e ? e y ? Y ? u e ? e y ? ? o D D § u8 i;HpfDS1302PinOutData();addr&=0xfe;D' 6y?Y£? w? x? ?a?rstreset;clkreset;HpfDealyUs(dstim);rstset;HpfDealyUs(dstim);for(i=0

8、;i<8;i+)/ D ' 6 ?科? ? clkreset;HpfDealyUs(dstim);if(addr&0x01)datset;elsedatreset;clkset;HpfDealyUs(dstim);addr>>=1;/ HpfDealyUs(10); for(i=0;i<8;i+)D' e ? e y ? Y data clkreset;HpfDealyUs(dstim);if(data&0x01)datset;elsedatreset;clkset;HpfDealyUs(dstim);data>>=1;rst

9、reset;/ 1 £? 1 x u ? ?clkreset;/DS1302? y ? 一? a e ? o ? ? ? e y ? Y/Ver1.0 By MrHDS/2016,4.23/162 /163 /D313醛驅(qū)動(dòng)讀取一個(gè)數(shù)據(jù)164 /Verl+0 Ey MtHDS165 /201,4.231 /1 67u8 HpfDS1302ReadByte(u8 addr)/ ? a e ? o ? ? ? e y ? e ? e y ? ? o D D § u8 i,tem=0;addr|=0x01;rstreset;clkreset;HpfDealyUs(dstim);r

10、stset;HpfDealyUs(dstim);HpfDS1302PinOutData();for(i=0;i<8;i+) clkreset; HpfDealyUs(dstim); if(addr&0x01) datset;elsedatreset;Y?u?w?6DD§£?D' 6?科/ ? G6y?Y£? ? ? x? i ? ? ? a 1/ ? ? ? "Xu?clkset;HpfDealyUs(dstim);addr>>=1;HpfDS1302PinInData();for(i=0;i<8;i+) clkr

11、eset; HpfDealyUs(dstim); if(datred) tem|=0x80;if(i<7)tem>>=1;clkset;HpfDealyUs(dstim); rstreset;clkreset;return tem; u8 HpfDSBCDToNum(u8 BCD)/8421BCD? ? x a ? ? ? a 6yx u8 temp,temp1;temp1=BCD&0x0f;temp=(BCD&0xf0)>>4)*10+temp1;return temp;u8 HpfDSNumToBCD(u8 NUM)/eyx?xa?a 8421

12、BCD? ?u8 temp;temp=(NUM/10)<<4)|(NUM%10); return temp;/DS1302? y ? ? e ? o ? ? §6 土? 2 0Xa?a bcd? ? 2 0 ? ' ? ?科 ? DS1302buffer ? D/Ver1.0 By MrHDS/2016,4.23/-239/ “Q H驅(qū)空獲取用戶時(shí)間并轉(zhuǎn)換為碼并復(fù)制到DS13Sbuffu中21 /Vecl. 0 By MrHDS242 /3016,1.£3213/544void HpfDSTimrSet(void)HpfWTime *p;Ds1302Ti

13、me *s;p=GetWRTime();s=&DSTime;s->century=p->MyYear/100+1;s->year=HpfDSNumToBCD(p->MyYear-(s->century-1)*100);s->month=HpfDSNumToBCD(p->MyMon);s->day=HpfDSNumToBCD(p->MyDay);s->hh=HpfDSNumToBCD(p->MyHH);s->mm=HpfDSNumToBCD(p->MyMM);s->ss=HpfDSNumToBCD(p-&

14、gt;MySS);s->week=HpfDSNumToBCD(GetWNLWeek(p,s->day);/DS1302 ? buffer ? D ? e ±? ? 6y?YD' e ? ds1302? D/Ver1.0 By MrHDS/2016,4.23/269 n270 fDBL3Q2把but比匚中的時(shí)間數(shù)弼寫入到g13口£中271 Verl.O By M匚HD5272 2016,4+23273274void HpfDS1302WritData(void) Ds1302Time *s;s=&DSTime;DS1302DisEnable;1?&

15、#177;?D' ±£?。HpfDS1302WritByte(sec_add,0x80);/?Y i £ e ±? oHpfDS1302WritByte(year_add,s->year);HpfDS1302WritByte(month_add,s->month);HpfDS1302WritByte(day_add,s->day);HpfDS1302WritByte(hh_add,s->hh);HpfDS1302WritByte(min_add,s->mm);HpfDS1302WritByte(sec_add,s-&

16、gt;ss);HpfDS1302WritByte(week_add,s->week);HpfDS1302WritByte(RAM_Address29,testdat);DS1302Enable;/DS1302? a e ? e ±? ? e y ? Y 2 0Xa?a e y X?2 0' ? e ? ? o ? +? D /Ver1.0 By MrHDS/2016,4.23/29B/299 /口M3。2讀取時(shí)間數(shù)據(jù)并轉(zhuǎn)換為數(shù)字并存入緩存翳中300 /Verl. 0 By MrHDS3Q1 H2016,4,23302/303void HpfDS1302ReadData(

17、void) Ds1302Time *s;s=&DSTime;s->year=HpfDSBCDToNum(HpfDS1302ReadByte(year_add);s->month=HpfDSBCDToNum(HpfDS1302ReadByte(month_add);s->day=HpfDSBCDToNum(HpfDS1302ReadByte(day_add);s->hh=HpfDSBCDToNum(HpfDS1302ReadByte(hh_add);s->mm=HpfDSBCDToNum(HpfDS1302ReadByte(min_add);s->ss

18、=HpfDSBCDToNum(HpfDS1302ReadByte(sec_add);s->week=HpfDSBCDToNum(HpfDS1302ReadByte(week_add);/DS1302 ? e ±? ? i ? 2 ?科? 6? § e ±/Ver1.0 By MrHDS/2016,4.23/32 2 J J 4 三 04 4 三 =- 二=4=4q =三4= = 44=323 /瞪上38把盹間同步到用戶時(shí)間324 /Verl<D By- Mr-IDS/2ai«/4.23/ void HpfDS1302TimeSyn(void)

19、HpfWTime *p;p=GetWRTime();p->MyYear=(DSTime.century-1)*100+DSTime.year;p->MyMon=DSTime.month;p->MyDay=DSTime.day;p->MyHH=DSTime.hh;p->MyMM=DSTime.mm;p->MySS=DSTime.ss;/DS1302? y?"?e?o?/Ver1.0 By MrHDS/2016,4.23/344/34S /DSi 38 理?駐取遵存嘉胞址彳4, ,/veri.o By wrRTfl317 ”工口=MS / 'D

20、s1302Time *HpfDS1302GetTime(void) HpfDS1302Init();HpfDS1302ReadData();return &DSTime;/DS1302? y ? 一 RAM u X -/Ver1.0 By MrHDS/2016,4.23/ /buffer ?a?o'?+p? £? ramaddr? a?u'?p?£? num? a a? D ? 2 fiX+w? ? ? §£?rw?a1£?±f 6?D' e ? ey?Y£?a0±i e? ? a

21、e? e y ? Y / / / / / /Ql / l mm .谷 一 *1 .004* = maiK q 工= = * = = .工工 a.三三臺(tái)工谷二二二工.一工. = >&_ - n, qanwMHd 4 ,一 .« .一工 m M * = q ai = h n i* 工工 4 a三一1* m a = w q3依 NBUM干割 3 礁作362 Hvel. 0 E V ExHES*3 /2仇& K”M4 /3版“hMEF為#存器拈址為內(nèi)存批孫,小為連聲揖昨的茶犀一為L(zhǎng)表示寫入舒亭為門市示滿虱皙樵36E /XMET /3«B"35m/370' /| , _ void HpfDs1302RamWR(u8 *buffer,u8 ramaddr,u8 num,u8 rw)u8 i;if(ramaddr=RAM_Address29)return;if(rw)for(i=0;i<num;i+)DS1302DisEnable;HpfDS1302WritByte(ramaddr+(i<<1),bufferi);DS1302Enable;elsefor(i=0;i<num;i+)bufferi=HpfDS1302ReadByte(ramaddr+(i<<1); /DS1302? y ? 一?

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論