天堂草原最受欢迎的角色,天堂动漫,天堂在线,色天堂下载,天堂中文在线资源,亚洲男人天堂

技術熱線: 4007-888-234
設計開發

專注差異化嵌入式產品解決方案 給智能產品定制注入靈魂給予生命

開發工具

提供開發工具、應用測試 完善的開發代碼案例庫分享

技術支持

從全面的產品導入到強大技術支援服務 全程貼心伴隨服務,創造無限潛能!

新品推廣

提供新的芯片及解決方案,提升客戶產品競爭力

新聞中心

提供最新的單片機資訊,行業消息以及公司新聞動態

PICC實現秒、分、小時時鐘程序

更新時間: 2019-03-26
閱讀量:2026

//******************************************************************************* //程 序 名:高精度時鐘 //設 計 者:石魚WLEEN //設計說明:設置TMR0預分頻系數為16,一次計數中斷溢出時間為4096us(0x1000) // 每次TMR0中斷服務中對時間累計變量microsecond加上4096 // 程序主循環中不停地查詢變量microsecond,看是否超過50ms,如果時間超過 // 50ms,microsecond=microsecond-50000,同時50ms計數器ms501 // 基于50ms計數器的累加值,更新秒,分和小時值 // 雖然每一個50ms的變化時間略有偏差,但所有偏差值都保留在microsecond // ,并得到累計修正,所以長時間跨度計時精確 //******************************************************************************* #include

//*******************//variable define//**********************************

long int microsecond; //microsecond accumulative unit int ms50; //50ms counter int second; //second counter int minute; //minute counter int hour; //hour counter

main() {

//*******************//initialize//************************************** T0CS=0; //timer0 work at timer mode T0IF=0; //clear timer0 flag PSA=0; PS2=1; PS1=0; PS0=0; //psa=0,ps2:ps0=100,1:16 prescale value T0IE=1; //timer0 overflow interrupt enable GIE=1; // global interrupt enable

//*******************//main loop//************************************** while(1) { CLRWDT(); //clear the watchdog T0IE=0; //temporarily forbid the timer0 to interrupt //to keep the value of microsecond

microsecond-=50000; if(microsecond>=50000) //deal with microsecond>=50000 { ms50=+1; //50ms counter increase 1 if(ms50!=20) T0IE=1; //the time is not one second, resume t0ie ms50=0; //the time is one second,clear ms50 second++; //second counter if(second!=60) T0IE=1; //the time is not one minute, resume t0ie second=0; //the time is one minute,clear second minute++; //minute counter if(minute!=60) T0IE=1; //the time is not one hour, resume t0ie minute=0; //the time is one hour,clear minute hour++; //hour counter if(hour!=24) T0IE=1; //the time is not 24h, resume t0ie hour=0; //the time is 24 hour,clear hour } else microsecond+=50000; T0IE=1; //resume t0ie } }

void interrupt timer(void) { microsecond+=4096; }

 



联系我们: 洮南市| 榆社县| 凭祥市| 林西县| 文登市| 卢龙县| 临沭县| 澄迈县| 田林县| 宁陕县| 梁平县| 手机| 新竹市| 盐津县| 浪卡子县| 漳州市| 彭山县| 买车| 资阳市| 怀柔区| 来宾市| 孟津县| 合江县| 城口县| 淮阳县| 福海县| 汝城县| 精河县| 安岳县| 略阳县| 曲麻莱县| 秭归县| 顺义区| 裕民县| 河源市| 吉木萨尔县| 嫩江县| 岱山县| 监利县| 神农架林区| 夏河县|