人狗畜禽COMPANY LIMITED|全是肉的高H文〈男男〉|全篇肉高H秘书被C办公室四爱|全黄H全肉共妻|全黄H全肉短篇禁乱NP慕浅浅|全黄H全肉短篇N男男

技術熱線: 4007-888-234

技術支持

PICC實現(xiàn)秒、分、小時時鐘程序

更新時間: 2019-03-26

//******************************************************************************* //程 序 名:高精度時鐘 //設 計 者:石魚WLEEN //設計說明:設置TMR0預分頻系數(shù)為16,一次計數(shù)中斷溢出時間為4096us(0x1000) // 每次TMR0中斷服務中對時間累計變量microsecond加上4096 // 程序主循環(huán)中不停地查詢變量microsecond,看是否超過50ms,如果時間超過 // 50ms,microsecond=microsecond-50000,同時50ms計數(shù)器ms501 // 基于50ms計數(shù)器的累加值,更新秒,分和小時值 // 雖然每一個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; }

 



404
返回首頁 |  返回上一頁
嘉峪关市| 宁波市| 二手房| 奈曼旗| 玛多县| 庄浪县| 资中县| 周口市| 清水河县| 怀远县| 河间市| 南木林县| 盈江县| 宝丰县| 呼伦贝尔市| 鞍山市| 尼木县| 佛坪县| 红桥区| 沙洋县| 台中市| 常熟市| 招远市| 郎溪县| 和顺县| 吉木乃县| 泰宁县| 沙洋县| 福州市| 潜山县| 陆丰市| 名山县| 昭平县| 祥云县| 孟州市| 云梦县| 横峰县| 南召县| 铁力市| 桐城市| 阿克苏市|